github.com/lzy4123/fabric@v2.1.1+incompatible/common/ledger/blockledger/ledger.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package blockledger 8 9 import ( 10 cb "github.com/hyperledger/fabric-protos-go/common" 11 ab "github.com/hyperledger/fabric-protos-go/orderer" 12 ) 13 14 // Factory retrieves or creates new ledgers by channelID 15 type Factory interface { 16 // GetOrCreate gets an existing ledger (if it exists) 17 // or creates it if it does not 18 GetOrCreate(channelID string) (ReadWriter, error) 19 20 // ChannelIDs returns the channel IDs the Factory is aware of 21 ChannelIDs() []string 22 23 // Close releases all resources acquired by the factory 24 Close() 25 } 26 27 // Iterator is useful for a chain Reader to stream blocks as they are created 28 type Iterator interface { 29 // Next blocks until there is a new block available, or returns an error if 30 // the next block is no longer retrievable 31 Next() (*cb.Block, cb.Status) 32 // Close releases resources acquired by the Iterator 33 Close() 34 } 35 36 // Reader allows the caller to inspect the ledger 37 type Reader interface { 38 // Iterator returns an Iterator, as specified by an ab.SeekInfo message, and 39 // its starting block number 40 Iterator(startType *ab.SeekPosition) (Iterator, uint64) 41 // Height returns the number of blocks on the ledger 42 Height() uint64 43 } 44 45 // Writer allows the caller to modify the ledger 46 type Writer interface { 47 // Append a new block to the ledger 48 Append(block *cb.Block) error 49 } 50 51 // ReadWriter encapsulates the read/write functions of the ledger 52 type ReadWriter interface { 53 Reader 54 Writer 55 }