fsledger.go 2.06 KB
Newer Older
manish's avatar
manish committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
Copyright IBM Corp. 2016 All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

		 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

17
package fsledger
manish's avatar
manish committed
18
19
20
21

import (
	"errors"

22
23
	"github.com/hyperledger/fabric/common/ledger"
	"github.com/hyperledger/fabric/common/ledger/blkstorage"
24

25
	"github.com/hyperledger/fabric/protos/common"
manish's avatar
manish committed
26
27
28
29
30
31
)

const (
	fileSegmentSize = 64 * 1024 * 1024
)

32
33
// fsLedger - an orderer ledger implementation that persists blocks on filesystem based store
type fsLedger struct {
manish's avatar
manish committed
34
	blockStore blkstorage.BlockStore
manish's avatar
manish committed
35
36
37
}

// GetBlockchainInfo returns basic info about blockchain
38
39
func (l *fsLedger) GetBlockchainInfo() (*common.BlockchainInfo, error) {
	return l.blockStore.GetBlockchainInfo()
manish's avatar
manish committed
40
41
42
}

// GetBlockByNumber returns block at a given height
43
44
func (l *fsLedger) GetBlockByNumber(blockNumber uint64) (*common.Block, error) {
	return l.blockStore.RetrieveBlockByNumber(blockNumber)
manish's avatar
manish committed
45
46
47
48
49
}

// GetBlocksIterator returns an iterator that starts from `startBlockNumber`(inclusive).
// The iterator is a blocking iterator i.e., it blocks till the next block gets available in the ledger
// ResultsIterator contains type BlockHolder
50
51
func (l *fsLedger) GetBlocksIterator(startBlockNumber uint64) (ledger.ResultsIterator, error) {
	return l.blockStore.RetrieveBlocks(startBlockNumber)
manish's avatar
manish committed
52
53
54
}

//Prune prunes the blocks/transactions that satisfy the given policy
55
func (l *fsLedger) Prune(policy ledger.PrunePolicy) error {
manish's avatar
manish committed
56
57
58
59
	return errors.New("Not yet implemented")
}

// Close closes the ledger
60
61
func (l *fsLedger) Close() {
	l.blockStore.Shutdown()
manish's avatar
manish committed
62
63
}

64
// Commit adds a new block
65
66
func (l *fsLedger) Commit(block *common.Block) error {
	return l.blockStore.AddBlock(block)
manish's avatar
manish committed
67
}