blockstorage.go 2.8 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/common/ledger"
23
	l "github.com/hyperledger/fabric/core/ledger"
24
	"github.com/hyperledger/fabric/protos/common"
25
	"github.com/hyperledger/fabric/protos/peer"
manish's avatar
manish committed
26
27
)

manish's avatar
manish committed
28
29
30
31
32
// IndexableAttr represents an indexable attribute
type IndexableAttr string

// constants for indexable attributes
const (
33
34
35
36
37
38
	IndexableAttrBlockNum         = IndexableAttr("BlockNum")
	IndexableAttrBlockHash        = IndexableAttr("BlockHash")
	IndexableAttrTxID             = IndexableAttr("TxID")
	IndexableAttrBlockNumTranNum  = IndexableAttr("BlockNumTranNum")
	IndexableAttrBlockTxID        = IndexableAttr("BlockTxID")
	IndexableAttrTxValidationCode = IndexableAttr("TxValidationCode")
manish's avatar
manish committed
39
40
41
42
43
44
45
46
47
)

// 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
48
49
	ErrNotFoundInIndex = l.NotFoundInIndexErr("")

manish's avatar
manish committed
50
51
52
53
	// ErrAttrNotIndexed is used to indicate that an attribute is not indexed
	ErrAttrNotIndexed = errors.New("Attribute not indexed")
)

manish's avatar
manish committed
54
55
56
57
58
59
60
61
62
// BlockStoreProvider provides an handle to a BlockStore
type BlockStoreProvider interface {
	CreateBlockStore(ledgerid string) (BlockStore, error)
	OpenBlockStore(ledgerid string) (BlockStore, error)
	Exists(ledgerid string) (bool, error)
	List() ([]string, error)
	Close()
}

manish's avatar
manish committed
63
// BlockStore - an interface for persisting and retrieving blocks
manish's avatar
manish committed
64
65
// 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
66
type BlockStore interface {
67
	AddBlock(block *common.Block) error
68
	GetBlockchainInfo() (*common.BlockchainInfo, error)
manish's avatar
manish committed
69
	RetrieveBlocks(startNum uint64) (ledger.ResultsIterator, error)
70
	RetrieveBlockByHash(blockHash []byte) (*common.Block, error)
denyeart's avatar
denyeart committed
71
	RetrieveBlockByNumber(blockNum uint64) (*common.Block, error) // blockNum of  math.MaxUint64 will return last block
72
	RetrieveTxByID(txID string) (*common.Envelope, error)
73
	RetrieveTxByBlockNumTranNum(blockNum uint64, tranNum uint64) (*common.Envelope, error)
74
	RetrieveBlockByTxID(txID string) (*common.Block, error)
75
	RetrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error)
manish's avatar
manish committed
76
77
	Shutdown()
}