bolt

package
v0.6.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DBVersion = uint32(len(upgrades))

DBVersion is the latest version of the database that is understood. Databases with recorded versions higher than this will fail to open (meaning any upgrades prevent reverting to older software).

Variables

This section is empty.

Functions

func NewDB

func NewDB(dbPath string, logger dex.Logger, opts ...Opts) (dexdb.DB, error)

NewDB is a constructor for a *BoltDB.

Types

type BoltDB

type BoltDB struct {
	*bbolt.DB
	// contains filtered or unexported fields
}

BoltDB is a bbolt-based database backend for a DEX client. BoltDB satisfies the db.DB interface defined at decred.org/dcrdex/client/db.

func (*BoltDB) Account

func (db *BoltDB) Account(url string) (*dexdb.AccountInfo, error)

Account gets the AccountInfo associated with the specified DEX address.

func (*BoltDB) AccountOrders

func (db *BoltDB) AccountOrders(dex string, n int, since uint64) ([]*dexdb.MetaOrder, error)

AccountOrders retrieves all orders associated with the specified DEX. n = 0 applies no limit on number of orders returned. since = 0 is equivalent to disabling the time filter, since no orders were created before 1970.

func (*BoltDB) AccountProof added in v0.2.0

func (db *BoltDB) AccountProof(url string) (*dexdb.AccountProof, error)

func (*BoltDB) Accounts

func (db *BoltDB) Accounts() ([]*dexdb.AccountInfo, error)

Accounts returns a list of DEX Accounts. The DB is designed to have a single account per DEX, so the account itself is identified by the DEX host. TODO: allow bonds filter based on lockTime.

func (*BoltDB) AckNotification

func (db *BoltDB) AckNotification(id []byte) error

AckNotification sets the acknowledgement for a notification.

func (*BoltDB) ActiveBotPrograms added in v0.6.0

func (db *BoltDB) ActiveBotPrograms() (pgms map[uint64]*dexdb.BotProgram, err error)

ActiveBotPrograms loads a list of active bot program IDs.

func (*BoltDB) ActiveDEXOrders

func (db *BoltDB) ActiveDEXOrders(dex string) ([]*dexdb.MetaOrder, error)

ActiveDEXOrders retrieves all orders for the specified DEX.

func (*BoltDB) ActiveMatches

func (db *BoltDB) ActiveMatches() ([]*dexdb.MetaMatch, error)

ActiveMatches retrieves the matches that are in an active state, which is any match that is still active.

func (*BoltDB) ActiveOrders

func (db *BoltDB) ActiveOrders() ([]*dexdb.MetaOrder, error)

ActiveOrders retrieves all orders which appear to be in an active state, which is either in the epoch queue or in the order book.

func (*BoltDB) AddBond added in v0.6.0

func (db *BoltDB) AddBond(host string, bond *db.Bond) error

AddBond saves a new Bond or updates an existing bond for an existing DEX account.

func (*BoltDB) Backup

func (db *BoltDB) Backup() error

Backup makes a copy of the database in the "backup" folder, overwriting any existing backup.

func (*BoltDB) BackupTo added in v0.4.2

func (db *BoltDB) BackupTo(dst string, overwrite, compact bool) error

BackupTo makes a copy of the database to the specified file, optionally overwriting and compacting the DB.

func (*BoltDB) BondRefunded added in v0.6.0

func (db *BoltDB) BondRefunded(host string, assetID uint32, bondCoinID []byte) error

BondRefunded marks a DEX account bond as refunded by the client wallet.

func (*BoltDB) ConfirmBond added in v0.6.0

func (db *BoltDB) ConfirmBond(host string, assetID uint32, bondCoinID []byte) error

ConfirmBond marks a DEX account bond as confirmed by the DEX.

func (*BoltDB) CreateAccount

func (db *BoltDB) CreateAccount(ai *dexdb.AccountInfo) error

CreateAccount saves the AccountInfo. If an account already exists for this DEX, it will return an error.

func (*BoltDB) DEXOrdersWithActiveMatches

func (db *BoltDB) DEXOrdersWithActiveMatches(dex string) ([]order.OrderID, error)

DEXOrdersWithActiveMatches retrieves order IDs for any order that has active matches, regardless of whether the order itself is in an active state.

func (*BoltDB) DeleteInactiveMatches added in v0.5.0

