walletdata

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DCRDbName = "walletData.db"
	BTCDBName = "neutrino.db"
	LTCDBName = "neutrino.db"
	OldDbName = "tx.db"

	TxBucketName = "TxIndexInfo"
	KeyDbVersion = "DbVersion"

	// TxDbVersion is necessary to force re-indexing if changes are made to the structure of data being stored.
	// Increment this version number if db structure changes such that client apps need to re-index.
	TxDbVersion uint32 = 3
)
View Source
const KeyEndBlock = "EndBlock"
View Source
const MaxReOrgBlocks = 6

Variables

This section is empty.

Functions

This section is empty.

Types

type BTCBucket

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

func (*BTCBucket) CreateBucket

func (b *BTCBucket) CreateBucket(key []byte) (walletdb.ReadWriteBucket, error)

CreateBucket creates and returns a new nested bucket with the given key. Returns ErrBucketExists if the bucket already exists, ErrBucketNameRequired if the key is empty, or ErrIncompatibleValue if the key value is otherwise invalid for the particular database implementation. Other errors are possible depending on the implementation.

func (*BTCBucket) CreateBucketIfNotExists

func (b *BTCBucket) CreateBucketIfNotExists(key []byte) (walletdb.ReadWriteBucket, error)

CreateBucketIfNotExists creates and returns a new nested bucket with the given key if it does not already exist. Returns ErrBucketNameRequired if the key is empty or ErrIncompatibleValue if the key value is otherwise invalid for the particular database backend. Other errors are possible depending on the implementation.

func (*BTCBucket) Delete

func (b *BTCBucket) Delete(key []byte) error

Delete removes the specified key from the bucket. Deleting a key that does not exist does not return an error. Returns ErrTxNotWritable if attempted against a read-only transaction.

func (*BTCBucket) DeleteNestedBucket

func (b *BTCBucket) DeleteNestedBucket(key []byte) error

DeleteNestedBucket removes a nested bucket with the given key. Returns ErrTxNotWritable if attempted against a read-only transaction and ErrBucketNotFound if the specified bucket does not exist.

func (*BTCBucket) ForEach

func (b *BTCBucket) ForEach(fn func(k, v []byte) error) error

ForEach invokes the passed function with every key/value pair in the bucket. This includes nested buckets, in which case the value is nil, but it does not include the key/value pairs within those nested buckets.

NOTE: The values returned by this function are only valid during a transaction. Attempting to access them after a transaction has ended results in undefined behavior. This constraint prevents additional data copies and allows support for memory-mapped database implementations.

func (*BTCBucket) Get

func (b *BTCBucket) Get(key []byte) []byte

Get returns the value for the given key. Returns nil if the key does not exist in this bucket (or nested buckets).

NOTE: The value returned by this function is only valid during a transaction. Attempting to access it after a transaction has ended results in undefined behavior. This constraint prevents additional data copies and allows support for memory-mapped database implementations.

func (*BTCBucket) NestedReadBucket

func (b *BTCBucket) NestedReadBucket(key []byte) walletdb.ReadBucket

NestedReadBucket retrieves a nested bucket with the given key. Returns nil if the bucket does not exist.

func (*BTCBucket) NestedReadWriteBucket

func (b *BTCBucket) NestedReadWriteBucket(key []byte) walletdb.ReadWriteBucket

NestedReadWriteBucket retrieves a nested bucket with the given key. Returns nil if the bucket does not exist.

func (*BTCBucket) NextSequence

func (b *BTCBucket) NextSequence() (uint64, error)

NextSequence returns an autoincrementing integer for the bucket.

func (*BTCBucket) Put

func (b *BTCBucket) Put(key, value []byte) error

Put saves the specified key/value pair to the bucket. Keys that do not already exist are added and keys that already exist are overwritten. Returns ErrTxNotWritable if attempted against a read-only transaction.

func (*BTCBucket) ReadCursor

func (b *BTCBucket) ReadCursor() walletdb.ReadCursor

func (*BTCBucket) ReadWriteCursor

func (b *BTCBucket) ReadWriteCursor() walletdb.ReadWriteCursor

ReadWriteCursor returns a new cursor, allowing for iteration over the bucket's key/value pairs and nested buckets in forward or backward order.

func (*BTCBucket) Sequence

func (b *BTCBucket) Sequence() uint64

Sequence returns the current integer for the bucket without incrementing it.

func (*BTCBucket) SetSequence

func (b *BTCBucket) SetSequence(v uint64) error

SetSequence updates the sequence number for the bucket.

func (*BTCBucket) Tx

func (b *BTCBucket) Tx() walletdb.ReadWriteTx

Tx returns the bucket's transaction.

type BTCDB

type BTCDB struct {
	Bolt *bbolt.DB
}

func (*BTCDB) BeginReadTx

