indexer

package
v0.0.0-...-54f36b3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultIndexCacheSize is the default size of the indexer cache. The larger
	// the index cache size, the better the performance.
	DefaultIndexCacheSize = 1 << 30 // 5 GB

)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	NetworkStatus(context.Context) (*types.NetworkStatusResponse, error)
	PruneBlockchain(context.Context, int64) (int64, error)
	GetRawBlock(context.Context, *types.PartialBlockIdentifier) (*bitcoin.Block, []string, error)
	ParseBlock(
		context.Context,
		*bitcoin.Block,
		map[string]*storage.AccountCoin,
	) (*types.Block, error)
}

Client is used by the indexer to sync blocks.

type Indexer

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

Indexer caches blocks and provides balance query functionality.

func Initialize

func Initialize(
	ctx context.Context,
	cancel context.CancelFunc,
	config *configuration.Configuration,
	client Client,
	indexCacheSize int64,
) (*Indexer, error)

Initialize returns a new Indexer.

func (*Indexer) Block

func (i *Indexer) Block(
	ctx context.Context,
	network *types.NetworkIdentifier,
	blockIdentifier *types.PartialBlockIdentifier,
) (*types.Block, error)

Block is called by the syncer to fetch a block.

func (*Indexer) BlockAdded

func (i *Indexer) BlockAdded(ctx context.Context, block *types.Block) error

BlockAdded is called by the syncer when a block is added.

func (*Indexer) BlockRemoved

func (i *Indexer) BlockRemoved(
	ctx context.Context,
	blockIdentifier *types.BlockIdentifier,
) error

BlockRemoved is called by the syncer when a block is removed.

func (*Indexer) CloseDatabase

func (i *Indexer) CloseDatabase(ctx context.Context)

CloseDatabase closes a storage.Database. This should be called before exiting.

func (*Indexer) CurrentBlockIdentifier

func (i *Indexer) CurrentBlockIdentifier(
	ctx context.Context,
	transaction storage.DatabaseTransaction,
) (*types.BlockIdentifier, error)

CurrentBlockIdentifier returns the current head block identifier and is used to comply with the CoinStorageHelper interface.

func (*Indexer) GetBlockLazy

func (i *Indexer) GetBlockLazy(
	ctx context.Context,
	blockIdentifier *types.PartialBlockIdentifier,
) (*types.BlockResponse, error)

GetBlockLazy returns a *types.BlockResponse from the indexer's block storage. All transactions in a block must be fetched individually.

func (*Indexer) GetBlockTransaction

func (i *Indexer) GetBlockTransaction(
	ctx context.Context,
	blockIdentifier *types.BlockIdentifier,
	transactionIdentifier *types.TransactionIdentifier,
) (*types.Transaction, error)

GetBlockTransaction returns a *types.Transaction if it is in the provided *types.BlockIdentifier.

func (*Indexer) GetCoins

func (i *Indexer) GetCoins(
	ctx context.Context,
	accountIdentifier *types.AccountIdentifier,
) ([]*types.Coin, *types.BlockIdentifier, error)

GetCoins returns all unspent coins for a particular *types.AccountIdentifier.

func (*Indexer) GetScriptPubKeys

func (i *Indexer) GetScriptPubKeys(
	ctx context.Context,
	coins []*types.Coin,
) ([]*bitcoin.ScriptPubKey, error)

GetScriptPubKeys gets the ScriptPubKey for a collection of *types.CoinIdentifier. It also confirms that the amount provided with each coin is valid.

func (*Indexer) NetworkStatus

func (i *Indexer) NetworkStatus(
	ctx context.Context,
	network *types.NetworkIdentifier,
) (*types.NetworkStatusResponse, error)

NetworkStatus is called by the syncer to get the current network status.

func (*Indexer) Prune

func (i *Indexer) Prune(ctx context.Context) error

Prune attempts to prune blocks in bitcoind every pruneFrequency.

func (*Indexer) Sync

func (i *Indexer) Sync(ctx context.Context) error

Sync attempts to index Bitcoin blocks using the bitcoin.Client until stopped.

Jump to

Keyboard shortcuts

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