Documentation ¶
Index ¶
- Constants
- func DropTxIndex(ds repo.Datastore) error
- func DropWalletServerIndex(ds repo.Datastore) error
- func UseLogger(logger *logger.Logger)
- type IndexManager
- type Indexer
- type Subscription
- type TxIndex
- func (idx *TxIndex) Close(ds repo.Datastore) error
- 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
- type UserTransaction
- type WalletServerIndex
- func (idx *WalletServerIndex) Close(ds repo.Datastore) error
- func (idx *WalletServerIndex) ConnectBlock(dbtx datastore.Txn, blk *blocks.Block) error
- func (idx *WalletServerIndex) GetTransactionsIDs(ds repo.Datastore, viewKey crypto.PrivKey) ([]types.ID, error)
- func (idx *WalletServerIndex) GetTxoProofs(commitments []types.ID) ([]*blockchain.InclusionProof, types.ID, error)
- func (idx *WalletServerIndex) Key() string
- func (idx *WalletServerIndex) Name() string
- func (idx *WalletServerIndex) RegisterViewKey(ds repo.Datastore, viewKey crypto.PrivKey, serializedLockingScript []byte) error
- func (idx *WalletServerIndex) RegistrationExists(ds repo.Datastore, viewKey crypto.PrivKey) (bool, error)
- func (idx *WalletServerIndex) RescanViewkey(ds repo.Datastore, viewKey crypto.PrivKey, ...) error
- func (idx *WalletServerIndex) Subscribe() *Subscription
Constants ¶
const TxIndexName = "transaction index"
Variables ¶
This section is empty.
Functions ¶
func DropTxIndex ¶
func DropWalletServerIndex ¶
DropWalletServerIndex deletes the wallet server index from the datastore
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 ¶
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 (*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.
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, serializedLockingScript []byte) error
RegisterViewKey registers a new user with the index. It will track transactions for this user.
func (*WalletServerIndex) RegistrationExists ¶
func (idx *WalletServerIndex) RegistrationExists(ds repo.Datastore, viewKey crypto.PrivKey) (bool, error)
RegistrationExists returns whether the viewkey is currently registered in the index
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.