func (db *BTCDB) BeginReadTx() (walletdb.ReadTx, error)

BeginReadTx opens a database read transaction.

func (*BTCDB) BeginReadWriteTx

func (db *BTCDB) BeginReadWriteTx() (walletdb.ReadWriteTx, error)

BeginReadWriteTx opens a database read+write transaction.

func (*BTCDB) Close

func (db *BTCDB) Close() error

Close cleanly shuts down the database and syncs all data.

func (*BTCDB) Copy

func (db *BTCDB) Copy(w io.Writer) error

Copy writes a copy of the database to the provided writer. This call will start a read-only transaction to perform all operations.

func (*BTCDB) PrintStats

func (db *BTCDB) PrintStats() string

PrintStats returns all collected stats pretty printed into a string.

func (*BTCDB) Update

func (db *BTCDB) Update(f func(tx walletdb.ReadWriteTx) error, reset func()) error

Update opens a database read/write transaction and executes the function f with the transaction passed as a parameter. After f exits, if f did not error, the transaction is committed. Otherwise, if f did error, the transaction is rolled back. If the rollback fails, the original error returned by f is still returned. If the commit fails, the commit error is returned. As callers may expect retries of the f closure (depending on the database backend used), the reset function will be called before each retry respectively.

NOTE: For new code, this method should be used directly instead of the package level Update() function.

func (*BTCDB) View

func (db *BTCDB) View(f func(tx walletdb.ReadTx) error, reset func()) error

View opens a database read transaction and executes the function f with the transaction passed as a parameter. After f exits, the transaction is rolled back. If f errors, its error is returned, not a rollback error (if any occur). The passed reset function is called before the start of the transaction and can be used to reset intermediate state. As callers may expect retries of the f closure (depending on the database backend used), the reset function will be called before each retry respectively.

NOTE: For new code, this method should be used directly instead of the package level View() function.

type BTCTX

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

func (*BTCTX) Commit

func (tx *BTCTX) Commit() error

Commit commits all changes that have been on the transaction's root buckets and all of their sub-buckets to persistent storage.

func (*BTCTX) CreateTopLevelBucket

func (tx *BTCTX) CreateTopLevelBucket(key []byte) (walletdb.ReadWriteBucket, error)

CreateTopLevelBucket creates the top level bucket for a key if it does not exist. The newly-created bucket it returned.

func (*BTCTX) DeleteTopLevelBucket

func (tx *BTCTX) DeleteTopLevelBucket(key []byte) error

DeleteTopLevelBucket deletes the top level bucket for a key. This errors if the bucket can not be found or the key keys a single value instead of a bucket.

func (*BTCTX) ForEachBucket

func (tx *BTCTX) ForEachBucket(fn func(key []byte) error) error

ForEachBucket will iterate through all top level buckets.

func (*BTCTX) OnCommit

func (tx *BTCTX) OnCommit(f func())

OnCommit takes a function closure that will be executed when the transaction successfully gets committed.

func (*BTCTX) ReadBucket

func (tx *BTCTX) ReadBucket(key []byte) walletdb.ReadBucket

ReadBucket opens the root bucket for read only access. If the bucket described by the key does not exist, nil is returned.

func (*BTCTX) ReadWriteBucket

func (tx *BTCTX) ReadWriteBucket(key []byte) walletdb.ReadWriteBucket

ReadWriteBucket opens the root bucket for read/write access. If the bucket described by the key does not exist, nil is returned.

func (*BTCTX) Rollback

func (tx *BTCTX) Rollback() error

Rollback closes the transaction, discarding changes (if any) if the database was modified by a write transaction.

type DB

type DB struct {
	BTC *BTCDB
	LTC *LTCDB

	Path string
	// contains filtered or unexported fields
}

func Initialize

func Initialize(dbPath string, txData interface{}) (*DB, error)

Initialize opens the existing storm db at `dbPath` and checks the database version for compatibility. If there is a version mismatch or the db does not exist at `dbPath`, a new db is created and the current db version number saved to the db.

func (*DB) ClearSavedTransactions

func (db *DB) ClearSavedTransactions(emptyTxPointer interface{}) error

func (*DB) Close

func (db *DB) Close() error

Close closes the wallet data database.

func (*DB) Count

func (db *DB) Count(txFilter int32, requiredConfirmations, bestBlock int32, txObj interface{}) (int, error)

Count queries the db for transactions of the `txObj` type to return the number of records matching the specified `txFilter`.

func (*DB) Find

func (db *DB) Find(matcher q.Matcher, transactions interface{}) error

func (*DB) FindAll

func (db *DB) FindAll(fieldName string, value interface{}, txObj interface{}) error

func (*DB) FindLast

func (db *DB) FindLast(fieldName string, value interface{}, txObj interface{}) error

