Documentation
¶
Index ¶
- Constants
- func DropTxIndex(ds repo.Datastore) error
- type GetBlockFunc
- type IndexManager
- type Indexer
- type TxIndex
- func (idx *TxIndex) ConnectBlock(dbtx datastore.Txn, blk *blocks.Block) error
- func (idx *TxIndex) GetContainingBlockID(ds repo.Datastore, txid types.ID) (types.ID, error)
- func (idx *TxIndex) GetTransaction(ds repo.Datastore, txid types.ID) (*transactions.Transaction, error)
- func (idx *TxIndex) Key() string
- func (idx *TxIndex) Name() string
Constants ¶
const (
TxIndexName = "transaction index"
)
Variables ¶
This section is empty.
Functions ¶
func DropTxIndex ¶
Types ¶
type GetBlockFunc ¶
GetBlockFunc defines a function that is part of the blockchain class that gets us around circular imports.
type IndexManager ¶
type IndexManager struct {
// contains filtered or unexported fields
}
IndexManager maintains the blockchain indexes and ensures they are current with the blockchain.
func NewIndexManager ¶
func NewIndexManager(ds repo.Datastore, indexers []Indexer) *IndexManager
NewIndexManager returns a new IndexManager.
func (*IndexManager) ConnectBlock ¶
ConnectBlock connects the block to each indexer.
func (*IndexManager) Init ¶
func (im *IndexManager) Init(tipHeight uint32, getBlock GetBlockFunc) error
Init iterates over each indexer and checks to see if the indexer height is the same height as the tip of the chain. If not, it will roll the index forward until it is current.
type Indexer ¶
type Indexer interface {
// Key returns the key of the index as a string.
Key() string
// Name returns the human-readable name of the index.
Name() string
// ConnectBlock is called when a block is connected to the chain.
// The indexer can use this opportunity to parse it and store it in
// the database. The database transaction must be respected.
ConnectBlock(dbtx datastore.Txn, blk *blocks.Block) error
}
Indexer defines the interface that all blockchain indexers will use.
type TxIndex ¶
type TxIndex struct{}
TxIndex is and implementation of the Indexer which indexes transactions by their ID and maps them to the location of the transaction in the database. This is useful functionality for anyone interested in inspecting a given transaction, for example, block explorers.
func (*TxIndex) ConnectBlock ¶
ConnectBlock is called when a block is connected to the chain. The indexer can use this opportunity to parse it and store it in the database. The database transaction must be respected.
func (*TxIndex) GetContainingBlockID ¶
GetContainingBlockID returns the ID of the block containing the transaction.
func (*TxIndex) GetTransaction ¶
func (idx *TxIndex) GetTransaction(ds repo.Datastore, txid types.ID) (*transactions.Transaction, error)
GetTransaction looks up the block id and position in the transaction index then fetches the transaction from the db and returns it.