decred.org/dcrdex@v1.0.5/client/db/interface.go (about) 1 // This code is available on the terms of the project LICENSE.md file, 2 // also available online at https://blueoakcouncil.org/license/1.0.0. 3 4 package db 5 6 import ( 7 "context" 8 "time" 9 10 "decred.org/dcrdex/dex" 11 "decred.org/dcrdex/dex/encrypt" 12 "decred.org/dcrdex/dex/order" 13 ) 14 15 // DB is an interface that must be satisfied by Bison Wallet persistent storage 16 // manager. 17 type DB interface { 18 dex.Runner 19 // SetPrimaryCredentials sets the initial *PrimaryCredentials. 20 SetPrimaryCredentials(creds *PrimaryCredentials) error 21 // PrimaryCredentials fetches the *PrimaryCredentials. 22 PrimaryCredentials() (*PrimaryCredentials, error) 23 // Recrypt re-encrypts the wallet passwords and account private keys, and 24 // stores the new *PrimaryCredentials. 25 Recrypt(creds *PrimaryCredentials, oldCrypter, newCrypter encrypt.Crypter) ( 26 walletUpdates map[uint32][]byte, acctUpdates map[string][]byte, err error) 27 // ListAccounts returns a list of DEX URLs. The DB is designed to have a 28 // single account per DEX, so the account is uniquely identified by the DEX 29 // host. 30 ListAccounts() ([]string, error) 31 // Accounts retrieves all accounts. 32 Accounts() ([]*AccountInfo, error) 33 // Account gets the AccountInfo associated with the specified DEX node. 34 Account(host string) (*AccountInfo, error) 35 // CreateAccount saves the AccountInfo. 36 CreateAccount(ai *AccountInfo) error 37 // UpdateAccountInfo updates the account info for an existing account with 38 // the same Host as the parameter. If no account exists with this host, 39 // an error is returned. 40 UpdateAccountInfo(ai *AccountInfo) error 41 // AddBond saves a new Bond or updates an existing bond for a DEX. 42 AddBond(host string, bond *Bond) error 43 // NextBondKeyIndex returns the next bond key index and increments the 44 // stored value so that subsequent calls will always return a higher index. 45 NextBondKeyIndex(assetID uint32) (uint32, error) 46 // ConfirmBond records that a bond has been accepted by a DEX. 47 ConfirmBond(host string, assetID uint32, bondCoinID []byte) error 48 // BondRefunded records that a bond has been refunded. 49 BondRefunded(host string, assetID uint32, bondCoinID []byte) error 50 // ToggleAccountStatus enables or disables the account associated with the 51 // given host. 52 ToggleAccountStatus(host string, disable bool) error 53 // UpdateOrder saves the order information in the database. Any existing 54 // order info will be overwritten without indication. 55 UpdateOrder(m *MetaOrder) error 56 // ActiveOrders retrieves all orders which appear to be in an active state, 57 // which is either in the epoch queue or in the order book. 58 ActiveOrders() ([]*MetaOrder, error) 59 // AccountOrders retrieves all orders associated with the specified DEX. The 60 // order count can be limited by supplying a non-zero n value. In that case 61 // the newest n orders will be returned. The orders can be additionally 62 // filtered by supplying a non-zero since value, corresponding to a UNIX 63 // timestamp, in milliseconds. n = 0 applies no limit on number of orders 64 // returned. since = 0 is equivalent to disabling the time filter, since 65 // no orders were created before 1970. 66 AccountOrders(dex string, n int, since uint64) ([]*MetaOrder, error) 67 // Order fetches a MetaOrder by order ID. 68 Order(order.OrderID) (*MetaOrder, error) 69 // Orders fetches a slice of orders, sorted by descending time, and filtered 70 // with the provided OrderFilter. 71 Orders(*OrderFilter) ([]*MetaOrder, error) 72 // ActiveDEXOrders retrieves orders for a particular dex, specified by its 73 // URL. 74 ActiveDEXOrders(dex string) ([]*MetaOrder, error) 75 // MarketOrders retrieves all orders for the specified DEX and market. The 76 // order count can be limited by supplying a non-zero n value. In that case 77 // the newest n orders will be returned. The orders can be additionally 78 // filtered by supplying a non-zero since value, corresponding to a UNIX 79 // timestamp, in milliseconds. n = 0 applies no limit on number of orders 80 // returned. since = 0 is equivalent to disabling the time filter, since 81 // no orders were created before 1970. 82 MarketOrders(dex string, base, quote uint32, n int, since uint64) ([]*MetaOrder, error) 83 // UpdateOrderMetaData updates the order metadata, not including the Host. 84 UpdateOrderMetaData(order.OrderID, *OrderMetaData) error 85 // UpdateOrderStatus sets the order status for an order. 86 UpdateOrderStatus(oid order.OrderID, status order.OrderStatus) error 87 // LinkOrder sets the LinkedOrder field of the specified order's 88 // OrderMetaData. 89 LinkOrder(oid, linkedID order.OrderID) error 90 // UpdateMatch updates the match information in the database. Any existing 91 // entry for the match will be overwritten without indication. 92 UpdateMatch(m *MetaMatch) error 93 // ActiveMatches retrieves the matches that are in an active state, which is 94 // any state except order.MatchComplete. 95 ActiveMatches() ([]*MetaMatch, error) 96 // DEXOrdersWithActiveMatches retrieves order IDs for any order that has 97 // active matches, regardless of whether the order itself is in an active 98 // state. 99 DEXOrdersWithActiveMatches(dex string) ([]order.OrderID, error) 100 // MatchesForOrder gets the matches for the order ID. 101 MatchesForOrder(oid order.OrderID, excludeCancels bool) ([]*MetaMatch, error) 102 // Update wallets adds a wallet to the database, or updates the wallet 103 // credentials if the wallet already exists. A wallet is specified by the 104 // pair (asset ID, account name). 105 UpdateWallet(wallet *Wallet) error 106 // SetWalletPassword sets the encrypted password for the wallet. 107 SetWalletPassword(wid []byte, newPW []byte) error 108 // UpdateBalance updates a wallet's balance. 109 UpdateBalance(wid []byte, balance *Balance) error 110 // Wallets lists all saved wallets. 111 Wallets() ([]*Wallet, error) 112 // Wallet fetches the wallet for the specified asset by wallet ID. 113 Wallet(wid []byte) (*Wallet, error) 114 // UpdateWalletStatus updates a wallet's status. 115 UpdateWalletStatus(wid []byte, disable bool) error 116 // Backup makes a copy of the database to the default "backups" folder. 117 Backup() error 118 // BackupTo makes a backup of the database at the specified location, 119 // optionally overwriting any existing file and compacting the database. 120 BackupTo(dst string, overwrite, compact bool) error 121 // SaveNotification saves the notification. 122 SaveNotification(*Notification) error 123 // NotificationsN reads out the N most recent notifications. 124 NotificationsN(int) ([]*Notification, error) 125 // AckNotification sets the acknowledgement for a notification. 126 AckNotification(id []byte) error 127 // SavePokes saves a slice of notifications, overwriting any previously 128 // saved slice. 129 SavePokes([]*Notification) error 130 // LoadPokes loads the slice of notifications last saved with SavePokes. 131 // The loaded pokes are deleted from the database. 132 LoadPokes() ([]*Notification, error) 133 // DeleteInactiveOrders deletes inactive orders from the database that are 134 // older than the supplied time and returns the total number of orders 135 // deleted. If no time is supplied, the current time is used. Accepts an 136 // optional function to perform on deleted orders. 137 DeleteInactiveOrders(ctx context.Context, olderThan *time.Time, perOrderFn func(ord *MetaOrder) error) (int, error) 138 // DeleteInactiveMatches deletes inactive matches from the database that are 139 // older than the supplied time and return total number of matches deleted. 140 // If no time is supplied, the current time is used. Accepts an optional 141 // function to perform on deleted matches that includes if it was a sell 142 // order. 143 DeleteInactiveMatches(ctx context.Context, olderThan *time.Time, perMatchFn func(match *MetaMatch, isSell bool) error) (int, error) 144 // SetSeedGenerationTime stores the time when the app seed was generated. 145 SetSeedGenerationTime(time uint64) error 146 // SeedGenerationTime fetches the time when the app seed was generated. 147 SeedGenerationTime() (uint64, error) 148 // DisabledRateSources retrieves disabled fiat rate sources from the 149 // database. 150 DisabledRateSources() ([]string, error) 151 // SaveDisabledRateSources saves disabled fiat rate sources in the database. 152 // A source name must not contain a comma. 153 SaveDisabledRateSources(disabledSources []string) error 154 // SetLanguage stores the user's chosen language. 155 SetLanguage(lang string) error 156 // Language gets the language stored with SetLanguage. 157 Language() (string, error) 158 }