Documentation ¶
Index ¶
- Variables
- func NewBlock(channelID string, transactions ...*TxInfo) *cb.Block
- func NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction) *pb.FilteredBlock
- func NewFilteredTx(txID string, txValidationCode pb.TxValidationCode) *pb.FilteredTransaction
- func NewFilteredTxWithCCEvent(txID, ccID, event string) *pb.FilteredTransaction
- type Block
- type BlockEvent
- type BlockProducer
- type BlockWrapper
- type Consumer
- type EventFactory
- type FilteredBlockWrapper
- type Ledger
- type MockLedger
- func (l *MockLedger) BlockProducer() *BlockProducer
- func (l *MockLedger) NewBlock(channelID string, transactions ...*TxInfo)
- func (l *MockLedger) NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction)
- func (l *MockLedger) Register(consumer Consumer)
- func (l *MockLedger) SendFrom(blockNum uint64)
- func (l *MockLedger) Store(block Block)
- func (l *MockLedger) Unregister(Consumer Consumer)
- type MockProducer
- type TxInfo
Constants ¶
This section is empty.
Variables ¶
var BlockEventFactory = func(block Block) BlockEvent { b, ok := block.(*BlockWrapper) if !ok { panic(fmt.Sprintf("Invalid block type: %T", block)) } return b.Block() }
BlockEventFactory creates block events
var FilteredBlockEventFactory = func(block Block) BlockEvent { b, ok := block.(*FilteredBlockWrapper) if !ok { panic(fmt.Sprintf("Invalid block type: %T", block)) } return b.Block() }
FilteredBlockEventFactory creates filtered block events
Functions ¶
func NewFilteredBlock ¶
func NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction) *pb.FilteredBlock
NewFilteredBlock returns a new mock filtered block initialized with the given channel and filtered transactions
func NewFilteredTx ¶
func NewFilteredTx(txID string, txValidationCode pb.TxValidationCode) *pb.FilteredTransaction
NewFilteredTx returns a new mock filtered transaction
func NewFilteredTxWithCCEvent ¶
func NewFilteredTxWithCCEvent(txID, ccID, event string) *pb.FilteredTransaction
NewFilteredTxWithCCEvent returns a new mock filtered transaction with the given chaincode event
Types ¶
type BlockProducer ¶
type BlockProducer struct {
// contains filtered or unexported fields
}
BlockProducer is a block BlockProducer that ensures the block number is set sequencially
func NewBlockProducer ¶
func NewBlockProducer() *BlockProducer
NewBlockProducer returns a new block producer
func (*BlockProducer) NewBlock ¶
func (p *BlockProducer) NewBlock(channelID string, transactions ...*TxInfo) *cb.Block
NewBlock returns a new block
func (*BlockProducer) NewFilteredBlock ¶
func (p *BlockProducer) NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction) *pb.FilteredBlock
NewFilteredBlock returns a new filtered block
type BlockWrapper ¶
type BlockWrapper struct {
// contains filtered or unexported fields
}
BlockWrapper wraps the Block and conforms to the Block interface
func NewBlockWrapper ¶
func NewBlockWrapper(block *cb.Block) *BlockWrapper
NewBlockWrapper returns a new Block wrapper
func (*BlockWrapper) Number ¶
func (w *BlockWrapper) Number() uint64
Number returns the block number
func (*BlockWrapper) SetNumber ¶
func (w *BlockWrapper) SetNumber(number uint64)
SetNumber sets the block number
type EventFactory ¶
type EventFactory func(block Block) BlockEvent
EventFactory creates block events
type FilteredBlockWrapper ¶
type FilteredBlockWrapper struct {
// contains filtered or unexported fields
}
FilteredBlockWrapper wraps the FilteredBlock and conforms to the Block interface
func NewFilteredBlockWrapper ¶
func NewFilteredBlockWrapper(block *pb.FilteredBlock) *FilteredBlockWrapper
NewFilteredBlockWrapper returns a new Filtered Block wrapper
func (*FilteredBlockWrapper) Block ¶
func (w *FilteredBlockWrapper) Block() *pb.FilteredBlock
Block returns the filtered block
func (*FilteredBlockWrapper) Number ¶
func (w *FilteredBlockWrapper) Number() uint64
Number returns the block number
func (*FilteredBlockWrapper) SetNumber ¶
func (w *FilteredBlockWrapper) SetNumber(number uint64)
SetNumber sets the block number
type Ledger ¶
type Ledger interface { // Register registers an event consumer Register(consumer Consumer) // Unregister unregisters the given consumer Unregister(consumer Consumer) // NewBlock returns a new block NewBlock(channelID string, transactions ...*TxInfo) // NewFilteredBlock returns a new filtered block NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction) // SendFrom sends block events to all registered consumers from the // given block number SendFrom(blockNum uint64) }
Ledger is a MockLedger
type MockLedger ¶
MockLedger is a mock ledger that stores blocks sequentially
func NewMockLedger ¶
func NewMockLedger(eventFactory EventFactory) *MockLedger
NewMockLedger creates a new MockLedger
func (*MockLedger) BlockProducer ¶
func (l *MockLedger) BlockProducer() *BlockProducer
BlockProducer returns the block producer
func (*MockLedger) NewBlock ¶
func (l *MockLedger) NewBlock(channelID string, transactions ...*TxInfo)
NewBlock stores a new block on the ledger
func (*MockLedger) NewFilteredBlock ¶
func (l *MockLedger) NewFilteredBlock(channelID string, filteredTx ...*pb.FilteredTransaction)
NewFilteredBlock stores a new filtered block on the ledger
func (*MockLedger) Register ¶
func (l *MockLedger) Register(consumer Consumer)
Register registers an event consumer
func (*MockLedger) SendFrom ¶
func (l *MockLedger) SendFrom(blockNum uint64)
SendFrom sends block events to all registered consumers from the given block number
func (*MockLedger) Store ¶
func (l *MockLedger) Store(block Block)
Store stores the given block to the ledger
func (*MockLedger) Unregister ¶
func (l *MockLedger) Unregister(Consumer Consumer)
Unregister unregisters the given consumer
type MockProducer ¶
MockProducer produces events for unit testing
func NewMockProducer ¶
func NewMockProducer(ledger Ledger) *MockProducer
NewMockProducer returns a new MockProducer
func (*MockProducer) Register ¶
func (c *MockProducer) Register() <-chan interface{}
Register registers an event channel
func (*MockProducer) Unregister ¶
func (c *MockProducer) Unregister(eventch chan<- interface{})
Unregister unregisters an event channel
type TxInfo ¶
type TxInfo struct { TxID string TxValidationCode pb.TxValidationCode HeaderType cb.HeaderType ChaincodeID string EventName string Payload []byte }
TxInfo contains the data necessary to construct a mock transaction
func NewTransaction ¶
func NewTransaction(txID string, txValidationCode pb.TxValidationCode, headerType cb.HeaderType) *TxInfo
NewTransaction creates a new transaction
func NewTransactionWithCCEvent ¶
func NewTransactionWithCCEvent(txID string, txValidationCode pb.TxValidationCode, ccID string, eventName string, payload []byte) *TxInfo
NewTransactionWithCCEvent creates a new transaction with the given chaincode event