github.com/sykesm/fabric@v1.1.0-preview.0.20200129034918-2aa12b1a0181/common/ledger/ledger_interface.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  	"github.com/hyperledger/fabric-protos-go/common"
    21  )
    22  
    23  // Ledger captures the methods that are common across the 'PeerLedger', 'OrdererLedger', and 'ValidatedLedger'
    24  type Ledger interface {
    25  	// GetBlockchainInfo returns basic info about blockchain
    26  	GetBlockchainInfo() (*common.BlockchainInfo, error)
    27  	// GetBlockByNumber returns block at a given height
    28  	// blockNumber of  math.MaxUint64 will return last block
    29  	GetBlockByNumber(blockNumber uint64) (*common.Block, error)
    30  	// GetBlocksIterator returns an iterator that starts from `startBlockNumber`(inclusive).
    31  	// The iterator is a blocking iterator i.e., it blocks till the next block gets available in the ledger
    32  	// ResultsIterator contains type BlockHolder
    33  	GetBlocksIterator(startBlockNumber uint64) (ResultsIterator, error)
    34  	// Close closes the ledger
    35  	Close()
    36  }
    37  
    38  // ResultsIterator - an iterator for query result set
    39  type ResultsIterator interface {
    40  	// Next returns the next item in the result set. The `QueryResult` is expected to be nil when
    41  	// the iterator gets exhausted
    42  	Next() (QueryResult, error)
    43  	// Close releases resources occupied by the iterator
    44  	Close()
    45  }
    46  
    47  // QueryResultsIterator - an iterator for query result set
    48  type QueryResultsIterator interface {
    49  	ResultsIterator
    50  	GetBookmarkAndClose() string
    51  }
    52  
    53  // QueryResult - a general interface for supporting different types of query results. Actual types differ for different queries
    54  type QueryResult interface{}
    55  
    56  // PrunePolicy - a general interface for supporting different pruning policies
    57  type PrunePolicy interface{}