func (db *BoltDB) DeleteInactiveMatches(ctx context.Context, olderThan *time.Time,
	perMatchFn func(mtch *dexdb.MetaMatch, isSell bool) error) (int, error)

DeleteInactiveMatches deletes matches that are no longer needed for normal operations. Optionally accepts a time to delete matches with a later time stamp. Accepts an optional function to perform on deleted matches.

func (*BoltDB) DeleteInactiveOrders added in v0.5.0

func (db *BoltDB) DeleteInactiveOrders(ctx context.Context, olderThan *time.Time,
	perOrderFn func(ords *dexdb.MetaOrder) error) (int, error)

DeleteInactiveOrders deletes orders that are no longer needed for normal operations. Optionally accepts a time to delete orders with a later time stamp. Accepts an optional function to perform on deleted orders.

func (*BoltDB) DisableAccount

func (db *BoltDB) DisableAccount(url string) error

DisableAccount disables the account associated with the given host and archives it. The Accounts and Account methods will no longer find the disabled account.

TODO: Add disabledAccounts method for retrieval of a disabled account and possible recovery of the account data.

func (*BoltDB) DisabledRateSources added in v0.5.0

func (db *BoltDB) DisabledRateSources() (disabledSources []string, err error)

DisabledRateSources retrieves a map of disabled fiat rate sources.

func (*BoltDB) LinkOrder

func (db *BoltDB) LinkOrder(oid, linkedID order.OrderID) error

LinkOrder sets the linked order.

func (*BoltDB) ListAccounts

func (db *BoltDB) ListAccounts() ([]string, error)

ListAccounts returns a list of DEX URLs. The DB is designed to have a single account per DEX, so the account itself is identified by the DEX URL.

func (*BoltDB) MarketOrders

func (db *BoltDB) MarketOrders(dex string, base, quote uint32, n int, since uint64) ([]*dexdb.MetaOrder, error)

MarketOrders retrieves all orders for the specified DEX and market. n = 0 applies no limit on number of orders returned. since = 0 is equivalent to disabling the time filter, since no orders were created before 1970.

func (*BoltDB) MatchesForOrder

func (db *BoltDB) MatchesForOrder(oid order.OrderID, excludeCancels bool) ([]*dexdb.MetaMatch, error)

MatchesForOrder retrieves the matches for the specified order ID.

func (*BoltDB) NextBondKeyIndex added in v0.6.0

func (db *BoltDB) NextBondKeyIndex(assetID uint32) (uint32, error)

NextBondKeyIndex returns the next bond key index and increments the stored value so that subsequent calls will always return a higher index.

func (*BoltDB) NotificationsN

func (db *BoltDB) NotificationsN(n int) ([]*dexdb.Notification, error)

NotificationsN reads out the N most recent notifications.

func (*BoltDB) Order

func (db *BoltDB) Order(oid order.OrderID) (mord *dexdb.MetaOrder, err error)

Order fetches a MetaOrder by order ID.

func (*BoltDB) Orders

func (db *BoltDB) Orders(orderFilter *dexdb.OrderFilter) (ords []*dexdb.MetaOrder, err error)

Orders fetches a slice of orders, sorted by descending time, and filtered with the provided OrderFilter. Orders does not return cancel orders.

func (*BoltDB) PrimaryCredentials added in v0.4.0

func (db *BoltDB) PrimaryCredentials() (creds *dexdb.PrimaryCredentials, err error)

PrimaryCredentials retrieves the *PrimaryCredentials, if they are stored. It is an error if none have been stored.

func (*BoltDB) Recrypt added in v0.4.0

func (db *BoltDB) Recrypt(creds *dexdb.PrimaryCredentials, oldCrypter, newCrypter encrypt.Crypter) (walletUpdates map[uint32][]byte, acctUpdates map[string][]byte, err error)

Recrypt re-encrypts the wallet passwords and account private keys. As a convenience, the provided *PrimaryCredentials are stored under the same transaction.

func (*BoltDB) RetireBotProgram added in v0.6.0

func (db *BoltDB) RetireBotProgram(pgmID uint64) error

RetireBotProgram deletes the bot program from the database.

func (*BoltDB) Run

func (db *BoltDB) Run(ctx context.Context)

Run waits for context cancellation and closes the database.

