github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/common/ledger/blockledger/ledger.go (about) 1 /* 2 Copyright hechain. 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 // Remove removes an existing ledger 21 Remove(channelID string) error 22 23 // ChannelIDs returns the channel IDs the Factory is aware of 24 ChannelIDs() []string 25 26 // Close releases all resources acquired by the factory 27 Close() 28 } 29 30 // Iterator is useful for a chain Reader to stream blocks as they are created 31 type Iterator interface { 32 // Next blocks until there is a new block available, or returns an error if 33 // the next block is no longer retrievable 34 Next() (*cb.Block, cb.Status) 35 // Close releases resources acquired by the Iterator 36 Close() 37 } 38 39 // Reader allows the caller to inspect the ledger 40 type Reader interface { 41 // Iterator returns an Iterator, as specified by an ab.SeekInfo message, and 42 // its starting block number 43 Iterator(startType *ab.SeekPosition) (Iterator, uint64) 44 // Height returns the number of blocks on the ledger 45 Height() uint64 46 // retrieve blockByNumber 47 RetrieveBlockByNumber(blockNumber uint64) (*cb.Block, error) 48 } 49 50 // Writer allows the caller to modify the ledger 51 type Writer interface { 52 // Append a new block to the ledger 53 Append(block *cb.Block) error 54 } 55 56 // ReadWriter encapsulates the read/write functions of the ledger 57 type ReadWriter interface { 58 Reader 59 Writer 60 }