github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/orderer/ledger/fsledger/fsledger.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 fsledger
    18  
    19  import (
    20  	"errors"
    21  
    22  	"github.com/hyperledger/fabric/common/ledger"
    23  	"github.com/hyperledger/fabric/common/ledger/blkstorage"
    24  
    25  	"github.com/hyperledger/fabric/protos/common"
    26  )
    27  
    28  const (
    29  	fileSegmentSize = 64 * 1024 * 1024
    30  )
    31  
    32  // fsLedger - an orderer ledger implementation that persists blocks on filesystem based store
    33  type fsLedger struct {
    34  	blockStore blkstorage.BlockStore
    35  }
    36  
    37  // GetBlockchainInfo returns basic info about blockchain
    38  func (l *fsLedger) GetBlockchainInfo() (*common.BlockchainInfo, error) {
    39  	return l.blockStore.GetBlockchainInfo()
    40  }
    41  
    42  // GetBlockByNumber returns block at a given height
    43  func (l *fsLedger) GetBlockByNumber(blockNumber uint64) (*common.Block, error) {
    44  	return l.blockStore.RetrieveBlockByNumber(blockNumber)
    45  }
    46  
    47  // GetBlocksIterator returns an iterator that starts from `startBlockNumber`(inclusive).
    48  // The iterator is a blocking iterator i.e., it blocks till the next block gets available in the ledger
    49  // ResultsIterator contains type BlockHolder
    50  func (l *fsLedger) GetBlocksIterator(startBlockNumber uint64) (ledger.ResultsIterator, error) {
    51  	return l.blockStore.RetrieveBlocks(startBlockNumber)
    52  }
    53  
    54  //Prune prunes the blocks/transactions that satisfy the given policy
    55  func (l *fsLedger) Prune(policy ledger.PrunePolicy) error {
    56  	return errors.New("Not yet implemented")
    57  }
    58  
    59  // Close closes the ledger
    60  func (l *fsLedger) Close() {
    61  	l.blockStore.Shutdown()
    62  }
    63  
    64  // Commit adds a new block
    65  func (l *fsLedger) Commit(block *common.Block) error {
    66  	return l.blockStore.AddBlock(block)
    67  }