func (*BoltDB) SaveBotProgram added in v0.6.0

func (db *BoltDB) SaveBotProgram(pgm *dexdb.BotProgram) (pgmID uint64, err error)

SaveBotProgram saves data associated with a bot program. A unique ID is returned that can be used to address this program in future queries.

func (*BoltDB) SaveDisabledRateSources added in v0.5.0

func (db *BoltDB) SaveDisabledRateSources(disabledSources []string) error

SaveDisabledRateSources updates disabled fiat rate sources.

func (*BoltDB) SaveNotification

func (db *BoltDB) SaveNotification(note *dexdb.Notification) error

SaveNotification saves the notification.

func (*BoltDB) SeedGenerationTime added in v0.5.0

func (db *BoltDB) SeedGenerationTime() (uint64, error)

SeedGenerationTime returns the time the app seed was generated, if it was stored. It returns dexdb.ErrNoSeedGenTime if it was not stored.

func (*BoltDB) SetPrimaryCredentials added in v0.4.0

func (db *BoltDB) SetPrimaryCredentials(creds *dexdb.PrimaryCredentials) error

SetPrimaryCredentials validates and stores the PrimaryCredentials.

func (*BoltDB) SetSeedGenerationTime added in v0.5.0

func (db *BoltDB) SetSeedGenerationTime(time uint64) error

SetSeedGenerationTime stores the time the app seed was generated.

func (*BoltDB) SetWalletPassword

func (db *BoltDB) SetWalletPassword(wid []byte, newEncPW []byte) error

SetWalletPassword set the encrypted password field for the wallet.

func (*BoltDB) StoreAccountProof added in v0.6.0

func (db *BoltDB) StoreAccountProof(proof *dexdb.AccountProof) error

StoreAccountProof marks the account as paid with the legacy registration fee by setting the "fee proof".

func (*BoltDB) UpdateAccountInfo added in v0.5.0

func (db *BoltDB) UpdateAccountInfo(ai *dexdb.AccountInfo) error

UpdateAccountInfo updates the account info for an existing account with the same Host as the parameter. If no account exists with this host, an error is returned.

func (*BoltDB) UpdateBalance

func (db *BoltDB) UpdateBalance(wid []byte, bal *dexdb.Balance) error

UpdateBalance updates balance in the wallet bucket.

func (*BoltDB) UpdateBotProgram added in v0.6.0

func (db *BoltDB) UpdateBotProgram(pgmID uint64, pgm *dexdb.BotProgram) error

UpdateBotProgram updates the data associated with a running bot program.

func (*BoltDB) UpdateMatch

func (db *BoltDB) UpdateMatch(m *dexdb.MetaMatch) error

UpdateMatch updates the match information in the database. Any existing entry for the same match ID will be overwritten without indication.

func (*BoltDB) UpdateOrder

func (db *BoltDB) UpdateOrder(m *dexdb.MetaOrder) error

UpdateOrder saves the order information in the database. Any existing order info for the same order ID will be overwritten without indication.

func (*BoltDB) UpdateOrderMetaData

func (db *BoltDB) UpdateOrderMetaData(oid order.OrderID, md *dexdb.OrderMetaData) error

UpdateOrderMetaData updates the order metadata, not including the Host.

func (*BoltDB) UpdateOrderStatus

func (db *BoltDB) UpdateOrderStatus(oid order.OrderID, status order.OrderStatus) error

UpdateOrderStatus sets the order status for an order.

func (*BoltDB) UpdateWallet

func (db *BoltDB) UpdateWallet(wallet *dexdb.Wallet) error

UpdateWallet adds a wallet to the database.

func (*BoltDB) UpdateWalletStatus added in v0.6.0

func (db *BoltDB) UpdateWalletStatus(wid []byte, disable bool) error

UpdateWalletStatus updates a wallet's status.

func (*BoltDB) Wallet

func (db *BoltDB) Wallet(wid []byte) (wallet *dexdb.Wallet, err error)

Wallet loads a single wallet from the database.

func (*BoltDB) Wallets

func (db *BoltDB) Wallets() ([]*dexdb.Wallet, error)

Wallets loads all wallets from the database.

type Opts added in v0.5.8

type Opts struct {
	BackupOnShutdown bool // default is true
}

Opts is a set of options for the DB.

Jump to

Keyboard shortcuts

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