func (*DB) FindOne

func (db *DB) FindOne(fieldName string, value interface{}, obj interface{}) error

func (*DB) LastIndexPoint

func (db *DB) LastIndexPoint() (int32, error)

func (*DB) Read

func (db *DB) Read(offset, limit, txFilter int32, newestFirst bool, requiredConfirmations, bestBlock int32, transactions interface{}) error

Read queries the db for `limit` count transactions that match the specified `txFilter` starting from the specified `offset`; and saves the transactions found to the received `transactions` object. `transactions` should be a pointer to a slice of Transaction objects.

func (*DB) ReadIndexingStartBlock

func (db *DB) ReadIndexingStartBlock() (int32, error)

ReadIndexingStartBlock checks if the end block height was saved from last indexing operation. If so, the end block height - MaxReOrgBlocks is returned. Otherwise, 0 is returned to begin indexing from height 0.

func (*DB) SaveLastIndexPoint

func (db *DB) SaveLastIndexPoint(endBlockHeight int32) error

func (*DB) SaveOrUpdate

func (db *DB) SaveOrUpdate(emptyTxPointer, record interface{}) (overwritten bool, err error)

SaveOrUpdate saves a transaction to the database and would overwrite if a transaction with same hash exists

func (*DB) SaveOrUpdateVspdRecord

func (db *DB) SaveOrUpdateVspdRecord(emptyTxPointer, record interface{}) (updated bool, err error)

func (*DB) SetTicketExpiry

func (db *DB) SetTicketExpiry(val int32) *DB

SetTicketExpiry sets the ticket expiry value required when filtering txs

func (*DB) SetTicketMaturity

func (db *DB) SetTicketMaturity(val int32) *DB

SetTicketMaturity sets the ticket maturity value required when filterig txs.

type LTCBucket

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

func (*LTCBucket) CreateBucket

func (b *LTCBucket) CreateBucket(key []byte) (walletdb.ReadWriteBucket, error)

CreateBucket creates and returns a new nested bucket with the given key. Returns ErrBucketExists if the bucket already exists, ErrBucketNameRequired if the key is empty, or ErrIncompatibleValue if the key value is otherwise invalid for the particular database implementation. Other errors are possible depending on the implementation.

func (*LTCBucket) CreateBucketIfNotExists

func (b *LTCBucket) CreateBucketIfNotExists(key []byte) (walletdb.ReadWriteBucket, error)

CreateBucketIfNotExists creates and returns a new nested bucket with the given key if it does not already exist. Returns ErrBucketNameRequired if the key is empty or ErrIncompatibleValue if the key value is otherwise invalid for the particular database backend. Other errors are possible depending on the implementation.

func (*LTCBucket) Delete

func (b *LTCBucket) Delete(key []byte) error

Delete removes the specified key from the bucket. Deleting a key that does not exist does not return an error. Returns ErrTxNotWritable if attempted against a read-only transaction.

func (*LTCBucket) DeleteNestedBucket

func (b *LTCBucket) DeleteNestedBucket(key []byte) error

DeleteNestedBucket removes a nested bucket with the given key. Returns ErrTxNotWritable if attempted against a read-only transaction and ErrBucketNotFound if the specified bucket does not exist.

func (*LTCBucket) ForEach

func (b *LTCBucket) ForEach(fn func(k, v []byte) error) error

ForEach invokes the passed function with every key/value pair in the bucket. This includes nested buckets, in which case the value is nil, but it does not include the key/value pairs within those nested buckets.

NOTE: The values returned by this function are only valid during a transaction. Attempting to access them after a transaction has ended results in undefined behavior. This constraint prevents additional data copies and allows support for memory-mapped database implementations.

func (*LTCBucket) Get

func (b *LTCBucket) Get(key []byte) []byte

Get returns the value for the given key. Returns nil if the key does not exist in this bucket (or nested buckets).

NOTE: The value returned by this function is only valid during a transaction. Attempting to access it after a transaction has ended results in undefined behavior. This constraint prevents additional data copies and allows support for memory-mapped database implementations.

func (*LTCBucket) NestedReadBucket

func (b *LTCBucket) NestedReadBucket(key []byte) walletdb.ReadBucket

NestedReadBucket retrieves a nested bucket with the given key. Returns nil if the bucket does not exist.

func (*LTCBucket) NestedReadWriteBucket

func (b *LTCBucket) NestedReadWriteBucket(key []byte) walletdb.ReadWriteBucket

NestedReadWriteBucket retrieves a nested bucket with the given key. Returns nil if the bucket does not exist.

func (*LTCBucket) NextSequence

func (b *LTCBucket) NextSequence() (uint64, error)

NextSequence returns an autoincrementing integer for the bucket.

func (*LTCBucket) Put

func (b *LTCBucket) Put(key, value []byte) error

