blockstorage.go 2.01 KB
Newer Older
manish's avatar
manish committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
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.
*/

package blkstorage

import (
manish's avatar
manish committed
20
21
	"errors"

22
	"github.com/hyperledger/fabric/core/ledger"
23

24
	"github.com/hyperledger/fabric/protos/common"
25
	pb "github.com/hyperledger/fabric/protos/peer"
manish's avatar
manish committed
26
27
)

manish's avatar
manish committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// IndexableAttr represents an indexable attribute
type IndexableAttr string

// constants for indexable attributes
const (
	IndexableAttrBlockNum  = IndexableAttr("BlockNum")
	IndexableAttrBlockHash = IndexableAttr("BlockHash")
	IndexableAttrTxID      = IndexableAttr("TxID")
)

// IndexConfig - a configuration that includes a list of attributes that should be indexed
type IndexConfig struct {
	AttrsToIndex []IndexableAttr
}

var (
	// ErrNotFoundInIndex is used to indicate missing entry in the index
	ErrNotFoundInIndex = errors.New("Entry not found in index")
	// ErrAttrNotIndexed is used to indicate that an attribute is not indexed
	ErrAttrNotIndexed = errors.New("Attribute not indexed")
)

manish's avatar
manish committed
50
// BlockStore - an interface for persisting and retrieving blocks
manish's avatar
manish committed
51
52
// An implementation of this interface is expected to take an argument
// of type `IndexConfig` which configures the block store on what items should be indexed
manish's avatar
manish committed
53
type BlockStore interface {
54
	AddBlock(block *common.Block) error
55
	GetBlockchainInfo() (*pb.BlockchainInfo, error)
manish's avatar
manish committed
56
	RetrieveBlocks(startNum uint64) (ledger.ResultsIterator, error)
57
58
	RetrieveBlockByHash(blockHash []byte) (*common.Block, error)
	RetrieveBlockByNumber(blockNum uint64) (*common.Block, error)
59
	RetrieveTxByID(txID string) (*pb.Transaction, error)
manish's avatar
manish committed
60
61
	Shutdown()
}