indexers

package
v0.0.4-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TxIndexName = "transaction index"
)
View Source
const (
	WalletServerIndexName = "wallet server index"
)

Variables

This section is empty.

Functions

func DropTxIndex

func DropTxIndex(ds repo.Datastore) error

func DropWalletServerIndex

func DropWalletServerIndex(ds repo.Datastore) error

DropWalletServerIndex deletes the wallet server index from the datastore

func UpdateLogger

func UpdateLogger()

Types

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) Close

func (im *IndexManager) Close() error

Close shuts down all the indexers.

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 func(height uint32) (*blocks.Block, error)) 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.
	//
	// It is the responsibility of the index to update the height
	// of the index in the datastore. This can be done after connecting
	// each block or, if the index is doing some caching, on Close().
	ConnectBlock(dbtx datastore.Txn, blk *blocks.Block) error

	// Close is called when the index manager shuts down and gives the indexer
	// an opportunity to do some cleanup.
	Close(ds repo.Datastore) error
}

Indexer defines the interface that all blockchain indexers will use.

type Subscription

type Subscription struct {
	C chan *UserTransaction

	Close func()
	// contains filtered or unexported fields
}

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) Close

func (idx *TxIndex) Close(ds repo.Datastore) error

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.

type UserTransaction

type UserTransaction struct {
	Tx      *transactions.Transaction
	ViewKey crypto.PrivKey
}

type WalletServerIndex

type WalletServerIndex struct {
	// contains filtered or unexported fields
}

WalletServerIndex is and implementation of the Indexer which indexes transactions on behalf of wallets. It allows for building lite wallets that tradeoff privacy vis-à-vis the server for fast syncing and instant access to coins.

func NewWalletServerIndex

func NewWalletServerIndex(ds repo.Datastore) (*WalletServerIndex, error)

NewWalletServerIndex returns a new WalletServerIndex.

func (*WalletServerIndex) Close

func (idx *WalletServerIndex) Close(ds repo.Datastore) error

Close closes the wallet server index

func (*WalletServerIndex) ConnectBlock

func (idx *WalletServerIndex) 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 (*WalletServerIndex) GetTransactionsIDs

func (idx *WalletServerIndex) GetTransactionsIDs(ds repo.Datastore, viewKey crypto.PrivKey) ([]types.ID, error)

GetTransactionsIDs returns the transaction IDs stored for the given viewKey

func (*WalletServerIndex) GetTxoProofs

func (idx *WalletServerIndex) GetTxoProofs(commitments []types.ID) ([]*blockchain.InclusionProof, types.ID, error)

GetTxoProofs returns the txo inclusion proof and merkle root for the provided commitments

func (*WalletServerIndex) Key

func (idx *WalletServerIndex) Key() string

Key returns the key of the index as a string.

func (*WalletServerIndex) Name

func (idx *WalletServerIndex) Name() string

Name returns the human-readable name of the index.

func (*WalletServerIndex) RegisterViewKey

func (idx *WalletServerIndex) RegisterViewKey(ds repo.Datastore, viewKey crypto.PrivKey, serializedUnlockingScript []byte) error

RegisterViewKey registers a new user with the index. It will track transactions for this user.

func (*WalletServerIndex) RescanViewkey

func (idx *WalletServerIndex) RescanViewkey(ds repo.Datastore, viewKey crypto.PrivKey, accumulatorCheckpoint *blockchain.Accumulator, checkpointHeight uint32, getBlockFunc func(uint32) (*blocks.Block, error)) error

RescanViewkey loads historical blocks from disk from the provided checkpoint (or genesis if checkpoint is nil) and scans them looking for transactions for the provided viewKey. If transactions are found the internal state is updated.

func (*WalletServerIndex) Subscribe

func (idx *WalletServerIndex) Subscribe() *Subscription

Subscribe returns a subscription to the stream of user transactions.

Jump to

Keyboard shortcuts

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