Put saves the specified key/value pair to the bucket. Keys that do not already exist are added and keys that already exist are overwritten. Returns ErrTxNotWritable if attempted against a read-only transaction.

func (*LTCBucket) ReadCursor

func (b *LTCBucket) ReadCursor() walletdb.ReadCursor

func (*LTCBucket) ReadWriteCursor

func (b *LTCBucket) ReadWriteCursor() walletdb.ReadWriteCursor

ReadWriteCursor returns a new cursor, allowing for iteration over the bucket's key/value pairs and nested buckets in forward or backward order.

func (*LTCBucket) Sequence

func (b *LTCBucket) Sequence() uint64

Sequence returns the current integer for the bucket without incrementing it.

func (*LTCBucket) SetSequence

func (b *LTCBucket) SetSequence(v uint64) error

SetSequence updates the sequence number for the bucket.

func (*LTCBucket) Tx

func (b *LTCBucket) Tx() walletdb.ReadWriteTx

Tx returns the bucket's transaction.

type LTCDB

type LTCDB struct {
	Bolt *bbolt.DB
}

func (*LTCDB) BeginReadTx

func (db *LTCDB) BeginReadTx() (walletdb.ReadTx, error)

BeginReadTx opens a database read transaction.

func (*LTCDB) BeginReadWriteTx

func (db *LTCDB) BeginReadWriteTx() (walletdb.ReadWriteTx, error)

BeginReadWriteTx opens a database read+write transaction.

func (*LTCDB) Close

func (db *LTCDB) Close() error

Close cleanly shuts down the database and syncs all data.

func (*LTCDB) Copy

func (db *LTCDB) Copy(w io.Writer) error

Copy writes a copy of the database to the provided writer. This call will start a read-only transaction to perform all operations.

func (*LTCDB) PrintStats

func (db *LTCDB) PrintStats() string

PrintStats returns all collected stats pretty printed into a string.

func (*LTCDB) Update

func (db *LTCDB) Update(f func(tx walletdb.ReadWriteTx) error, reset func()) error

Update opens a database read/write transaction and executes the function f with the transaction passed as a parameter. After f exits, if f did not error, the transaction is committed. Otherwise, if f did error, the transaction is rolled back. If the rollback fails, the original error returned by f is still returned. If the commit fails, the commit error is returned. As callers may expect retries of the f closure (depending on the database backend used), the reset function will be called before each retry respectively.

NOTE: For new code, this method should be used directly instead of the package level Update() function.

func (*LTCDB) View

func (db *LTCDB) View(f func(tx walletdb.ReadTx) error, reset func()) error

View opens a database read transaction and executes the function f with the transaction passed as a parameter. After f exits, the transaction is rolled back. If f errors, its error is returned, not a rollback error (if any occur). The passed reset function is called before the start of the transaction and can be used to reset intermediate state. As callers may expect retries of the f closure (depending on the database backend used), the reset function will be called before each retry respectively.

NOTE: For new code, this method should be used directly instead of the package level View() function.

type LTCTX

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

func (*LTCTX) Commit

func (tx *LTCTX) Commit() error

Commit commits all changes that have been on the transaction's root buckets and all of their sub-buckets to persistent storage.

func (*LTCTX) CreateTopLevelBucket

func (tx *LTCTX) CreateTopLevelBucket(key []byte) (walletdb.ReadWriteBucket, error)

CreateTopLevelBucket creates the top level bucket for a key if it does not exist. The newly-created bucket it returned.

func (*LTCTX) DeleteTopLevelBucket

func (tx *LTCTX) DeleteTopLevelBucket(key []byte) error

DeleteTopLevelBucket deletes the top level bucket for a key. This errors if the bucket can not be found or the key keys a single value instead of a bucket.

func (*LTCTX) ForEachBucket

func (tx *LTCTX) ForEachBucket(fn func(key []byte) error) error

ForEachBucket will iterate through all top level buckets.

func (*LTCTX) OnCommit

func (tx *LTCTX) OnCommit(f func())

OnCommit takes a function closure that will be executed when the transaction successfully gets committed.

func (*LTCTX) ReadBucket

func (tx *LTCTX) ReadBucket(key []byte) walletdb.ReadBucket

ReadBucket opens the root bucket for read only access. If the bucket described by the key does not exist, nil is returned.

func (*LTCTX) ReadWriteBucket

func (tx *LTCTX) ReadWriteBucket(key []byte) walletdb.ReadWriteBucket

ReadWriteBucket opens the root bucket for read/write access. If the bucket described by the key does not exist, nil is returned.

func (*LTCTX) Rollback

func (tx *LTCTX) Rollback() error

Rollback closes the transaction, discarding changes (if any) if the database was modified by a write transaction.

Jump to

Keyboard shortcuts

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