github.com/darrenli6/fabric-sdk-example@v0.0.0-20220109053535-94b13b56df8c/orderer/ledger/ledger.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8                   http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package ledger
    18  
    19  import (
    20  	cb "github.com/hyperledger/fabric/protos/common"
    21  	ab "github.com/hyperledger/fabric/protos/orderer"
    22  )
    23  
    24  // Factory retrieves or creates new ledgers by chainID
    25  type Factory interface {
    26  	// GetOrCreate gets an existing ledger (if it exists)
    27  	// or creates it if it does not
    28  	GetOrCreate(chainID string) (ReadWriter, error)
    29  
    30  	// ChainIDs returns the chain IDs the Factory is aware of
    31  	ChainIDs() []string
    32  
    33  	// Close releases all resources acquired by the factory
    34  	Close()
    35  }
    36  
    37  // Iterator is useful for a chain Reader to stream blocks as they are created
    38  type Iterator interface {
    39  	// Next blocks until there is a new block available, or returns an error if
    40  	// the next block is no longer retrievable
    41  	Next() (*cb.Block, cb.Status)
    42  	// ReadyChan supplies a channel which will block until Next will not block
    43  	ReadyChan() <-chan struct{}
    44  }
    45  
    46  // Reader allows the caller to inspect the ledger
    47  type Reader interface {
    48  	// Iterator returns an Iterator, as specified by a cb.SeekInfo message, and
    49  	// its starting block number
    50  	Iterator(startType *ab.SeekPosition) (Iterator, uint64)
    51  	// Height returns the number of blocks on the ledger
    52  	Height() uint64
    53  }
    54  
    55  // Writer allows the caller to modify the ledger
    56  type Writer interface {
    57  	// Append a new block to the ledger
    58  	Append(block *cb.Block) error
    59  }
    60  
    61  // ReadWriter encapsulates the read/write functions of the ledger
    62  type ReadWriter interface {
    63  	Reader
    64  	Writer
    65  }