indexers

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TxIndexName = "transaction index"
)

Variables

This section is empty.

Functions

func DropTxIndex

func DropTxIndex(ds repo.Datastore) error

Types

type GetBlockFunc

type GetBlockFunc func(height uint32) (*blocks.Block, error)

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

func (im *IndexManager) ConnectBlock(dbtx datastore.Txn, blk *blocks.Block) error

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 NewTxIndex

func NewTxIndex() *TxIndex

NewTxIndex returns a new TxIndex.

func (*TxIndex) ConnectBlock

func (idx *TxIndex) ConnectBlock(dbtx datastore.Txn, blk *blocks.Block) error

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

func (idx *TxIndex) GetContainingBlockID(ds repo.Datastore, txid types.ID) (types.ID, error)

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.

func (*TxIndex) Key

func (idx *TxIndex) Key() string

Key returns the key of the index as a string.

func (*TxIndex) Name

func (idx *TxIndex) Name() string

Name returns the human-readable name of the index.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址