This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
/
blockindex.go
70 lines (61 loc) · 2.02 KB
/
blockindex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2017-2018 The qitmeer developers
package blockchain
import (
"github.com/Qitmeer/qitmeer/common/hash"
"github.com/Qitmeer/qitmeer/core/blockdag"
"github.com/Qitmeer/qitmeer/core/types"
"github.com/Qitmeer/qitmeer/database"
)
// IndexManager provides a generic interface that the is called when blocks are
// connected and disconnected to and from the tip of the main chain for the
// purpose of supporting optional indexes.
type IndexManager interface {
// Init is invoked during chain initialize in order to allow the index
// manager to initialize itself and any indexes it is managing. The
// channel parameter specifies a channel the caller can close to signal
// that the process should be interrupted. It can be nil if that
// behavior is not desired.
Init(*BlockChain, <-chan struct{}) error
// ConnectBlock is invoked when a new block has been connected to the
// main chain.
ConnectBlock(tx database.Tx, block *types.SerializedBlock, stxos []SpentTxOut) error
// DisconnectBlock is invoked when a block has been disconnected from
// the main chain.
DisconnectBlock(tx database.Tx, block *types.SerializedBlock, stxos []SpentTxOut) error
// IsDuplicateTx
IsDuplicateTx(tx database.Tx, txid *hash.Hash, blockHash *hash.Hash) bool
}
// LookupNode returns the block node identified by the provided hash. It will
// return nil if there is no entry for the hash.
func (b *BlockChain) LookupNode(hash *hash.Hash) *BlockNode {
ib := b.GetBlock(hash)
if ib == nil {
return nil
}
if ib.GetData() == nil {
return nil
}
return ib.GetData().(*BlockNode)
}
func (b *BlockChain) LookupNodeById(id uint) *BlockNode {
ib := b.bd.GetBlockById(id)
if ib == nil {
return nil
}
if ib.GetData() == nil {
return nil
}
return ib.GetData().(*BlockNode)
}
func (b *BlockChain) GetBlockNode(ib blockdag.IBlock) *BlockNode {
if ib == nil {
return nil
}
if ib.GetData() == nil {
return nil
}
return ib.GetData().(*BlockNode)
}
func (b *BlockChain) GetBlock(h *hash.Hash) blockdag.IBlock {
return b.bd.GetBlock(h)
}