diff --git a/accounts.go b/accounts.go index 30a3df76..a65d6c56 100644 --- a/accounts.go +++ b/accounts.go @@ -9,6 +9,8 @@ import ( "github.com/decred/dcrwallet/errors/v2" ) +// GetAccounts returns a json array of all +// accounts information in a wallet. func (wallet *Wallet) GetAccounts() (string, error) { accountsResponse, err := wallet.GetAccountsRaw() if err != nil { @@ -19,6 +21,7 @@ func (wallet *Wallet) GetAccounts() (string, error) { return string(result), nil } +// GetAccountsRaw returns an Accounts pointer containing all accounts information in a wallet. func (wallet *Wallet) GetAccountsRaw() (*Accounts, error) { resp, err := wallet.internal.Accounts(wallet.shutdownContext()) if err != nil { @@ -51,6 +54,8 @@ func (wallet *Wallet) GetAccountsRaw() (*Accounts, error) { }, nil } +// AccountsIterator returns an iterator that can be +// used to loop through the accounts of a wallet. func (wallet *Wallet) AccountsIterator() (*AccountsIterator, error) { accounts, err := wallet.GetAccountsRaw() if err != nil { @@ -63,6 +68,8 @@ func (wallet *Wallet) AccountsIterator() (*AccountsIterator, error) { }, nil } +// Next returns the account on the current iterator +// index and increments the current index. func (accountsInterator *AccountsIterator) Next() *Account { if accountsInterator.currentIndex < len(accountsInterator.accounts) { account := accountsInterator.accounts[accountsInterator.currentIndex] @@ -73,10 +80,13 @@ func (accountsInterator *AccountsIterator) Next() *Account { return nil } +// Reset sets the current iterator's index to 0. func (accountsInterator *AccountsIterator) Reset() { accountsInterator.currentIndex = 0 } +// GetAccount fetches an account and all the accompanying +// information and properties of the said account. func (wallet *Wallet) GetAccount(accountNumber int32) (*Account, error) { props, err := wallet.internal.AccountProperties(wallet.shutdownContext(), uint32(accountNumber)) if err != nil { @@ -102,6 +112,8 @@ func (wallet *Wallet) GetAccount(accountNumber int32) (*Account, error) { return account, nil } +// GetAccountBalance returns all the balance +// information in a given account. func (wallet *Wallet) GetAccountBalance(accountNumber int32) (*Balance, error) { balance, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(accountNumber), wallet.RequiredConfirmations()) if err != nil { @@ -119,6 +131,8 @@ func (wallet *Wallet) GetAccountBalance(accountNumber int32) (*Balance, error) { }, nil } +// SpendableForAccount returns the spendable +// balance in a given account. func (wallet *Wallet) SpendableForAccount(account int32) (int64, error) { bals, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(account), wallet.RequiredConfirmations()) if err != nil { @@ -128,6 +142,8 @@ func (wallet *Wallet) SpendableForAccount(account int32) (int64, error) { return int64(bals.Spendable), nil } +// NextAccount creates the account and returns the +// account number. func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, error) { lock := make(chan time.Time, 1) defer func() { @@ -149,6 +165,7 @@ func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, e return int32(accountNumber), err } +// RenameAccount sets the name for an account number to newName. func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error { err := wallet.internal.RenameAccount(wallet.shutdownContext(), uint32(accountNumber), newName) if err != nil { @@ -158,6 +175,7 @@ func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error { return nil } +// AccountName returns the name for the passed account number. func (wallet *Wallet) AccountName(accountNumber int32) string { name, err := wallet.AccountNameRaw(uint32(accountNumber)) if err != nil { @@ -167,14 +185,18 @@ func (wallet *Wallet) AccountName(accountNumber int32) string { return name } +// AccountNameRaw returns the name for the passed account number. func (wallet *Wallet) AccountNameRaw(accountNumber uint32) (string, error) { return wallet.internal.AccountName(wallet.shutdownContext(), accountNumber) } +// AccountNumber returns an account number for the passed account. func (wallet *Wallet) AccountNumber(accountName string) (uint32, error) { return wallet.internal.AccountNumber(wallet.shutdownContext(), accountName) } +// HDPathForAccount returns the HD path for the passed account based +// on the coin-type and the net type of the wallet. func (wallet *Wallet) HDPathForAccount(accountNumber int32) (string, error) { cointype, err := wallet.internal.CoinType(wallet.shutdownContext()) if err != nil { diff --git a/address.go b/address.go index f6c69192..96e6fae8 100644 --- a/address.go +++ b/address.go @@ -11,7 +11,9 @@ import ( ) // AddressInfo holds information about an address -// If the address belongs to the querying wallet, IsMine will be true and the AccountNumber and AccountName values will be populated +// If the address belongs to the querying wallet, +// IsMine will be true and the AccountNumber and +// AccountName values will be populated. type AddressInfo struct { Address string IsMine bool @@ -19,11 +21,14 @@ type AddressInfo struct { AccountName string } +// IsAddressValid decodes an address string and checks if +// it is valid for the current net type. func (wallet *Wallet) IsAddressValid(address string) bool { _, err := dcrutil.DecodeAddress(address, wallet.chainParams) return err == nil } +// HaveAddress returns whether wallet is the owner of the address. func (wallet *Wallet) HaveAddress(address string) bool { addr, err := dcrutil.DecodeAddress(address, wallet.chainParams) if err != nil { @@ -38,6 +43,7 @@ func (wallet *Wallet) HaveAddress(address string) bool { return have } +// AccountOfAddress returns the account name of the passed wallet address. func (wallet *Wallet) AccountOfAddress(address string) string { addr, err := dcrutil.DecodeAddress(address, wallet.chainParams) if err != nil { @@ -48,6 +54,8 @@ func (wallet *Wallet) AccountOfAddress(address string) string { return wallet.AccountName(int32(info.Account())) } +// AddressInfo returns information for an address such as +// the address, account number and name of the account. func (wallet *Wallet) AddressInfo(address string) (*AddressInfo, error) { addr, err := dcrutil.DecodeAddress(address, wallet.chainParams) if err != nil { @@ -69,6 +77,7 @@ func (wallet *Wallet) AddressInfo(address string) (*AddressInfo, error) { return addressInfo, nil } +// CurrentAddress returns the next unused address of an account. func (wallet *Wallet) CurrentAddress(account int32) (string, error) { if wallet.IsRestored && !wallet.HasDiscoveredAccounts { return "", errors.E(ErrAddressDiscoveryNotDone) @@ -82,6 +91,8 @@ func (wallet *Wallet) CurrentAddress(account int32) (string, error) { return addr.Address(), nil } +// NextAddress returns a new external address +// for the passed account. func (wallet *Wallet) NextAddress(account int32) (string, error) { if wallet.IsRestored && !wallet.HasDiscoveredAccounts { return "", errors.E(ErrAddressDiscoveryNotDone) @@ -95,6 +106,7 @@ func (wallet *Wallet) NextAddress(account int32) (string, error) { return addr.Address(), nil } +// AddressPubKey returns the public key of the passed address. func (wallet *Wallet) AddressPubKey(address string) (string, error) { addr, err := dcrutil.DecodeAddress(address, wallet.chainParams) if err != nil { diff --git a/addresshelper/helper.go b/addresshelper/helper.go index cd401e4a..ce30e023 100644 --- a/addresshelper/helper.go +++ b/addresshelper/helper.go @@ -19,6 +19,8 @@ func PkScript(address string, net dcrutil.AddressParams) ([]byte, error) { return txscript.PayToAddrScript(addr) } +// PkScriptAddresses extracts and returns the addresses from +// the passed script. func PkScriptAddresses(params *chaincfg.Params, pkScript []byte) ([]string, error) { _, addresses, _, err := txscript.ExtractPkScriptAddrs(scriptVersion, pkScript, params) if err != nil { diff --git a/badgerdb/db.go b/badgerdb/db.go index f3a9ea14..887f4e39 100644 --- a/badgerdb/db.go +++ b/badgerdb/db.go @@ -45,6 +45,8 @@ type transaction struct { writable bool } +// ReadBucket returns a structure within the +// database allowed to perform read operations. func (tx *transaction) ReadBucket(key []byte) walletdb.ReadBucket { if tx.db.closed { return nil @@ -52,6 +54,8 @@ func (tx *transaction) ReadBucket(key []byte) walletdb.ReadBucket { return tx.ReadWriteBucket(key) } +// ReadWriteBucket returns a structure within the database +// allowed to perform read and write operations. func (tx *transaction) ReadWriteBucket(key []byte) walletdb.ReadWriteBucket { if tx.db.closed { return nil @@ -69,6 +73,8 @@ func (tx *transaction) ReadWriteBucket(key []byte) walletdb.ReadWriteBucket { return readWriteBucket } +// CreateTopLevelBucket creates a new bucket with +// ability to perform read and write operations. func (tx *transaction) CreateTopLevelBucket(key []byte) (walletdb.ReadWriteBucket, error) { if tx.db.closed { return nil, errors.E(errors.Invalid) @@ -82,6 +88,8 @@ func (tx *transaction) CreateTopLevelBucket(key []byte) (walletdb.ReadWriteBucke return bucket, nil } +// DeleteTopLevelBucket removes a bucket (structure within +// database that allows for read or write operations). func (tx *transaction) DeleteTopLevelBucket(key []byte) error { if tx.db.closed { return errors.E(errors.Invalid) @@ -186,6 +194,7 @@ func (b *Bucket) NestedReadWriteBucket(key []byte) walletdb.ReadWriteBucket { return nestedBucket } +// NestedReadBucket returns a read and write bucket interface implementation. func (b *Bucket) NestedReadBucket(key []byte) walletdb.ReadBucket { if b.dbTransaction.db.closed { return nil @@ -293,6 +302,8 @@ func (b *Bucket) Delete(key []byte) error { return convertErr(b.delete(key)) } +// ReadCursor returns a bucket cursor that can be +// positioned at the start and end of the bucket. func (b *Bucket) ReadCursor() walletdb.ReadCursor { if b.dbTransaction.db.closed { return nil @@ -589,10 +600,14 @@ func (db *db) beginTx(writable bool) (*transaction, error) { return tran, nil } +// BeginReadTx returns a database transaction +// that can be used for reads. func (db *db) BeginReadTx() (walletdb.ReadTx, error) { return db.beginTx(false) } +// BeginReadWriteTx returns a database transactions +// that can be used for reads and writes. func (db *db) BeginReadWriteTx() (walletdb.ReadWriteTx, error) { return db.beginTx(true) } diff --git a/message.go b/message.go index 965afdf4..2937ee3c 100644 --- a/message.go +++ b/message.go @@ -9,6 +9,8 @@ import ( w "github.com/decred/dcrwallet/wallet/v3" ) +// SignMessage returns the signature of a signed message +// using an address associated private key. func (wallet *Wallet) SignMessage(passphrase []byte, address string, message string) ([]byte, error) { lock := make(chan time.Time, 1) defer func() { @@ -45,6 +47,7 @@ func (wallet *Wallet) SignMessage(passphrase []byte, address string, message str return sig, nil } +// VerifyMessage verifies that signatureBase64 is a valid signature. func (wallet *Wallet) VerifyMessage(address string, message string, signatureBase64 string) (bool, error) { var valid bool diff --git a/multiwallet.go b/multiwallet.go index 3a57260f..6ce1c6bb 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -114,6 +114,8 @@ func NewMultiWallet(rootDir, dbDriver, netType string) (*MultiWallet, error) { return mw, nil } +// Shutdown closes all opened wallets and database +// in MultiWallet instance. func (mw *MultiWallet) Shutdown() { log.Info("Shutting down dcrlibwallet") @@ -141,10 +143,14 @@ func (mw *MultiWallet) Shutdown() { } } +// SetStartupPassPhrase sets the passphrase of a wallet +// other than the default startup passphrase. func (mw *MultiWallet) SetStartupPassphrase(passphrase []byte, passphraseType int32) error { return mw.ChangeStartupPassphrase([]byte(""), passphrase, passphraseType) } +// VerifyStartupPassphrase checks is startupPassphrase is +// the correct startup passphrase. func (mw *MultiWallet) VerifyStartupPassphrase(startupPassphrase []byte) error { var startupPassphraseHash []byte err := mw.db.Get(walletsMetadataBucketName, walletstartupPassphraseField, &startupPassphraseHash) @@ -169,6 +175,7 @@ func (mw *MultiWallet) VerifyStartupPassphrase(startupPassphrase []byte) error { return nil } +// ChangeStartupPassPhrase changes the startup passphrase. func (mw *MultiWallet) ChangeStartupPassphrase(oldPassphrase, newPassphrase []byte, passphraseType int32) error { if len(newPassphrase) == 0 { return mw.RemoveStartupPassphrase(oldPassphrase) @@ -195,6 +202,8 @@ func (mw *MultiWallet) ChangeStartupPassphrase(oldPassphrase, newPassphrase []by return nil } +// RemoveStartupPassphrase removes the startup security +// if oldPassphrase is valid. func (mw *MultiWallet) RemoveStartupPassphrase(oldPassphrase []byte) error { err := mw.VerifyStartupPassphrase(oldPassphrase) if err != nil { @@ -212,14 +221,18 @@ func (mw *MultiWallet) RemoveStartupPassphrase(oldPassphrase []byte) error { return nil } +// IsStartupSecuritySet returns true if startup security is set. func (mw *MultiWallet) IsStartupSecuritySet() bool { return mw.ReadBoolConfigValueForKey(IsStartupSecuritySetConfigKey, false) } +// StartupSecurityType returns the PassPhraseType used +// for the startup security. func (mw *MultiWallet) StartupSecurityType() int32 { return mw.ReadInt32ConfigValueForKey(StartupSecurityTypeConfigKey, PassphraseTypePass) } +// OpenWallets opens all loaded wallets. func (mw *MultiWallet) OpenWallets(startupPassphrase []byte) error { if mw.IsSyncing() { return errors.New(ErrSyncAlreadyInProgress) @@ -242,6 +255,8 @@ func (mw *MultiWallet) OpenWallets(startupPassphrase []byte) error { return nil } +// CreateWatchOnlyWallet generates a wallet seed and creates a +// new wallet using the provided private passphrase. func (mw *MultiWallet) CreateWatchOnlyWallet(walletName, extendedPublicKey string) (*Wallet, error) { wallet := &Wallet{ Name: walletName, @@ -258,6 +273,8 @@ func (mw *MultiWallet) CreateWatchOnlyWallet(walletName, extendedPublicKey strin }) } +// CreateNewWallet generates a wallet seed and creates a new +// wallet using the provided private PassPhrase. func (mw *MultiWallet) CreateNewWallet(privatePassphrase string, privatePassphraseType int32) (*Wallet, error) { seed, err := GenerateSeed() if err != nil { @@ -280,6 +297,8 @@ func (mw *MultiWallet) CreateNewWallet(privatePassphrase string, privatePassphra }) } +// RestoreWallet uses a wallet seed and private passphrase +// to restore an existing wallet. func (mw *MultiWallet) RestoreWallet(seedMnemonic, privatePassphrase string, privatePassphraseType int32) (*Wallet, error) { wallet := &Wallet{ PrivatePassphraseType: privatePassphraseType, @@ -297,6 +316,11 @@ func (mw *MultiWallet) RestoreWallet(seedMnemonic, privatePassphrase string, pri }) } +// LinkExistingWallet links an already existing wallet +// to the multi-wallet database. +// +// This is used as backward compatibility for wallets +// created before multi-wallet. func (mw *MultiWallet) LinkExistingWallet(walletDataDir, originalPubPass string, privatePassphraseType int32) (*Wallet, error) { // check if `walletDataDir` contains wallet.db if !WalletExistsAt(walletDataDir) { @@ -422,6 +446,7 @@ func (mw *MultiWallet) saveNewWallet(wallet *Wallet, setupWallet func() error) ( return wallet, nil } +// RenameWallet sets the name for a wallet to newName. func (mw *MultiWallet) RenameWallet(walletID int, newName string) error { if strings.HasPrefix(newName, "wallet-") { return errors.E(ErrReservedWalletName) @@ -442,6 +467,8 @@ func (mw *MultiWallet) RenameWallet(walletID int, newName string) error { return mw.db.Save(wallet) // update WalletName field } +// DeleteWallet deletes a wallet data files and it's information +// from multi-wallet database. func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { wallet := mw.WalletWithID(walletID) @@ -473,6 +500,7 @@ func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { return nil } +// WalletWithID returns the wallet that owns the passed ID. func (mw *MultiWallet) WalletWithID(walletID int) *Wallet { if wallet, ok := mw.wallets[walletID]; ok { return wallet @@ -480,6 +508,8 @@ func (mw *MultiWallet) WalletWithID(walletID int) *Wallet { return nil } +// VerifySeedForWallet checks if seedMnemonic is valid for the walletID +// and deletes the wallet seed from multi-wallet database. func (mw *MultiWallet) VerifySeedForWallet(walletID int, seedMnemonic string) error { wallet := mw.WalletWithID(walletID) if wallet == nil { @@ -494,6 +524,8 @@ func (mw *MultiWallet) VerifySeedForWallet(walletID int, seedMnemonic string) er return errors.New(ErrInvalid) } +// NumWalletsNeedingSeedBackup returns the number of +// wallets that requires seed backup. func (mw *MultiWallet) NumWalletsNeedingSeedBackup() int32 { var backupsNeeded int32 for _, wallet := range mw.wallets { @@ -505,10 +537,12 @@ func (mw *MultiWallet) NumWalletsNeedingSeedBackup() int32 { return backupsNeeded } +// LoadedWalletsCount returns the number of loaded wallets. func (mw *MultiWallet) LoadedWalletsCount() int32 { return int32(len(mw.wallets)) } +// OpenedWalletIDsRaw returns a walletID array of opened wallets. func (mw *MultiWallet) OpenedWalletIDsRaw() []int { walletIDs := make([]int, 0) for _, wallet := range mw.wallets { @@ -519,16 +553,19 @@ func (mw *MultiWallet) OpenedWalletIDsRaw() []int { return walletIDs } +// OpenedWalletIDs returns a json array of opened walletIDs. func (mw *MultiWallet) OpenedWalletIDs() string { walletIDs := mw.OpenedWalletIDsRaw() jsonEncoded, _ := json.Marshal(&walletIDs) return string(jsonEncoded) } +// OpenedWalletsCount returns the number of opened wallets. func (mw *MultiWallet) OpenedWalletsCount() int32 { return int32(len(mw.OpenedWalletIDsRaw())) } +// SyncedWalletsCount returns the number of synced wallets. func (mw *MultiWallet) SyncedWalletsCount() int32 { var syncedWallets int32 for _, wallet := range mw.wallets { @@ -540,6 +577,7 @@ func (mw *MultiWallet) SyncedWalletsCount() int32 { return syncedWallets } +// WalletNameExists checks if a wallet name is valid amd unique. func (mw *MultiWallet) WalletNameExists(walletName string) (bool, error) { if strings.HasPrefix(walletName, "wallet-") { return false, errors.E(ErrReservedWalletName) @@ -555,6 +593,7 @@ func (mw *MultiWallet) WalletNameExists(walletName string) (bool, error) { return false, nil } +// UnlockWallet unlocks a wallet using the private pass. func (mw *MultiWallet) UnlockWallet(walletID int, privPass []byte) error { wallet := mw.WalletWithID(walletID) if wallet == nil { @@ -564,6 +603,8 @@ func (mw *MultiWallet) UnlockWallet(walletID int, privPass []byte) error { return wallet.UnlockWallet(privPass) } +// ChangePrivatePassphraseForWallet changes the passPhrase +// for a wallet from old to new. func (mw *MultiWallet) ChangePrivatePassphraseForWallet(walletID int, oldPrivatePassphrase, newPrivatePassphrase []byte, privatePassphraseType int32) error { if privatePassphraseType != PassphraseTypePin && privatePassphraseType != PassphraseTypePass { return errors.New(ErrInvalid) diff --git a/multiwallet_config.go b/multiwallet_config.go index 51837bd6..a09f1e60 100644 --- a/multiwallet_config.go +++ b/multiwallet_config.go @@ -51,6 +51,7 @@ func (mw *MultiWallet) walletConfigReadFn(walletID int) configReadFn { } } +// SaveUserConfigValue saves config value for key func (mw *MultiWallet) SaveUserConfigValue(key string, value interface{}) { err := mw.db.Set(userConfigBucketName, key, value) if err != nil { @@ -58,6 +59,7 @@ func (mw *MultiWallet) SaveUserConfigValue(key string, value interface{}) { } } +// ReadUserConfigValue retrieves the raw value for config key. func (mw *MultiWallet) ReadUserConfigValue(key string, valueOut interface{}) error { err := mw.db.Get(userConfigBucketName, key, valueOut) if err != nil && err != storm.ErrNotFound { @@ -66,6 +68,7 @@ func (mw *MultiWallet) ReadUserConfigValue(key string, valueOut interface{}) err return err } +// DeleteUserConfigValueForKey deletes a key from the bucket. func (mw *MultiWallet) DeleteUserConfigValueForKey(key string) { err := mw.db.Delete(userConfigBucketName, key) if err != nil { @@ -73,6 +76,7 @@ func (mw *MultiWallet) DeleteUserConfigValueForKey(key string) { } } +// ClearConfig clears all saved config. func (mw *MultiWallet) ClearConfig() { err := mw.db.Drop(userConfigBucketName) if err != nil { @@ -80,30 +84,37 @@ func (mw *MultiWallet) ClearConfig() { } } +// SetBoolConfigValueForKey sets bool config value for key. func (mw *MultiWallet) SetBoolConfigValueForKey(key string, value bool) { mw.SaveUserConfigValue(key, value) } +// SetDoubleConfigValueForKey sets float64 config value for key. func (mw *MultiWallet) SetDoubleConfigValueForKey(key string, value float64) { mw.SaveUserConfigValue(key, value) } +// SetIntConfigValueForKey sets an int config value for key. func (mw *MultiWallet) SetIntConfigValueForKey(key string, value int) { mw.SaveUserConfigValue(key, value) } +// SetInt32ConfigValueForKey sets an int32 config value for key. func (mw *MultiWallet) SetInt32ConfigValueForKey(key string, value int32) { mw.SaveUserConfigValue(key, value) } +// SetLongConfigValueForKey sets an int64 config value for key. func (mw *MultiWallet) SetLongConfigValueForKey(key string, value int64) { mw.SaveUserConfigValue(key, value) } +// SetStringConfigValueForKey sets a string config value for key. func (mw *MultiWallet) SetStringConfigValueForKey(key, value string) { mw.SaveUserConfigValue(key, value) } +// ReadBoolConfigValueForKey reads the bool config value for key. func (mw *MultiWallet) ReadBoolConfigValueForKey(key string, defaultValue bool) (valueOut bool) { if err := mw.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -111,6 +122,7 @@ func (mw *MultiWallet) ReadBoolConfigValueForKey(key string, defaultValue bool) return } +// ReadDoubleConfigValueForKey reads the float64 config value for key. func (mw *MultiWallet) ReadDoubleConfigValueForKey(key string, defaultValue float64) (valueOut float64) { if err := mw.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -118,6 +130,7 @@ func (mw *MultiWallet) ReadDoubleConfigValueForKey(key string, defaultValue floa return } +// ReadIntConfigValueForKey reads the int config value for key. func (mw *MultiWallet) ReadIntConfigValueForKey(key string, defaultValue int) (valueOut int) { if err := mw.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -125,6 +138,7 @@ func (mw *MultiWallet) ReadIntConfigValueForKey(key string, defaultValue int) (v return } +// ReadInt32ConfigValueForKey reads the int32 config value for key. func (mw *MultiWallet) ReadInt32ConfigValueForKey(key string, defaultValue int32) (valueOut int32) { if err := mw.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -132,6 +146,7 @@ func (mw *MultiWallet) ReadInt32ConfigValueForKey(key string, defaultValue int32 return } +// ReadLongConfigValueForKey reads the int64 config value for key. func (mw *MultiWallet) ReadLongConfigValueForKey(key string, defaultValue int64) (valueOut int64) { if err := mw.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -139,6 +154,7 @@ func (mw *MultiWallet) ReadLongConfigValueForKey(key string, defaultValue int64) return } +// ReadStringConfigValueForKey reads the string config value for key. func (mw *MultiWallet) ReadStringConfigValueForKey(key string) (valueOut string) { mw.ReadUserConfigValue(key, &valueOut) return diff --git a/rescan.go b/rescan.go index 84bfa526..bf2a21c9 100644 --- a/rescan.go +++ b/rescan.go @@ -9,6 +9,8 @@ import ( w "github.com/decred/dcrwallet/wallet/v3" ) +// RescanBlocks rescans for relevant transactions in +// all blocks in the main chain. func (mw *MultiWallet) RescanBlocks(walletID int) error { wallet := mw.WalletWithID(walletID) @@ -107,6 +109,7 @@ func (mw *MultiWallet) RescanBlocks(walletID int) error { return nil } +// CancelRescan cancels an ongoing scans. func (mw *MultiWallet) CancelRescan() { mw.syncData.mu.Lock() defer mw.syncData.mu.Unlock() @@ -118,12 +121,15 @@ func (mw *MultiWallet) CancelRescan() { } } +// IsRescanning returns true if a wallet is rescanning blocks. func (mw *MultiWallet) IsRescanning() bool { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() return mw.syncData.rescanning } +// SetBlocksRescanProgressListener sets a listener to +// receive block rescan progress. func (mw *MultiWallet) SetBlocksRescanProgressListener(blocksRescanProgressListener BlocksRescanProgressListener) { mw.blocksRescanProgressListener = blocksRescanProgressListener } diff --git a/sync.go b/sync.go index 6bd567d8..f7d04478 100644 --- a/sync.go +++ b/sync.go @@ -90,6 +90,8 @@ func (mw *MultiWallet) initActiveSyncData() { mw.syncData.mu.Unlock() } +// IsSyncProgressListenerRegisteredFor returns true if a sync +// progress listener is registered for uniqueIdentifier. func (mw *MultiWallet) IsSyncProgressListenerRegisteredFor(uniqueIdentifier string) bool { mw.syncData.mu.RLock() _, exists := mw.syncData.syncProgressListeners[uniqueIdentifier] @@ -97,6 +99,8 @@ func (mw *MultiWallet) IsSyncProgressListenerRegisteredFor(uniqueIdentifier stri return exists } +// AddSyncProgressListener checks and sets a new progress listener if there is +// no existing progress listener for wallet syncing. func (mw *MultiWallet) AddSyncProgressListener(syncProgressListener SyncProgressListener, uniqueIdentifier string) error { if mw.IsSyncProgressListenerRegisteredFor(uniqueIdentifier) { return errors.New(ErrListenerAlreadyExist) @@ -110,6 +114,7 @@ func (mw *MultiWallet) AddSyncProgressListener(syncProgressListener SyncProgress return mw.PublishLastSyncProgress(uniqueIdentifier) } +// RemoveSyncProgressListener deletes an existing sync progress listener. func (mw *MultiWallet) RemoveSyncProgressListener(uniqueIdentifier string) { mw.syncData.mu.Lock() delete(mw.syncData.syncProgressListeners, uniqueIdentifier) @@ -128,6 +133,8 @@ func (mw *MultiWallet) syncProgressListeners() []SyncProgressListener { return listeners } +// PublishLastSyncProgress broadcasts last sync progress +// to registered sync progress listeners. func (mw *MultiWallet) PublishLastSyncProgress(uniqueIdentifier string) error { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -151,12 +158,14 @@ func (mw *MultiWallet) PublishLastSyncProgress(uniqueIdentifier string) error { return nil } +// EnableSyncLogs enables logging of sync logs. func (mw *MultiWallet) EnableSyncLogs() { mw.syncData.mu.Lock() mw.syncData.showLogs = true mw.syncData.mu.Unlock() } +// SyncInactiveForPeriod accounts for inactive sync period. func (mw *MultiWallet) SyncInactiveForPeriod(totalInactiveSeconds int64) { mw.syncData.mu.Lock() defer mw.syncData.mu.Unlock() @@ -173,6 +182,7 @@ func (mw *MultiWallet) SyncInactiveForPeriod(totalInactiveSeconds int64) { } } +// SpvSync starts syncing a wallet using SPV peer to peer connections. func (mw *MultiWallet) SpvSync() error { // prevent an attempt to sync when the previous syncing has not been canceled if mw.IsSyncing() || mw.IsSynced() { @@ -258,6 +268,7 @@ func (mw *MultiWallet) SpvSync() error { return nil } +// RestartSpvSync restarts ongoing SpvSync. func (mw *MultiWallet) RestartSpvSync() error { mw.syncData.mu.Lock() mw.syncData.restartSyncRequested = true @@ -267,6 +278,7 @@ func (mw *MultiWallet) RestartSpvSync() error { return mw.SpvSync() } +// CancelSync stops any active wallet syncing. func (mw *MultiWallet) CancelSync() { mw.syncData.mu.RLock() cancelSync := mw.syncData.cancelSync @@ -297,18 +309,24 @@ func (mw *MultiWallet) CancelSync() { } } +// IsWaiting returns true if a wallet has not received +// headers in a multi-wallet sync. func (wallet *Wallet) IsWaiting() bool { return wallet.waiting } +// IsSynced returns true if a wallet is synced. func (wallet *Wallet) IsSynced() bool { return wallet.synced } +// IsSyncing returns true if a wallet is syncing. func (wallet *Wallet) IsSyncing() bool { return wallet.syncing } +// IsConnectedToDecredNetwork returns true is a wallet is +// connected to the decred network. func (mw *MultiWallet) IsConnectedToDecredNetwork() bool { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -321,12 +339,14 @@ func (mw *MultiWallet) IsSynced() bool { return mw.syncData.synced } +// IsSyncing returns true if the wallets are syncing. func (mw *MultiWallet) IsSyncing() bool { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() return mw.syncData.syncing } +// CurrentSyncStage returns the sync stage of the wallets. func (mw *MultiWallet) CurrentSyncStage() int32 { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -337,6 +357,7 @@ func (mw *MultiWallet) CurrentSyncStage() int32 { return InvalidSyncStage } +// GeneralSyncProgress returns the general sync progress. func (mw *MultiWallet) GeneralSyncProgress() *GeneralSyncProgress { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -355,12 +376,14 @@ func (mw *MultiWallet) GeneralSyncProgress() *GeneralSyncProgress { return nil } +// ConnectedPeers returns the number of connected peers via spv. func (mw *MultiWallet) ConnectedPeers() int32 { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() return mw.syncData.connectedPeers } +// GetBestBlock retrieves highest block height from the loaded wallets. func (mw *MultiWallet) GetBestBlock() *BlockInfo { var bestBlock int32 = -1 var blockInfo *BlockInfo @@ -379,6 +402,7 @@ func (mw *MultiWallet) GetBestBlock() *BlockInfo { return blockInfo } +// GetLowestBlock retrieves the lowest block height from the loaded wallets. func (mw *MultiWallet) GetLowestBlock() *BlockInfo { var lowestBlock int32 = -1 var blockInfo *BlockInfo @@ -396,6 +420,7 @@ func (mw *MultiWallet) GetLowestBlock() *BlockInfo { return blockInfo } +// GetBestBlock retrieves the best block height that the wallet is synced to. func (wallet *Wallet) GetBestBlock() int32 { if wallet.internal == nil { // This method is sometimes called after a wallet is deleted and causes crash. @@ -407,6 +432,7 @@ func (wallet *Wallet) GetBestBlock() int32 { return height } +// GetBestBlockTimeStamp retrieves the timestamp of the wallet's best block. func (wallet *Wallet) GetBestBlockTimeStamp() int64 { if wallet.internal == nil { // This method is sometimes called after a wallet is deleted and causes crash. @@ -425,6 +451,8 @@ func (wallet *Wallet) GetBestBlockTimeStamp() int64 { return info.Timestamp } +// GetLowestBlockTimestamp gets the block timestamp from the +// wallet with the lowest block height. func (mw *MultiWallet) GetLowestBlockTimestamp() int64 { var timestamp int64 = -1 for _, wallet := range mw.wallets { diff --git a/ticket.go b/ticket.go index 2775bf50..a97e7f19 100644 --- a/ticket.go +++ b/ticket.go @@ -36,6 +36,8 @@ func (wallet *Wallet) StakeInfo() (*w.StakeInfoData, error) { return wallet.internal.StakeInfo(ctx) } +// GetTickets returns an array of tickets found in the specified +// block hash range. func (wallet *Wallet) GetTickets(startingBlockHash, endingBlockHash []byte, targetCount int32) ([]*TicketInfo, error) { return wallet.getTickets(&GetTicketsRequest{ StartingBlockHash: startingBlockHash, @@ -44,6 +46,8 @@ func (wallet *Wallet) GetTickets(startingBlockHash, endingBlockHash []byte, targ }) } +// GetTicketsForBlockHeightRange returns an array of tickets found +// in the specified block hash range. func (wallet *Wallet) GetTicketsForBlockHeightRange(startHeight, endHeight, targetCount int32) ([]*TicketInfo, error) { return wallet.getTickets(&GetTicketsRequest{ StartingBlockHeight: startHeight, @@ -176,7 +180,8 @@ func (wallet *Wallet) TicketPrice(ctx context.Context) (*TicketPriceResponse, er }, nil } -// PurchaseTickets purchases tickets from the wallet. Returns a slice of hashes for tickets purchased +// PurchaseTickets purchases tickets for the wallet. Returns a slice +// of hashes for tickets purchased. func (wallet *Wallet) PurchaseTickets(ctx context.Context, request *PurchaseTicketsRequest, vspHost string) ([]string, error) { var err error diff --git a/transactions.go b/transactions.go index 9e33745c..4821d347 100644 --- a/transactions.go +++ b/transactions.go @@ -32,6 +32,8 @@ const ( TxTypeRevocation = txhelper.TxTypeRevocation ) +// GetTransaction returns the JSON encoded string of +// transaction details. func (wallet *Wallet) GetTransaction(txHash []byte) (string, error) { transaction, err := wallet.GetTransactionRaw(txHash) if err != nil { @@ -47,6 +49,7 @@ func (wallet *Wallet) GetTransaction(txHash []byte) (string, error) { return string(result), nil } +// GetTransactionRaw returns transaction details of a wallet belonging to txHash. func (wallet *Wallet) GetTransactionRaw(txHash []byte) (*Transaction, error) { hash, err := chainhash.NewHash(txHash) if err != nil { @@ -63,6 +66,8 @@ func (wallet *Wallet) GetTransactionRaw(txHash []byte) (*Transaction, error) { return wallet.decodeTransactionWithTxSummary(txSummary, blockHash) } +// GetTransactions returns the JSON encoding of all transactions +// found in the wallet matching the passed parameters. func (wallet *Wallet) GetTransactions(offset, limit, txFilter int32, newestFirst bool) (string, error) { transactions, err := wallet.GetTransactionsRaw(offset, limit, txFilter, newestFirst) if err != nil { @@ -77,11 +82,15 @@ func (wallet *Wallet) GetTransactions(offset, limit, txFilter int32, newestFirst return string(jsonEncodedTransactions), nil } +// GetTransactionsRaw returns an array of all transactions +// found in the wallet matching the passed parameters. func (wallet *Wallet) GetTransactionsRaw(offset, limit, txFilter int32, newestFirst bool) (transactions []Transaction, err error) { err = wallet.txDB.Read(offset, limit, txFilter, newestFirst, &transactions) return } +// GetTransactions returns the JSON encoding of all transactions +// matching the passed parameters found in the wallets. func (mw *MultiWallet) GetTransactions(offset, limit, txFilter int32, newestFirst bool) (string, error) { transactions := make([]Transaction, 0) for _, wallet := range mw.wallets { @@ -113,6 +122,8 @@ func (mw *MultiWallet) GetTransactions(offset, limit, txFilter int32, newestFirs return string(jsonEncodedTransactions), nil } +// CountTransactions returns number of transactions matching +// the txFilter. func (wallet *Wallet) CountTransactions(txFilter int32) (int, error) { return wallet.txDB.Count(txFilter, &Transaction{}) } diff --git a/txandblocknotifications.go b/txandblocknotifications.go index 173b9f74..ff7f842f 100644 --- a/txandblocknotifications.go +++ b/txandblocknotifications.go @@ -61,6 +61,8 @@ func (mw *MultiWallet) listenForTransactions(walletID int) { } } +// AddTxAndBlockNotificationListener adds a notification listener +// for new transactions and blocks received. func (mw *MultiWallet) AddTxAndBlockNotificationListener(txAndBlockNotificationListener TxAndBlockNotificationListener, uniqueIdentifier string) error { mw.notificationListenersMu.Lock() defer mw.notificationListenersMu.Unlock() @@ -75,6 +77,8 @@ func (mw *MultiWallet) AddTxAndBlockNotificationListener(txAndBlockNotificationL return nil } +// RemoveTxAndBlockNotificationListener deletes existing +// TxAndBlockNotificationListener matching uniqueIdentifier. func (mw *MultiWallet) RemoveTxAndBlockNotificationListener(uniqueIdentifier string) { mw.notificationListenersMu.Lock() defer mw.notificationListenersMu.Unlock() diff --git a/txauthor.go b/txauthor.go index 6fb6ca6f..097d5c27 100644 --- a/txauthor.go +++ b/txauthor.go @@ -23,6 +23,7 @@ type TxAuthor struct { changeAddress string } +// NewUnsignedTx returns a TxAuthor instance to construct a transaction. func (mw *MultiWallet) NewUnsignedTx(sourceWallet *Wallet, sourceAccountNumber int32) *TxAuthor { return &TxAuthor{ sourceWallet: sourceWallet, @@ -31,6 +32,8 @@ func (mw *MultiWallet) NewUnsignedTx(sourceWallet *Wallet, sourceAccountNumber i } } +// AddSendDestination adds an address and amount to receive +// to the transaction. func (tx *TxAuthor) AddSendDestination(address string, atomAmount int64, sendMax bool) { tx.destinations = append(tx.destinations, TransactionDestination{ Address: address, @@ -39,6 +42,7 @@ func (tx *TxAuthor) AddSendDestination(address string, atomAmount int64, sendMax }) } +//UpdateSendDestination updates the send destination at index. func (tx *TxAuthor) UpdateSendDestination(index int, address string, atomAmount int64, sendMax bool) { tx.destinations[index] = TransactionDestination{ Address: address, @@ -47,28 +51,15 @@ func (tx *TxAuthor) UpdateSendDestination(index int, address string, atomAmount } } +//RemoveSendDestination deletes a send destination suing the index. func (tx *TxAuthor) RemoveSendDestination(index int) { if len(tx.destinations) > index { tx.destinations = append(tx.destinations[:index], tx.destinations[index+1:]...) } } -func (tx *TxAuthor) SendDestination(atIndex int) *TransactionDestination { - return &tx.destinations[atIndex] -} - -func (tx *TxAuthor) TotalSendAmount() *Amount { - var totalSendAmountAtom int64 = 0 - for _, destination := range tx.destinations { - totalSendAmountAtom += destination.AtomAmount - } - - return &Amount{ - AtomValue: totalSendAmountAtom, - DcrValue: dcrutil.Amount(totalSendAmountAtom).ToCoin(), - } -} - +//EstimateFeeAndSize returns the information about the estimated +// transaction fee and size of transaction. func (tx *TxAuthor) EstimateFeeAndSize() (*TxFeeAndSize, error) { unsignedTx, err := tx.constructTransaction() if err != nil { @@ -87,6 +78,8 @@ func (tx *TxAuthor) EstimateFeeAndSize() (*TxFeeAndSize, error) { }, nil } +//EstimateMaxSendAmount returns the maximum spendable amount +// excluding the transaction fee. func (tx *TxAuthor) EstimateMaxSendAmount() (*Amount, error) { txFeeAndSize, err := tx.EstimateFeeAndSize() if err != nil { @@ -106,6 +99,7 @@ func (tx *TxAuthor) EstimateMaxSendAmount() (*Amount, error) { }, nil } +// Broadcast signs and publishes the transactions to the network. func (tx *TxAuthor) Broadcast(privatePassphrase []byte) ([]byte, error) { defer func() { for i := range privatePassphrase { diff --git a/txindex.go b/txindex.go index 086243dc..373c521e 100644 --- a/txindex.go +++ b/txindex.go @@ -6,6 +6,8 @@ import ( "github.com/raedahgroup/dcrlibwallet/txindex" ) +// IndexTransactions saves all wallet transactions +// into storm db. func (wallet *Wallet) IndexTransactions() error { ctx := wallet.shutdownContext() diff --git a/txindex/save.go b/txindex/save.go index 4de6e22f..95acb1f9 100644 --- a/txindex/save.go +++ b/txindex/save.go @@ -33,6 +33,8 @@ func (db *DB) SaveOrUpdate(emptyTxPointer, tx interface{}) (overwritten bool, er return } +// SaveLastIndexPoint this saves the ending block height +// from last tx index. func (db *DB) SaveLastIndexPoint(endBlockHeight int32) error { err := db.txDB.Set(TxBucketName, KeyEndBlock, &endBlockHeight) if err != nil { @@ -41,6 +43,7 @@ func (db *DB) SaveLastIndexPoint(endBlockHeight int32) error { return nil } +// ClearSavedTransactions deletes all transactions saved in storm db. func (db *DB) ClearSavedTransactions(emptyTxPointer interface{}) error { err := db.txDB.Drop(emptyTxPointer) if err != nil { diff --git a/utils.go b/utils.go index f950d6f8..efbafcad 100644 --- a/utils.go +++ b/utils.go @@ -88,6 +88,8 @@ func (mw *MultiWallet) contextWithShutdownCancel() (context.Context, context.Can return ctx, cancel } +// ValidateExtPubKey returns true if extendedPubKey is a +// valid extended public key. func (mw *MultiWallet) ValidateExtPubKey(extendedPubKey string) error { _, err := hdkeychain.NewKeyFromString(extendedPubKey, mw.chainParams) if err != nil { diff --git a/wallet.go b/wallet.go index f4bfc30f..680f68a8 100644 --- a/wallet.go +++ b/wallet.go @@ -85,6 +85,7 @@ func (wallet *Wallet) prepare(rootDir string, chainParams *chaincfg.Params, return nil } +// Shutdown closes the wallet and transaction db func (wallet *Wallet) Shutdown() { // Trigger shuttingDown signal to cancel all contexts created with // `wallet.shutdownContext()` or `wallet.shutdownContextWithCancel()`. @@ -109,10 +110,12 @@ func (wallet *Wallet) Shutdown() { } } +// NetType returns a human-readable identifier for a Network. func (wallet *Wallet) NetType() string { return wallet.chainParams.Name } +// WalletExists returns true if a wallet exists at the loaders' DB path. func (wallet *Wallet) WalletExists() (bool, error) { return wallet.loader.WalletExists() } @@ -158,6 +161,8 @@ func (wallet *Wallet) createWatchingOnlyWallet(extendedPublicKey string) error { return nil } +// IsWatchingOnlyWallet returns true if a wallet is +// a watching only wallet. func (wallet *Wallet) IsWatchingOnlyWallet() bool { if w, ok := wallet.loader.LoadedWallet(); ok { return w.Manager.WatchingOnly() @@ -184,6 +189,7 @@ func (wallet *Wallet) WalletOpened() bool { return wallet.internal != nil } +// UnlockWallet unlocks the wallet allowing access to private keys. func (wallet *Wallet) UnlockWallet(privPass []byte) error { loadedWallet, ok := wallet.loader.LoadedWallet() if !ok { @@ -205,12 +211,14 @@ func (wallet *Wallet) UnlockWallet(privPass []byte) error { return nil } +// LockWallet locks the wallet's address manager. func (wallet *Wallet) LockWallet() { if !wallet.internal.Locked() { wallet.internal.Lock() } } +// IsLocked returns true if a wallet is locked. func (wallet *Wallet) IsLocked() bool { return wallet.internal.Locked() } diff --git a/wallet_config.go b/wallet_config.go index ef782be1..e517b8ba 100644 --- a/wallet_config.go +++ b/wallet_config.go @@ -5,6 +5,7 @@ import ( "github.com/decred/dcrwallet/errors/v2" ) +// SaveUserConfigValue saves the provided key-value pair to a config database. func (wallet *Wallet) SaveUserConfigValue(key string, value interface{}) { if wallet.setUserConfigValue == nil { log.Errorf("call wallet.prepare before setting wallet config values") @@ -17,6 +18,7 @@ func (wallet *Wallet) SaveUserConfigValue(key string, value interface{}) { } } +// ReadUserConfigValue returns the saved key-value pair in a config database. func (wallet *Wallet) ReadUserConfigValue(key string, valueOut interface{}) error { if wallet.setUserConfigValue == nil { log.Errorf("call wallet.prepare before reading wallet config values") @@ -30,30 +32,44 @@ func (wallet *Wallet) ReadUserConfigValue(key string, valueOut interface{}) erro return err } +// SetBoolConfigValueForKey sets a bool value +// for key-value pair in a config database. func (wallet *Wallet) SetBoolConfigValueForKey(key string, value bool) { wallet.SaveUserConfigValue(key, value) } +// SetDoubleConfigValueForKey sets a float64 value +// for key-value pair in a config database. func (wallet *Wallet) SetDoubleConfigValueForKey(key string, value float64) { wallet.SaveUserConfigValue(key, value) } +// SetIntConfigValueForKey sets an int value +// for key-value pair in a config database. func (wallet *Wallet) SetIntConfigValueForKey(key string, value int) { wallet.SaveUserConfigValue(key, value) } +// SetInt32ConfigValueForKey sets an int32 value +// for key-value pair in a config database. func (wallet *Wallet) SetInt32ConfigValueForKey(key string, value int32) { wallet.SaveUserConfigValue(key, value) } +// SetLongConfigValueForKey sets an int64 value +// for key-value pair in a config database. func (wallet *Wallet) SetLongConfigValueForKey(key string, value int64) { wallet.SaveUserConfigValue(key, value) } +// SetStringConfigValueForKey sets a string value +// for key-value pair in a config database. func (wallet *Wallet) SetStringConfigValueForKey(key, value string) { wallet.SaveUserConfigValue(key, value) } +// ReadBoolConfigValueForKey returns the bool value +// for key-value pair from a config database. func (wallet *Wallet) ReadBoolConfigValueForKey(key string, defaultValue bool) (valueOut bool) { if err := wallet.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -61,6 +77,8 @@ func (wallet *Wallet) ReadBoolConfigValueForKey(key string, defaultValue bool) ( return } +// ReadDoubleConfigValueForKey returns a float64 value +// for key-value pair from a config database. func (wallet *Wallet) ReadDoubleConfigValueForKey(key string, defaultValue float64) (valueOut float64) { if err := wallet.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -68,6 +86,8 @@ func (wallet *Wallet) ReadDoubleConfigValueForKey(key string, defaultValue float return } +// ReadIntConfigValueForKey returns an int value +// for a key-value pair from a config database. func (wallet *Wallet) ReadIntConfigValueForKey(key string, defaultValue int) (valueOut int) { if err := wallet.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -75,6 +95,8 @@ func (wallet *Wallet) ReadIntConfigValueForKey(key string, defaultValue int) (va return } +// ReadInt32ConfigValueForKey returns an int32 value +// for a key-value pair from a config database. func (wallet *Wallet) ReadInt32ConfigValueForKey(key string, defaultValue int32) (valueOut int32) { if err := wallet.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -82,6 +104,8 @@ func (wallet *Wallet) ReadInt32ConfigValueForKey(key string, defaultValue int32) return } +// ReadLongConfigValueForKey returns an int64 value +// for a key-value pair from a config database. func (wallet *Wallet) ReadLongConfigValueForKey(key string, defaultValue int64) (valueOut int64) { if err := wallet.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue @@ -89,6 +113,8 @@ func (wallet *Wallet) ReadLongConfigValueForKey(key string, defaultValue int64) return } +// ReadStringConfigValueForKey returns the string value +// for a key-value pair from a config database. func (wallet *Wallet) ReadStringConfigValueForKey(key string, defaultValue string) (valueOut string) { if err := wallet.ReadUserConfigValue(key, &valueOut); err == storm.ErrNotFound { valueOut = defaultValue diff --git a/wallets.go b/wallets.go index c5f97cc7..28ab0eaa 100644 --- a/wallets.go +++ b/wallets.go @@ -1,5 +1,6 @@ package dcrlibwallet +// AllWallets returns an array of loaded wallets. func (mw *MultiWallet) AllWallets() (wallets []*Wallet) { for _, wallet := range mw.wallets { wallets = append(wallets, wallet) @@ -7,6 +8,7 @@ func (mw *MultiWallet) AllWallets() (wallets []*Wallet) { return wallets } +// WalletsIterator returns an iterator for mw wallets. func (mw *MultiWallet) WalletsIterator() *WalletsIterator { return &WalletsIterator{ currentIndex: 0, @@ -14,6 +16,8 @@ func (mw *MultiWallet) WalletsIterator() *WalletsIterator { } } +// Next iterates returns the wallet at the current iterator +// index and increments the iterator index. func (walletsIterator *WalletsIterator) Next() *Wallet { if walletsIterator.currentIndex < len(walletsIterator.wallets) { wallet := walletsIterator.wallets[walletsIterator.currentIndex] @@ -24,6 +28,7 @@ func (walletsIterator *WalletsIterator) Next() *Wallet { return nil } +// Reset sets the iterator index to 0. func (walletsIterator *WalletsIterator) Reset() { walletsIterator.currentIndex = 0 }