walletdata

package
v0.0.0-...-a0f938d Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: BlueOak-1.0.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTxIndexNotSupported = fmt.Errorf("database isn't configured for tx indexing")

Functions

func ReadUserConfigValue

func ReadUserConfigValue[T any](db UserConfigReader, key string, defaultValue ...T) T

Types

type DB

type DB[Tx any] struct {
	// contains filtered or unexported fields
}

DB is a storm-backed database for storing simple information in key-value pairs for a wallet. It can also be optionally used to index a wallet's transactions for subsequent quick querying and filtering.

func Initialize

func Initialize[Tx any](dbPath string, txIndexCfg *TxIndexDBConfig[Tx]) (*DB[Tx], error)

Initialize creates or open a database at the specified path. txIndexCfg is optional but must be provided if the database will be used for transaction indexing. If txIndexCfg.txVersion is different from the version last used by this database, the transactions index will be dropped and the wallet's transactions will need to be re-indexed.

func (*DB[Tx]) CountTransactions

func (db *DB[Tx]) CountTransactions(matchers ...q.Matcher) (int, error)

CountTransactions returns the number of transactions that match the specified criteria.

func (*DB[T]) DeleteUserConfigValue

func (db *DB[T]) DeleteUserConfigValue(key string) error

DeleteUserConfigValue deletes the user config data with the specified key.

func (*DB[T]) DeleteWalletConfigValue

func (db *DB[T]) DeleteWalletConfigValue(key string) error

DeleteWalletConfigValue deletes the wallet config data with the specified key.

func (*DB[Tx]) FindTransaction

func (db *DB[Tx]) FindTransaction(fieldName string, fieldValue interface{}) (*Tx, error)

FindTransaction looks up a transaction that has the specified value in the specified field. It's not an error if no transaction is found to match this criteria, instead a nil tx and a nil error are returned.

func (*DB[Tx]) FindTransactions

func (db *DB[Tx]) FindTransactions(offset, limit int, sort *SORT, matchers ...q.Matcher) ([]*Tx, error)

FindTransactions looks up and returns transactions that match the specified criteria and in the order specified by the sort argument. It is not an error if no transaction is found to match the provided criteria, instead an empty tx list and a nil error are returned. If no matcher is passed, all indexed transactions will be returned.

func (*DB[Tx]) IndexTransaction

func (db *DB[Tx]) IndexTransaction(tx *Tx) (bool, error)

IndexTransaction saves a transaction to the indexed transactions db. Returns true if the tx was previously saved.

func (*DB[T]) ReadUserConfigValue

func (db *DB[T]) ReadUserConfigValue(key string, valueOut interface{}) error

ReadUserConfigValue reads user configuration data from the database.

func (*DB[T]) ReadWalletConfigValue

func (db *DB[T]) ReadWalletConfigValue(key string, valueOut interface{}) error

ReadWalletConfigValue reads wallet configuration data from the database.

func (*DB[Tx]) RollbackTxIndexLastBlock

func (db *DB[Tx]) RollbackTxIndexLastBlock(height int32) error

RollbackTxIndexLastBlock is like SaveTxIndexLastBlock but it also deletes all previously indexed transactions whose block heights are above the specified height to allow subsequent re-indexing from the specified height+1.

func (*DB[Tx]) SaveTxIndexLastBlock

func (db *DB[Tx]) SaveTxIndexLastBlock(height int32) error

SaveTxIndexLastBlock saves the specified height as the last block height for which transactions are indexed. Subsequent tx indexing should start from this height+1.

func (*DB[T]) SaveUserConfigValue

func (db *DB[T]) SaveUserConfigValue(key string, value interface{}) error

SaveUserConfigValue saves user configuration data as a key-value pair.

func (*DB[T]) SaveWalletConfigValue

func (db *DB[T]) SaveWalletConfigValue(key string, value interface{}) error

SaveWalletConfigValue saves wallet configuration data as a key-value pair.

func (*DB[Tx]) TxIndexLastBlock

func (db *DB[Tx]) TxIndexLastBlock() (int32, error)

TxIndexLastBlock returns the highest block height for which transactions are indexed.

type SORT

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

func SortAscending

func SortAscending(fieldName string) *SORT

func SortDescending

func SortDescending(fieldName string) *SORT

type TxIndexDB

type TxIndexDB[T any] interface {
	TxIndexLastBlock() (int32, error)
	SaveTxIndexLastBlock(height int32) error
	RollbackTxIndexLastBlock(height int32) error
	IndexTransaction(tx *T) (bool, error)
	FindTransaction(fieldName string, fieldValue interface{}) (*T, error)
	FindTransactions(offset, limit int, sort *SORT, matchers ...q.Matcher) ([]*T, error)
	CountTransactions(matchers ...q.Matcher) (int, error)
}

TxIndexDB defines methods for saving and reading transactions to/from an indexed database.

type TxIndexDBConfig

type TxIndexDBConfig[Tx any] struct {
	// contains filtered or unexported fields
}

TxIndexDBConfig contains properties that are necessary for transaction indexing.

func NewTxIndexDBConfig

func NewTxIndexDBConfig[Tx any](txVersion uint32, txIDField, txBlockHeightField string, makeEmptyTx func() *Tx, txUpdateHook func(oldTx, newTx *Tx) (*Tx, error)) *TxIndexDBConfig[Tx]

NewTxIndexDBConfig creates a TxIndexDBConfig.

type UserConfigDB

type UserConfigDB interface {
	SaveUserConfigValue(key string, value interface{}) error
	ReadUserConfigValue(key string, valueOut interface{}) error
	DeleteUserConfigValue(key string) error
}

UserConfigDB defines methods for writing and reading user config information to/from a persistent data store.

type UserConfigReader

type UserConfigReader interface {
	ReadUserConfigValue(key string, valueOut interface{}) error
}

type WalletConfigDB

type WalletConfigDB interface {
	SaveWalletConfigValue(key string, value interface{}) error
	ReadWalletConfigValue(key string, valueOut interface{}) error
	DeleteWalletConfigValue(key string) error
}

WalletConfigDB defines methods for writing and reading wallet config information to/from a persistent data store.

Jump to

Keyboard shortcuts

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