From 678a6b4659f58d87e14d9a2dbbbd5ca1c1214c13 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Fri, 6 Mar 2020 14:22:52 +0100 Subject: [PATCH 01/41] documentation for accounts --- accounts.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/accounts.go b/accounts.go index 77c6a818..5b7eb7fd 100644 --- a/accounts.go +++ b/accounts.go @@ -9,6 +9,7 @@ import ( "github.com/decred/dcrwallet/errors/v2" ) +//GetAccounts returns a json.Marshal of an account information in a wallet. func (wallet *Wallet) GetAccounts(requiredConfirmations int32) (string, error) { accountsResponse, err := wallet.GetAccountsRaw(requiredConfirmations) if err != nil { @@ -19,6 +20,7 @@ func (wallet *Wallet) GetAccounts(requiredConfirmations int32) (string, error) { return string(result), nil } +//GetAccountsRaw returns all the information about an existing account func (wallet *Wallet) GetAccountsRaw(requiredConfirmations int32) (*Accounts, error) { resp, err := wallet.internal.Accounts(wallet.shutdownContext()) if err != nil { @@ -51,6 +53,7 @@ func (wallet *Wallet) GetAccountsRaw(requiredConfirmations int32) (*Accounts, er }, nil } +//AccountsIterator gets account information of an func (wallet *Wallet) AccountsIterator(requiredConfirmations int32) (*AccountsIterator, error) { accounts, err := wallet.GetAccountsRaw(requiredConfirmations) if err != nil { @@ -63,6 +66,8 @@ func (wallet *Wallet) AccountsIterator(requiredConfirmations int32) (*AccountsIt }, nil } +//Iterates over the available accounts in the wallet and +// returns the account within the length of the available accounts func (accountsInterator *AccountsIterator) Next() *Account { if accountsInterator.currentIndex < len(accountsInterator.accounts) { account := accountsInterator.accounts[accountsInterator.currentIndex] @@ -73,10 +78,13 @@ func (accountsInterator *AccountsIterator) Next() *Account { return nil } +//Sets the account index to default: 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, requiredConfirmations int32) (*Account, error) { props, err := wallet.internal.AccountProperties(wallet.shutdownContext(), uint32(accountNumber)) if err != nil { @@ -102,6 +110,8 @@ func (wallet *Wallet) GetAccount(accountNumber int32, requiredConfirmations int3 return account, nil } +//GetAccountBalance sums up the amount of all unspent transaction output in given +//account of a wallet and returns the available balance. func (wallet *Wallet) GetAccountBalance(accountNumber int32, requiredConfirmations int32) (*Balance, error) { balance, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(accountNumber), requiredConfirmations) if err != nil { @@ -119,6 +129,8 @@ func (wallet *Wallet) GetAccountBalance(accountNumber int32, requiredConfirmatio }, nil } +//SpendableForAccount sums up the amount of all unspent transaction output +//in a given account of a wallet and returns the spendable amount. func (wallet *Wallet) SpendableForAccount(account int32, requiredConfirmations int32) (int64, error) { bals, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(account), requiredConfirmations) if err != nil { @@ -149,6 +161,7 @@ func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, e return int32(accountNumber), err } +//Sets the name of an account to a newName func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error { err := wallet.internal.RenameAccount(wallet.shutdownContext(), uint32(accountNumber), newName) if err != nil { @@ -158,6 +171,7 @@ func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error { return nil } +//Checks for an account and logs error if wallet is empty func (wallet *Wallet) AccountName(accountNumber int32) string { name, err := wallet.AccountNameRaw(uint32(accountNumber)) if err != nil { @@ -167,14 +181,18 @@ func (wallet *Wallet) AccountName(accountNumber int32) string { return name } +//Returns the account name for the corresponding account number. func (wallet *Wallet) AccountNameRaw(accountNumber uint32) (string, error) { return wallet.internal.AccountName(wallet.shutdownContext(), accountNumber) } +//Returns an account number for the corresponding account name. func (wallet *Wallet) AccountNumber(accountName string) (uint32, error) { return wallet.internal.AccountNumber(wallet.shutdownContext(), accountName) } +//Checks and identifies the coin network type for the account +// and returns the path for any of the mainnet, testnet, or legacy. func (wallet *Wallet) HDPathForAccount(accountNumber int32) (string, error) { cointype, err := wallet.internal.CoinType(wallet.shutdownContext()) if err != nil { From 41c58fc957a93c1de3e298741353273216a07bef Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Fri, 6 Mar 2020 16:03:26 +0100 Subject: [PATCH 02/41] documentation for address --- address.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/address.go b/address.go index f6c69192..363c5d5c 100644 --- a/address.go +++ b/address.go @@ -19,11 +19,14 @@ type AddressInfo struct { AccountName string } +// IsAddressValid decodes the string coding of an address and +// returns whether the network param is valid or not func (wallet *Wallet) IsAddressValid(address string) bool { _, err := dcrutil.DecodeAddress(address, wallet.chainParams) return err == nil } +//HaveAddress returns whether or not 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 +41,8 @@ func (wallet *Wallet) HaveAddress(address string) bool { return have } +//AccountOfAddress returns a detailed information of an +// account belonging to a wallet address. func (wallet *Wallet) AccountOfAddress(address string) string { addr, err := dcrutil.DecodeAddress(address, wallet.chainParams) if err != nil { @@ -48,6 +53,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 +76,8 @@ func (wallet *Wallet) AddressInfo(address string) (*AddressInfo, error) { return addressInfo, nil } +//CurrentAddress returns the string encoding of the +// most recent payment address. func (wallet *Wallet) CurrentAddress(account int32) (string, error) { if wallet.IsRestored && !wallet.HasDiscoveredAccounts { return "", errors.E(ErrAddressDiscoveryNotDone) @@ -82,6 +91,7 @@ func (wallet *Wallet) CurrentAddress(account int32) (string, error) { return addr.Address(), nil } +//NextAddress returns the string encoding an external address. func (wallet *Wallet) NextAddress(account int32) (string, error) { if wallet.IsRestored && !wallet.HasDiscoveredAccounts { return "", errors.E(ErrAddressDiscoveryNotDone) @@ -95,6 +105,7 @@ func (wallet *Wallet) NextAddress(account int32) (string, error) { return addr.Address(), nil } +//AddressPubKey returns the public key of an address in wallet. func (wallet *Wallet) AddressPubKey(address string) (string, error) { addr, err := dcrutil.DecodeAddress(address, wallet.chainParams) if err != nil { From 2081259b34fe37a081f1fc863f32184e36da2907 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Fri, 6 Mar 2020 22:38:59 +0100 Subject: [PATCH 03/41] documentation for message and multiwallet --- message.go | 2 ++ multiwallet.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/message.go b/message.go index 965afdf4..65397a05 100644 --- a/message.go +++ b/message.go @@ -9,6 +9,7 @@ import ( w "github.com/decred/dcrwallet/wallet/v3" ) +//SignMessage returns a signature of a signed message func (wallet *Wallet) SignMessage(passphrase []byte, address string, message string) ([]byte, error) { lock := make(chan time.Time, 1) defer func() { @@ -45,6 +46,7 @@ func (wallet *Wallet) SignMessage(passphrase []byte, address string, message str return sig, nil } +//VerifyMessage returns whether or not the signature of a signed message is valid func (wallet *Wallet) VerifyMessage(address string, message string, signatureBase64 string) (bool, error) { var valid bool diff --git a/multiwallet.go b/multiwallet.go index a8041fa5..d5c09aae 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -139,10 +139,13 @@ func (mw *MultiWallet) Shutdown() { } } +//SetStartupPassPhrase sets the passPhrase of a wallet. func (mw *MultiWallet) SetStartupPassphrase(passphrase []byte, passphraseType int32) error { return mw.ChangeStartupPassphrase([]byte(""), passphrase, passphraseType) } +//VerifyStartupPassphrase checks for and verifies the passPhrase of a wallet +// and returns an error respectively. func (mw *MultiWallet) VerifyStartupPassphrase(startupPassphrase []byte) error { var startupPassphraseHash []byte err := mw.db.Get(walletsMetadataBucketName, walletstartupPassphraseField, &startupPassphraseHash) @@ -167,6 +170,8 @@ func (mw *MultiWallet) VerifyStartupPassphrase(startupPassphrase []byte) error { return nil } +//ChangeStartupPassPhrase verifies the current passPhrase +// and generates and sets a new one. func (mw *MultiWallet) ChangeStartupPassphrase(oldPassphrase, newPassphrase []byte, passphraseType int32) error { if len(newPassphrase) == 0 { return mw.RemoveStartupPassphrase(oldPassphrase) @@ -193,6 +198,7 @@ func (mw *MultiWallet) ChangeStartupPassphrase(oldPassphrase, newPassphrase []by return nil } +//RemoveStartupPassphrase verifies the current passPhrase and deletes it. func (mw *MultiWallet) RemoveStartupPassphrase(oldPassphrase []byte) error { err := mw.VerifyStartupPassphrase(oldPassphrase) if err != nil { @@ -210,14 +216,18 @@ func (mw *MultiWallet) RemoveStartupPassphrase(oldPassphrase []byte) error { return nil } +//IsStartupSecuritySet returns whether ot not the startup security is set. func (mw *MultiWallet) IsStartupSecuritySet() bool { return mw.ReadBoolConfigValueForKey(IsStartupSecuritySetConfigKey, false) } +//StartupSecurityType returns the type of security used for the startup passPhrase func (mw *MultiWallet) StartupSecurityType() int32 { return mw.ReadInt32ConfigValueForKey(StartupSecurityTypeConfigKey, PassphraseTypePass) } +//OpenWallets checks whether or not the wallets is syncing, +// verifies the passPhrase and opens the wallet func (mw *MultiWallet) OpenWallets(startupPassphrase []byte) error { if mw.IsSyncing() { return errors.New(ErrSyncAlreadyInProgress) @@ -240,6 +250,8 @@ func (mw *MultiWallet) OpenWallets(startupPassphrase []byte) error { return nil } +//CreateWatchOnlyWallet creates a watch-only wallet, +// without neither a wallet seed nor a private keys. func (mw *MultiWallet) CreateWatchOnlyWallet(walletName, extendedPublicKey string) (*Wallet, error) { wallet := &Wallet{ Name: walletName, @@ -256,6 +268,8 @@ func (mw *MultiWallet) CreateWatchOnlyWallet(walletName, extendedPublicKey strin }) } +//CreateNewWallet creates a new wallet with +// wallet seed as well as private PassPhrase func (mw *MultiWallet) CreateNewWallet(privatePassphrase string, privatePassphraseType int32) (*Wallet, error) { seed, err := GenerateSeed() if err != nil { @@ -278,6 +292,8 @@ func (mw *MultiWallet) CreateNewWallet(privatePassphrase string, privatePassphra }) } +//RestoreWallet uses a wallet seed, private passPhrase +// to restore a previously existing wallet. func (mw *MultiWallet) RestoreWallet(seedMnemonic, privatePassphrase string, privatePassphraseType int32) (*Wallet, error) { wallet := &Wallet{ PrivatePassphraseType: privatePassphraseType, @@ -295,6 +311,7 @@ func (mw *MultiWallet) RestoreWallet(seedMnemonic, privatePassphrase string, pri }) } +//LinkExistingWallet links an already existing wallet to a new one func (mw *MultiWallet) LinkExistingWallet(walletDataDir, originalPubPass string, privatePassphraseType int32) (*Wallet, error) { if mw.IsSyncing() { return nil, errors.New(ErrSyncAlreadyInProgress) @@ -424,6 +441,8 @@ func (mw *MultiWallet) saveNewWallet(wallet *Wallet, setupWallet func() error) ( return wallet, nil } +//RenameWallet checks the newName if it contains an existing name +// and returns an updated walletName for the wallet. func (mw *MultiWallet) RenameWallet(walletID int, newName string) error { if strings.HasPrefix(newName, "wallet-") { return errors.E(ErrReservedWalletName) @@ -444,6 +463,7 @@ func (mw *MultiWallet) RenameWallet(walletID int, newName string) error { return mw.db.Save(wallet) // update WalletName field } +//DeleteWallet checks whether or not wallet is syncing, then deletes teh wallet with its accompanying Id func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { if mw.IsSyncing() { return errors.New(ErrSyncAlreadyInProgress) @@ -469,6 +489,7 @@ func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { return nil } +//WalletWithID returns wallet with an Id for easy selection func (mw *MultiWallet) WalletWithID(walletID int) *Wallet { if wallet, ok := mw.wallets[walletID]; ok { return wallet @@ -476,6 +497,7 @@ func (mw *MultiWallet) WalletWithID(walletID int) *Wallet { return nil } +//VerifySeedForWallet checks if a certain wallets' seed is a match. func (mw *MultiWallet) VerifySeedForWallet(walletID int, seedMnemonic string) error { wallet := mw.WalletWithID(walletID) if wallet == nil { @@ -490,6 +512,8 @@ func (mw *MultiWallet) VerifySeedForWallet(walletID int, seedMnemonic string) er return errors.New(ErrInvalid) } +//NumWalletsNeedingSeedBackup iterates over the available +// wallets and checks and returns a list of any needing backups. func (mw *MultiWallet) NumWalletsNeedingSeedBackup() int32 { var backupsNeeded int32 for _, wallet := range mw.wallets { @@ -501,10 +525,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 an array of int of walletIDs of wallets opened func (mw *MultiWallet) OpenedWalletIDsRaw() []int { walletIDs := make([]int, 0) for _, wallet := range mw.wallets { @@ -515,16 +541,19 @@ func (mw *MultiWallet) OpenedWalletIDsRaw() []int { return walletIDs } +//OpenedWalletIDs returns a json.marshal of opened walletIDs func (mw *MultiWallet) OpenedWalletIDs() string { walletIDs := mw.OpenedWalletIDsRaw() jsonEncoded, _ := json.Marshal(&walletIDs) return string(jsonEncoded) } +//OpenedWalletsCount returns teh number of opened wallets func (mw *MultiWallet) OpenedWalletsCount() int32 { return int32(len(mw.OpenedWalletIDsRaw())) } +//SyncedWalletsCount returns an int of synced wallets func (mw *MultiWallet) SyncedWalletsCount() int32 { var syncedWallets int32 for _, wallet := range mw.wallets { @@ -536,6 +565,7 @@ func (mw *MultiWallet) SyncedWalletsCount() int32 { return syncedWallets } +//WalletNameExists returns whether or not a chosen walletName exists func (mw *MultiWallet) WalletNameExists(walletName string) (bool, error) { if strings.HasPrefix(walletName, "wallet-") { return false, errors.E(ErrReservedWalletName) @@ -551,6 +581,7 @@ func (mw *MultiWallet) WalletNameExists(walletName string) (bool, error) { return false, nil } +//UnlockWallet unlocks a wallet using the said wallets ID and privatePassPhrase func (mw *MultiWallet) UnlockWallet(walletID int, privPass []byte) error { wallet := mw.WalletWithID(walletID) if wallet == nil { @@ -560,6 +591,7 @@ 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) From 0b8564ea790e40cd574a3952e3c7c6e06b42e8b6 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Sat, 7 Mar 2020 18:09:23 +0100 Subject: [PATCH 04/41] spell check --- multiwallet.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multiwallet.go b/multiwallet.go index d5c09aae..110fd2ce 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -463,7 +463,7 @@ func (mw *MultiWallet) RenameWallet(walletID int, newName string) error { return mw.db.Save(wallet) // update WalletName field } -//DeleteWallet checks whether or not wallet is syncing, then deletes teh wallet with its accompanying Id +//DeleteWallet checks whether or not wallet is syncing, then deletes the wallet with its accompanying Id func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { if mw.IsSyncing() { return errors.New(ErrSyncAlreadyInProgress) @@ -548,7 +548,7 @@ func (mw *MultiWallet) OpenedWalletIDs() string { return string(jsonEncoded) } -//OpenedWalletsCount returns teh number of opened wallets +//OpenedWalletsCount returns the number of opened wallets func (mw *MultiWallet) OpenedWalletsCount() int32 { return int32(len(mw.OpenedWalletIDsRaw())) } From 76f93213c76e55e3a8fd47f99e6ea4e97a5b4dad Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Sat, 7 Mar 2020 18:51:21 +0100 Subject: [PATCH 05/41] documentation for multiwallet_config --- multiwallet_config.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/multiwallet_config.go b/multiwallet_config.go index 20ed8611..5739ce8c 100644 --- a/multiwallet_config.go +++ b/multiwallet_config.go @@ -49,6 +49,7 @@ func (mw *MultiWallet) walletConfigReadFn(walletID int) configReadFn { } } +//SaveUserConfigValue saves config value name for key func (mw *MultiWallet) SaveUserConfigValue(key string, value interface{}) { err := mw.db.Set(userConfigBucketName, key, value) if err != nil { @@ -56,6 +57,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 { @@ -64,6 +66,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 { @@ -71,6 +74,7 @@ func (mw *MultiWallet) DeleteUserConfigValueForKey(key string) { } } +//ClearConfig drops a config bucket name func (mw *MultiWallet) ClearConfig() { err := mw.db.Drop(userConfigBucketName) if err != nil { @@ -78,30 +82,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 @@ -109,6 +120,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 @@ -116,6 +128,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 @@ -123,6 +136,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 @@ -130,6 +144,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 @@ -137,6 +152,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 From a6dd0c6f3f6a9b4eb14861ea64ca05ea04dd391c Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Sat, 7 Mar 2020 19:13:46 +0100 Subject: [PATCH 06/41] documentation for rescan.go --- rescan.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rescan.go b/rescan.go index 84bfa526..22c61b9a 100644 --- a/rescan.go +++ b/rescan.go @@ -9,6 +9,8 @@ import ( w "github.com/decred/dcrwallet/wallet/v3" ) +//RescanBlocks checks whether or not the blocks are scanned or synced. +//If they are not updated, it scans the the block header until is it manually canceled. 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 locks the wallet out from syncing func (mw *MultiWallet) CancelRescan() { mw.syncData.mu.Lock() defer mw.syncData.mu.Unlock() @@ -118,12 +121,14 @@ func (mw *MultiWallet) CancelRescan() { } } +//IsRescanning bypasses the lock on wallet for syncing to be carried out func (mw *MultiWallet) IsRescanning() bool { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() return mw.syncData.rescanning } +//SetBlocksRescanProgressListener sets a block for the scan progress listener func (mw *MultiWallet) SetBlocksRescanProgressListener(blocksRescanProgressListener BlocksRescanProgressListener) { mw.blocksRescanProgressListener = blocksRescanProgressListener } From 54ecea85c1bdde46a36e965f238b772577aba1b4 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Sun, 8 Mar 2020 01:49:56 +0100 Subject: [PATCH 07/41] documentation for sync.go --- sync.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sync.go b/sync.go index 4fa2adbb..39c11716 100644 --- a/sync.go +++ b/sync.go @@ -90,6 +90,8 @@ func (mw *MultiWallet) initActiveSyncData() { mw.syncData.mu.Unlock() } +//IsSyncProgressListenerRegisteredFor checks for and returns a value that checks +// whether or not a progress listener was set for the wallet syncing. 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 progress listener for wallet syncing. func (mw *MultiWallet) RemoveSyncProgressListener(uniqueIdentifier string) { mw.syncData.mu.Lock() delete(mw.syncData.syncProgressListeners, uniqueIdentifier) @@ -128,6 +133,7 @@ func (mw *MultiWallet) syncProgressListeners() []SyncProgressListener { return listeners } +//PublishLastSyncProgress fetches and publishes sync and scan data func (mw *MultiWallet) PublishLastSyncProgress(uniqueIdentifier string) error { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -151,12 +157,14 @@ func (mw *MultiWallet) PublishLastSyncProgress(uniqueIdentifier string) error { return nil } +//EnableSyncLogs enables logging of scan 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 +181,7 @@ func (mw *MultiWallet) SyncInactiveForPeriod(totalInactiveSeconds int64) { } } +//SpvSync sets a wallet syncing for 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 +267,7 @@ func (mw *MultiWallet) SpvSync() error { return nil } +//RestartSpvSync sends a request to restart SpvSync func (mw *MultiWallet) RestartSpvSync() error { mw.syncData.mu.Lock() mw.syncData.restartSyncRequested = true @@ -267,6 +277,7 @@ func (mw *MultiWallet) RestartSpvSync() error { return mw.SpvSync() } +//CancelSync cancels/stops any active wallet syncing func (mw *MultiWallet) CancelSync() { mw.syncData.mu.RLock() cancelSync := mw.syncData.cancelSync @@ -297,30 +308,38 @@ func (mw *MultiWallet) CancelSync() { } } +//IsWaiting returns whether or not a wallet is waiting to be synced func (wallet *Wallet) IsWaiting() bool { return wallet.waiting } +//IsSynced returns whether or not a wallet has been synced func (wallet *Wallet) IsSynced() bool { return wallet.synced } +//IsSyncing returns whether or not a wallet is undergoing syncing func (wallet *Wallet) IsSyncing() bool { return wallet.syncing } +//IsSynced returns the state of a wallet +// being synced if it has been synced func (mw *MultiWallet) IsSynced() bool { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() return mw.syncData.synced } +//IsSyncing returns the state of a wallet undergoing syncing, +//if it is 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 wallet func (mw *MultiWallet) CurrentSyncStage() int32 { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -331,6 +350,7 @@ func (mw *MultiWallet) CurrentSyncStage() int32 { return InvalidSyncStage } +//GeneralSyncProgress returns the total sync progress func (mw *MultiWallet) GeneralSyncProgress() *GeneralSyncProgress { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -349,12 +369,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 the best block height of a loaded wallet func (mw *MultiWallet) GetBestBlock() *BlockInfo { var bestBlock int32 = -1 var blockInfo *BlockInfo @@ -373,6 +395,7 @@ func (mw *MultiWallet) GetBestBlock() *BlockInfo { return blockInfo } +//GetLowestBlock gets the lowest block height of a loaded wallet func (mw *MultiWallet) GetLowestBlock() *BlockInfo { var lowestBlock int32 = -1 var blockInfo *BlockInfo @@ -390,6 +413,7 @@ func (mw *MultiWallet) GetLowestBlock() *BlockInfo { return blockInfo } +//GetBestBlock gets 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. @@ -401,6 +425,7 @@ func (wallet *Wallet) GetBestBlock() int32 { return height } +//GetBestBlockTimeStamp gets the best Timestamp of a block header event func (wallet *Wallet) GetBestBlockTimeStamp() int64 { if wallet.internal == nil { // This method is sometimes called after a wallet is deleted and causes crash. @@ -419,6 +444,7 @@ func (wallet *Wallet) GetBestBlockTimeStamp() int64 { return info.Timestamp } +//GetLowestBlockTimestamp gets the lowest Timestamp of a block header event func (mw *MultiWallet) GetLowestBlockTimestamp() int64 { var timestamp int64 = -1 for _, wallet := range mw.wallets { From f4863d0d0dc2c37626aa8456200dd901c3492a0f Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Mon, 9 Mar 2020 14:39:36 +0100 Subject: [PATCH 08/41] documentations for tickets, tx, txnblocknotification --- ticket.go | 3 +++ transactions.go | 9 +++++++++ txandblocknotifications.go | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/ticket.go b/ticket.go index 2775bf50..08d1cac4 100644 --- a/ticket.go +++ b/ticket.go @@ -36,6 +36,7 @@ func (wallet *Wallet) StakeInfo() (*w.StakeInfoData, error) { return wallet.internal.StakeInfo(ctx) } +//GetTickets returns information about ticket request func (wallet *Wallet) GetTickets(startingBlockHash, endingBlockHash []byte, targetCount int32) ([]*TicketInfo, error) { return wallet.getTickets(&GetTicketsRequest{ StartingBlockHash: startingBlockHash, @@ -44,6 +45,8 @@ func (wallet *Wallet) GetTickets(startingBlockHash, endingBlockHash []byte, targ }) } +//GetTicketsForBlockHeightRange returns information about +// ticket request used for block height range. func (wallet *Wallet) GetTicketsForBlockHeightRange(startHeight, endHeight, targetCount int32) ([]*TicketInfo, error) { return wallet.getTickets(&GetTicketsRequest{ StartingBlockHeight: startHeight, diff --git a/transactions.go b/transactions.go index 9e33745c..372edef9 100644 --- a/transactions.go +++ b/transactions.go @@ -32,6 +32,7 @@ const ( TxTypeRevocation = txhelper.TxTypeRevocation ) +//GetTransaction returns the JSON encoding of transactions in a wallet func (wallet *Wallet) GetTransaction(txHash []byte) (string, error) { transaction, err := wallet.GetTransactionRaw(txHash) if err != nil { @@ -47,6 +48,7 @@ func (wallet *Wallet) GetTransaction(txHash []byte) (string, error) { return string(result), nil } +//GetTransactionRaw returns the details of transaction related to the wallet func (wallet *Wallet) GetTransactionRaw(txHash []byte) (*Transaction, error) { hash, err := chainhash.NewHash(txHash) if err != nil { @@ -63,6 +65,8 @@ func (wallet *Wallet) GetTransactionRaw(txHash []byte) (*Transaction, error) { return wallet.decodeTransactionWithTxSummary(txSummary, blockHash) } +//GetTransactions returns the JSON encoding of all transactions +// in a wallet starting from the most recent 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 +81,14 @@ func (wallet *Wallet) GetTransactions(offset, limit, txFilter int32, newestFirst return string(jsonEncodedTransactions), nil } +//GetTransactionsRaw returns the details of transactions related to the wallet 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 +// in several wallets starting from the newest wallet created func (mw *MultiWallet) GetTransactions(offset, limit, txFilter int32, newestFirst bool) (string, error) { transactions := make([]Transaction, 0) for _, wallet := range mw.wallets { @@ -113,6 +120,8 @@ func (mw *MultiWallet) GetTransactions(offset, limit, txFilter int32, newestFirs return string(jsonEncodedTransactions), nil } +//CountTransactions returns number of recorded transactions that +// occurred within a wallet at a given period of time func (wallet *Wallet) CountTransactions(txFilter int32) (int, error) { return wallet.txDB.Count(txFilter, &Transaction{}) } diff --git a/txandblocknotifications.go b/txandblocknotifications.go index 6bf05984..b6b9440a 100644 --- a/txandblocknotifications.go +++ b/txandblocknotifications.go @@ -61,6 +61,8 @@ func (mw *MultiWallet) listenForTransactions(walletID int) { } } +//AddTxAndBlockNotificationListener adds a notification listener +// for transaction and certain block height on wallet func (mw *MultiWallet) AddTxAndBlockNotificationListener(txAndBlockNotificationListener TxAndBlockNotificationListener, uniqueIdentifier string) error { _, ok := mw.txAndBlockNotificationListeners[uniqueIdentifier] if ok { @@ -72,6 +74,8 @@ func (mw *MultiWallet) AddTxAndBlockNotificationListener(txAndBlockNotificationL return nil } +//RemoveTxAndBlockNotificationListener deletes the notification +// listener set for transaction and block height in a wallet func (mw *MultiWallet) RemoveTxAndBlockNotificationListener(uniqueIdentifier string) { delete(mw.txAndBlockNotificationListeners, uniqueIdentifier) } From d9e945a500b0a32a9b7a412a5c8f3e2565319a1a Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Mon, 9 Mar 2020 17:02:28 +0100 Subject: [PATCH 09/41] documentation for txauthor, txindex, utils, and wallet --- txauthor.go | 9 +++++++++ txindex.go | 2 ++ utils.go | 1 + wallet.go | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/txauthor.go b/txauthor.go index f8c59433..f18476ed 100644 --- a/txauthor.go +++ b/txauthor.go @@ -22,6 +22,7 @@ type TxAuthor struct { wallet *Wallet } +//NewUnsignedTx returns information on the account of transaction author func (wallet *Wallet) NewUnsignedTx(sourceAccountNumber, requiredConfirmations int32) *TxAuthor { return &TxAuthor{ sendFromAccount: uint32(sourceAccountNumber), @@ -31,10 +32,12 @@ func (wallet *Wallet) NewUnsignedTx(sourceAccountNumber, requiredConfirmations i } } +//SetSourceAccount sets the particular account from which to carry out transaction func (tx *TxAuthor) SetSourceAccount(accountNumber int32) { tx.sendFromAccount = uint32(accountNumber) } +//AddSendDestination sets the wallet address to which funds are sent to func (tx *TxAuthor) AddSendDestination(address string, atomAmount int64, sendMax bool) { tx.destinations = append(tx.destinations, TransactionDestination{ Address: address, @@ -43,6 +46,7 @@ func (tx *TxAuthor) AddSendDestination(address string, atomAmount int64, sendMax }) } +//UpdateSendDestination allows for a change in wallet address to which funds are sent to func (tx *TxAuthor) UpdateSendDestination(index int, address string, atomAmount int64, sendMax bool) { tx.destinations[index] = TransactionDestination{ Address: address, @@ -51,12 +55,14 @@ func (tx *TxAuthor) UpdateSendDestination(index int, address string, atomAmount } } +//RemoveSendDestination deletes an address that was set for receiving funds func (tx *TxAuthor) RemoveSendDestination(index int) { if len(tx.destinations) > index { tx.destinations = append(tx.destinations[:index], tx.destinations[index+1:]...) } } +//EstimateFeeAndSize returns the information about transaction fee and estimated size of transaction func (tx *TxAuthor) EstimateFeeAndSize() (*TxFeeAndSize, error) { unsignedTx, err := tx.constructTransaction() if err != nil { @@ -75,6 +81,8 @@ func (tx *TxAuthor) EstimateFeeAndSize() (*TxFeeAndSize, error) { }, nil } +//EstimateMaxSendAmount returns the estimated limit of funds to send +//or an error if no amount is set func (tx *TxAuthor) EstimateMaxSendAmount() (*Amount, error) { txFeeAndSize, err := tx.EstimateFeeAndSize() if err != nil { @@ -94,6 +102,7 @@ func (tx *TxAuthor) EstimateMaxSendAmount() (*Amount, error) { }, nil } +//Broadcast allows for pasting of raw transactions conducted in a wallet func (tx *TxAuthor) Broadcast(privatePassphrase []byte) ([]byte, error) { defer func() { for i := range privatePassphrase { diff --git a/txindex.go b/txindex.go index 086243dc..50af8617 100644 --- a/txindex.go +++ b/txindex.go @@ -6,6 +6,8 @@ import ( "github.com/raedahgroup/dcrlibwallet/txindex" ) +//IndexTransactions returns an index of all transactions +// from start to end of a full block height func (wallet *Wallet) IndexTransactions() error { ctx := wallet.shutdownContext() diff --git a/utils.go b/utils.go index d9c08a1e..c5d29de4 100644 --- a/utils.go +++ b/utils.go @@ -71,6 +71,7 @@ func (mw *MultiWallet) contextWithShutdownCancel() (context.Context, context.Can return ctx, cancel } +//ValidateExtPubKey provides an instance of key extension required by the network type 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..d2a9ab9c 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 whether or not a wallet exists at the loaders' db path func (wallet *Wallet) WalletExists() (bool, error) { return wallet.loader.WalletExists() } @@ -158,6 +161,7 @@ func (wallet *Wallet) createWatchingOnlyWallet(extendedPublicKey string) error { return nil } +//IsWatchingOnlyWallet returns whether or not a wallet is in watching only mode func (wallet *Wallet) IsWatchingOnlyWallet() bool { if w, ok := wallet.loader.LoadedWallet(); ok { return w.Manager.WatchingOnly() @@ -184,6 +188,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 +210,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 whether a wallet is locked func (wallet *Wallet) IsLocked() bool { return wallet.internal.Locked() } From d91fe0788d488a64f1374dfc5d988ceba89cd086 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Mon, 9 Mar 2020 22:10:01 +0100 Subject: [PATCH 10/41] documentation for wallets and wallet_config --- wallet_config.go | 26 ++++++++++++++++++++++++++ wallets.go | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/wallet_config.go b/wallet_config.go index e5fce2b6..a6e4ce83 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..240eebc0 100644 --- a/wallets.go +++ b/wallets.go @@ -1,5 +1,6 @@ package dcrlibwallet +//AllWallets returns all the available wallets in a MultiWallet instance 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 all the available wallets and their index in a MultiWallet instance func (mw *MultiWallet) WalletsIterator() *WalletsIterator { return &WalletsIterator{ currentIndex: 0, @@ -14,6 +16,8 @@ func (mw *MultiWallet) WalletsIterator() *WalletsIterator { } } +//Next iterates over the the wallets in a MultiWallet instance and returns a wallet +// that has an index within the length of the available wallets 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 wallet to display at index 0 func (walletsIterator *WalletsIterator) Reset() { walletsIterator.currentIndex = 0 } From d6b0d012d3b3eea593bfe2cf5a16ad3d1370b618 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 10 Mar 2020 10:18:49 +0100 Subject: [PATCH 11/41] corrected multiwallet --- multiwallet.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multiwallet.go b/multiwallet.go index 110fd2ce..d5c09aae 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -463,7 +463,7 @@ func (mw *MultiWallet) RenameWallet(walletID int, newName string) error { return mw.db.Save(wallet) // update WalletName field } -//DeleteWallet checks whether or not wallet is syncing, then deletes the wallet with its accompanying Id +//DeleteWallet checks whether or not wallet is syncing, then deletes teh wallet with its accompanying Id func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { if mw.IsSyncing() { return errors.New(ErrSyncAlreadyInProgress) @@ -548,7 +548,7 @@ func (mw *MultiWallet) OpenedWalletIDs() string { return string(jsonEncoded) } -//OpenedWalletsCount returns the number of opened wallets +//OpenedWalletsCount returns teh number of opened wallets func (mw *MultiWallet) OpenedWalletsCount() int32 { return int32(len(mw.OpenedWalletIDsRaw())) } From 778174ec76b21a72b518c73e1f900a902b81be85 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 10 Mar 2020 11:57:24 +0100 Subject: [PATCH 12/41] corrected MultiWallet --- multiwallet.go | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/multiwallet.go b/multiwallet.go index d5c09aae..2d9b8f69 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -112,6 +112,7 @@ 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") @@ -139,12 +140,12 @@ func (mw *MultiWallet) Shutdown() { } } -//SetStartupPassPhrase sets the passPhrase of a wallet. +// SetStartupPassPhrase sets the passPhrase of a wallet. func (mw *MultiWallet) SetStartupPassphrase(passphrase []byte, passphraseType int32) error { return mw.ChangeStartupPassphrase([]byte(""), passphrase, passphraseType) } -//VerifyStartupPassphrase checks for and verifies the passPhrase of a wallet +// VerifyStartupPassphrase checks for and verifies the passPhrase of a wallet // and returns an error respectively. func (mw *MultiWallet) VerifyStartupPassphrase(startupPassphrase []byte) error { var startupPassphraseHash []byte @@ -170,7 +171,7 @@ func (mw *MultiWallet) VerifyStartupPassphrase(startupPassphrase []byte) error { return nil } -//ChangeStartupPassPhrase verifies the current passPhrase +// ChangeStartupPassPhrase verifies the current passPhrase // and generates and sets a new one. func (mw *MultiWallet) ChangeStartupPassphrase(oldPassphrase, newPassphrase []byte, passphraseType int32) error { if len(newPassphrase) == 0 { @@ -198,7 +199,7 @@ func (mw *MultiWallet) ChangeStartupPassphrase(oldPassphrase, newPassphrase []by return nil } -//RemoveStartupPassphrase verifies the current passPhrase and deletes it. +// RemoveStartupPassphrase verifies the current passPhrase and deletes it. func (mw *MultiWallet) RemoveStartupPassphrase(oldPassphrase []byte) error { err := mw.VerifyStartupPassphrase(oldPassphrase) if err != nil { @@ -216,17 +217,17 @@ func (mw *MultiWallet) RemoveStartupPassphrase(oldPassphrase []byte) error { return nil } -//IsStartupSecuritySet returns whether ot not the startup security is set. +// IsStartupSecuritySet returns whether ot not the startup security is set. func (mw *MultiWallet) IsStartupSecuritySet() bool { return mw.ReadBoolConfigValueForKey(IsStartupSecuritySetConfigKey, false) } -//StartupSecurityType returns the type of security used for the startup passPhrase +// StartupSecurityType returns the type of security used for the startup passPhrase func (mw *MultiWallet) StartupSecurityType() int32 { return mw.ReadInt32ConfigValueForKey(StartupSecurityTypeConfigKey, PassphraseTypePass) } -//OpenWallets checks whether or not the wallets is syncing, +// OpenWallets checks whether or not the wallets is syncing, // verifies the passPhrase and opens the wallet func (mw *MultiWallet) OpenWallets(startupPassphrase []byte) error { if mw.IsSyncing() { @@ -250,7 +251,7 @@ func (mw *MultiWallet) OpenWallets(startupPassphrase []byte) error { return nil } -//CreateWatchOnlyWallet creates a watch-only wallet, +// CreateWatchOnlyWallet creates a watch-only wallet, // without neither a wallet seed nor a private keys. func (mw *MultiWallet) CreateWatchOnlyWallet(walletName, extendedPublicKey string) (*Wallet, error) { wallet := &Wallet{ @@ -268,7 +269,7 @@ func (mw *MultiWallet) CreateWatchOnlyWallet(walletName, extendedPublicKey strin }) } -//CreateNewWallet creates a new wallet with +// CreateNewWallet creates a new wallet with // wallet seed as well as private PassPhrase func (mw *MultiWallet) CreateNewWallet(privatePassphrase string, privatePassphraseType int32) (*Wallet, error) { seed, err := GenerateSeed() @@ -292,7 +293,7 @@ func (mw *MultiWallet) CreateNewWallet(privatePassphrase string, privatePassphra }) } -//RestoreWallet uses a wallet seed, private passPhrase +// RestoreWallet uses a wallet seed, private passPhrase // to restore a previously existing wallet. func (mw *MultiWallet) RestoreWallet(seedMnemonic, privatePassphrase string, privatePassphraseType int32) (*Wallet, error) { wallet := &Wallet{ @@ -441,7 +442,7 @@ func (mw *MultiWallet) saveNewWallet(wallet *Wallet, setupWallet func() error) ( return wallet, nil } -//RenameWallet checks the newName if it contains an existing name +// RenameWallet checks the newName if it contains an existing name // and returns an updated walletName for the wallet. func (mw *MultiWallet) RenameWallet(walletID int, newName string) error { if strings.HasPrefix(newName, "wallet-") { @@ -463,7 +464,7 @@ func (mw *MultiWallet) RenameWallet(walletID int, newName string) error { return mw.db.Save(wallet) // update WalletName field } -//DeleteWallet checks whether or not wallet is syncing, then deletes teh wallet with its accompanying Id +// DeleteWallet checks whether or not wallet is syncing, then deletes the wallet with its accompanying Id func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { if mw.IsSyncing() { return errors.New(ErrSyncAlreadyInProgress) @@ -489,7 +490,7 @@ func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { return nil } -//WalletWithID returns wallet with an Id for easy selection +// WalletWithID returns wallet with an Id for easy selection func (mw *MultiWallet) WalletWithID(walletID int) *Wallet { if wallet, ok := mw.wallets[walletID]; ok { return wallet @@ -497,7 +498,7 @@ func (mw *MultiWallet) WalletWithID(walletID int) *Wallet { return nil } -//VerifySeedForWallet checks if a certain wallets' seed is a match. +// VerifySeedForWallet checks if a certain wallets' seed is a match. func (mw *MultiWallet) VerifySeedForWallet(walletID int, seedMnemonic string) error { wallet := mw.WalletWithID(walletID) if wallet == nil { @@ -512,7 +513,7 @@ func (mw *MultiWallet) VerifySeedForWallet(walletID int, seedMnemonic string) er return errors.New(ErrInvalid) } -//NumWalletsNeedingSeedBackup iterates over the available +// NumWalletsNeedingSeedBackup iterates over the available // wallets and checks and returns a list of any needing backups. func (mw *MultiWallet) NumWalletsNeedingSeedBackup() int32 { var backupsNeeded int32 @@ -525,12 +526,12 @@ func (mw *MultiWallet) NumWalletsNeedingSeedBackup() int32 { return backupsNeeded } -//LoadedWalletsCount returns the number of loaded wallets +// LoadedWalletsCount returns the number of loaded wallets func (mw *MultiWallet) LoadedWalletsCount() int32 { return int32(len(mw.wallets)) } -//OpenedWalletIDsRaw returns an array of int of walletIDs of wallets opened +// OpenedWalletIDsRaw returns an array of int of walletIDs of wallets opened func (mw *MultiWallet) OpenedWalletIDsRaw() []int { walletIDs := make([]int, 0) for _, wallet := range mw.wallets { @@ -541,19 +542,19 @@ func (mw *MultiWallet) OpenedWalletIDsRaw() []int { return walletIDs } -//OpenedWalletIDs returns a json.marshal of opened walletIDs +// OpenedWalletIDs returns a json.marshal of opened walletIDs func (mw *MultiWallet) OpenedWalletIDs() string { walletIDs := mw.OpenedWalletIDsRaw() jsonEncoded, _ := json.Marshal(&walletIDs) return string(jsonEncoded) } -//OpenedWalletsCount returns teh number of opened wallets +// OpenedWalletsCount returns the number of opened wallets func (mw *MultiWallet) OpenedWalletsCount() int32 { return int32(len(mw.OpenedWalletIDsRaw())) } -//SyncedWalletsCount returns an int of synced wallets +// SyncedWalletsCount returns an int of synced wallets func (mw *MultiWallet) SyncedWalletsCount() int32 { var syncedWallets int32 for _, wallet := range mw.wallets { @@ -565,7 +566,7 @@ func (mw *MultiWallet) SyncedWalletsCount() int32 { return syncedWallets } -//WalletNameExists returns whether or not a chosen walletName exists +// WalletNameExists returns whether or not a chosen walletName exists func (mw *MultiWallet) WalletNameExists(walletName string) (bool, error) { if strings.HasPrefix(walletName, "wallet-") { return false, errors.E(ErrReservedWalletName) @@ -581,7 +582,7 @@ func (mw *MultiWallet) WalletNameExists(walletName string) (bool, error) { return false, nil } -//UnlockWallet unlocks a wallet using the said wallets ID and privatePassPhrase +// UnlockWallet unlocks a wallet using the said wallets ID and privatePassPhrase func (mw *MultiWallet) UnlockWallet(walletID int, privPass []byte) error { wallet := mw.WalletWithID(walletID) if wallet == nil { @@ -591,7 +592,7 @@ func (mw *MultiWallet) UnlockWallet(walletID int, privPass []byte) error { return wallet.UnlockWallet(privPass) } -//ChangePrivatePassphraseForWallet changes the passPhrase for a wallet from old to new. +// 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) From b9af1423ad600efc5fb90a9e736c4e5e88f680d2 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 10 Mar 2020 13:07:06 +0100 Subject: [PATCH 13/41] documentation for helper.go --- addresshelper/helper.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addresshelper/helper.go b/addresshelper/helper.go index cd401e4a..ca740863 100644 --- a/addresshelper/helper.go +++ b/addresshelper/helper.go @@ -10,6 +10,10 @@ import ( const scriptVersion = 0 + +// PkScript decodes the string encoding of an address +// and returns an error if process failed and a new +// script for pay transaction output. func PkScript(address string, net dcrutil.AddressParams) ([]byte, error) { addr, err := dcrutil.DecodeAddress(address, net) if err != nil { @@ -19,6 +23,8 @@ func PkScript(address string, net dcrutil.AddressParams) ([]byte, error) { return txscript.PayToAddrScript(addr) } +// PkScriptAddresses returns the type of +// script and associated addresses. func PkScriptAddresses(params *chaincfg.Params, pkScript []byte) ([]string, error) { _, addresses, _, err := txscript.ExtractPkScriptAddrs(scriptVersion, pkScript, params) if err != nil { From 9ce932eb36fca49203c1ff73d065bcfa9aa29ea9 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 10 Mar 2020 14:15:39 +0100 Subject: [PATCH 14/41] documentation for db.go --- badgerdb/db.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/badgerdb/db.go b/badgerdb/db.go index f3a9ea14..2a30a83b 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 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) } From 9056562c9c7a52580003961f9a514d00684adef4 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 10 Mar 2020 15:18:18 +0100 Subject: [PATCH 15/41] documentation for save.go --- txindex/save.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/txindex/save.go b/txindex/save.go index 4de6e22f..0a5c608f 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 last index +// of of block height height achieved. func (db *DB) SaveLastIndexPoint(endBlockHeight int32) error { err := db.txDB.Set(TxBucketName, KeyEndBlock, &endBlockHeight) if err != nil { @@ -41,6 +43,8 @@ func (db *DB) SaveLastIndexPoint(endBlockHeight int32) error { return nil } +// ClearSavedTransactions deletes a bucket +// saved on the transaction database. func (db *DB) ClearSavedTransactions(emptyTxPointer interface{}) error { err := db.txDB.Drop(emptyTxPointer) if err != nil { From 15cca520ae34994506805fe8c1a72a0599170fce Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 11 Mar 2020 11:47:55 +0100 Subject: [PATCH 16/41] modifications to accounts, address, message and multiWallet_config --- accounts.go | 36 +++++++++++++++++++++--------------- address.go | 20 +++++++++++--------- message.go | 4 ++-- multiwallet_config.go | 30 +++++++++++++++--------------- 4 files changed, 49 insertions(+), 41 deletions(-) diff --git a/accounts.go b/accounts.go index 5b7eb7fd..9e9110e0 100644 --- a/accounts.go +++ b/accounts.go @@ -9,7 +9,8 @@ import ( "github.com/decred/dcrwallet/errors/v2" ) -//GetAccounts returns a json.Marshal of an account information in a wallet. +// GetAccounts returns a json.Marshal of an +// account information in a wallet. func (wallet *Wallet) GetAccounts(requiredConfirmations int32) (string, error) { accountsResponse, err := wallet.GetAccountsRaw(requiredConfirmations) if err != nil { @@ -20,7 +21,7 @@ func (wallet *Wallet) GetAccounts(requiredConfirmations int32) (string, error) { return string(result), nil } -//GetAccountsRaw returns all the information about an existing account +//GetAccountsRaw returns all the information about an existing account. func (wallet *Wallet) GetAccountsRaw(requiredConfirmations int32) (*Accounts, error) { resp, err := wallet.internal.Accounts(wallet.shutdownContext()) if err != nil { @@ -66,8 +67,8 @@ func (wallet *Wallet) AccountsIterator(requiredConfirmations int32) (*AccountsIt }, nil } -//Iterates over the available accounts in the wallet and -// returns the account within the length of the available accounts +// Iterates over the available accounts in the wallet and +// returns the account within the length of the available accounts. func (accountsInterator *AccountsIterator) Next() *Account { if accountsInterator.currentIndex < len(accountsInterator.accounts) { account := accountsInterator.accounts[accountsInterator.currentIndex] @@ -78,13 +79,13 @@ func (accountsInterator *AccountsIterator) Next() *Account { return nil } -//Sets the account index to default: 0 +// Sets the account index to default: 0 func (accountsInterator *AccountsIterator) Reset() { accountsInterator.currentIndex = 0 } -//GetAccount fetches an account and all the accompanying information -// and properties of the said account. +// GetAccount fetches an account and all the accompanying +// information and properties of the said account. func (wallet *Wallet) GetAccount(accountNumber int32, requiredConfirmations int32) (*Account, error) { props, err := wallet.internal.AccountProperties(wallet.shutdownContext(), uint32(accountNumber)) if err != nil { @@ -110,8 +111,9 @@ func (wallet *Wallet) GetAccount(accountNumber int32, requiredConfirmations int3 return account, nil } -//GetAccountBalance sums up the amount of all unspent transaction output in given -//account of a wallet and returns the available balance. +// GetAccountBalance sums up the amount of all unspent +// transaction output in given account of a wallet and +// returns the available balance. func (wallet *Wallet) GetAccountBalance(accountNumber int32, requiredConfirmations int32) (*Balance, error) { balance, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(accountNumber), requiredConfirmations) if err != nil { @@ -129,8 +131,9 @@ func (wallet *Wallet) GetAccountBalance(accountNumber int32, requiredConfirmatio }, nil } -//SpendableForAccount sums up the amount of all unspent transaction output -//in a given account of a wallet and returns the spendable amount. +// SpendableForAccount sums up the amount of all +// unspent transaction output in a given account +// of a wallet and returns the spendable amount. func (wallet *Wallet) SpendableForAccount(account int32, requiredConfirmations int32) (int64, error) { bals, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(account), requiredConfirmations) if err != nil { @@ -140,6 +143,9 @@ func (wallet *Wallet) SpendableForAccount(account int32, requiredConfirmations i return int64(bals.Spendable), nil } +// NextAccount creates a new account an returns +// the account number with an account name unique +// to the account number. func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, error) { lock := make(chan time.Time, 1) defer func() { @@ -161,7 +167,7 @@ func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, e return int32(accountNumber), err } -//Sets the name of an account to a newName +// Sets the name of an account to a newName. func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error { err := wallet.internal.RenameAccount(wallet.shutdownContext(), uint32(accountNumber), newName) if err != nil { @@ -171,7 +177,7 @@ func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error { return nil } -//Checks for an account and logs error if wallet is empty +// Checks for an account and logs error if wallet is empty func (wallet *Wallet) AccountName(accountNumber int32) string { name, err := wallet.AccountNameRaw(uint32(accountNumber)) if err != nil { @@ -181,12 +187,12 @@ func (wallet *Wallet) AccountName(accountNumber int32) string { return name } -//Returns the account name for the corresponding account number. +// Returns the account name for the corresponding account number. func (wallet *Wallet) AccountNameRaw(accountNumber uint32) (string, error) { return wallet.internal.AccountName(wallet.shutdownContext(), accountNumber) } -//Returns an account number for the corresponding account name. +// Returns an account number for the corresponding account name. func (wallet *Wallet) AccountNumber(accountName string) (uint32, error) { return wallet.internal.AccountNumber(wallet.shutdownContext(), accountName) } diff --git a/address.go b/address.go index 363c5d5c..5217293c 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 @@ -20,13 +22,13 @@ type AddressInfo struct { } // IsAddressValid decodes the string coding of an address and -// returns whether the network param is valid or not +// returns whether the network param is valid. func (wallet *Wallet) IsAddressValid(address string) bool { _, err := dcrutil.DecodeAddress(address, wallet.chainParams) return err == nil } -//HaveAddress returns whether or not wallet is the owner of the address. +// 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 { @@ -41,7 +43,7 @@ func (wallet *Wallet) HaveAddress(address string) bool { return have } -//AccountOfAddress returns a detailed information of an +// AccountOfAddress returns a detailed information of an // account belonging to a wallet address. func (wallet *Wallet) AccountOfAddress(address string) string { addr, err := dcrutil.DecodeAddress(address, wallet.chainParams) @@ -53,8 +55,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. +// 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 { @@ -76,7 +78,7 @@ func (wallet *Wallet) AddressInfo(address string) (*AddressInfo, error) { return addressInfo, nil } -//CurrentAddress returns the string encoding of the +// CurrentAddress returns the string encoding of the // most recent payment address. func (wallet *Wallet) CurrentAddress(account int32) (string, error) { if wallet.IsRestored && !wallet.HasDiscoveredAccounts { @@ -91,7 +93,7 @@ func (wallet *Wallet) CurrentAddress(account int32) (string, error) { return addr.Address(), nil } -//NextAddress returns the string encoding an external address. +// NextAddress returns the string encoding an external address. func (wallet *Wallet) NextAddress(account int32) (string, error) { if wallet.IsRestored && !wallet.HasDiscoveredAccounts { return "", errors.E(ErrAddressDiscoveryNotDone) @@ -105,7 +107,7 @@ func (wallet *Wallet) NextAddress(account int32) (string, error) { return addr.Address(), nil } -//AddressPubKey returns the public key of an address in wallet. +// AddressPubKey returns the public key of an address in wallet. func (wallet *Wallet) AddressPubKey(address string) (string, error) { addr, err := dcrutil.DecodeAddress(address, wallet.chainParams) if err != nil { diff --git a/message.go b/message.go index 65397a05..0627ece1 100644 --- a/message.go +++ b/message.go @@ -9,7 +9,7 @@ import ( w "github.com/decred/dcrwallet/wallet/v3" ) -//SignMessage returns a signature of a signed message +// SignMessage returns a signature of a signed message. func (wallet *Wallet) SignMessage(passphrase []byte, address string, message string) ([]byte, error) { lock := make(chan time.Time, 1) defer func() { @@ -46,7 +46,7 @@ func (wallet *Wallet) SignMessage(passphrase []byte, address string, message str return sig, nil } -//VerifyMessage returns whether or not the signature of a signed message is valid +// VerifyMessage returns whether or not the signature of a signed message is valid. func (wallet *Wallet) VerifyMessage(address string, message string, signatureBase64 string) (bool, error) { var valid bool diff --git a/multiwallet_config.go b/multiwallet_config.go index 5739ce8c..52ffae7c 100644 --- a/multiwallet_config.go +++ b/multiwallet_config.go @@ -57,7 +57,7 @@ func (mw *MultiWallet) SaveUserConfigValue(key string, value interface{}) { } } -//ReadUserConfigValue retrieves the raw value for config key +// 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,7 +66,7 @@ func (mw *MultiWallet) ReadUserConfigValue(key string, valueOut interface{}) err return err } -//DeleteUserConfigValueForKey deletes a key from the bucket +// DeleteUserConfigValueForKey deletes a key from the bucket. func (mw *MultiWallet) DeleteUserConfigValueForKey(key string) { err := mw.db.Delete(userConfigBucketName, key) if err != nil { @@ -74,7 +74,7 @@ func (mw *MultiWallet) DeleteUserConfigValueForKey(key string) { } } -//ClearConfig drops a config bucket name +// ClearConfig drops a config bucket name. func (mw *MultiWallet) ClearConfig() { err := mw.db.Drop(userConfigBucketName) if err != nil { @@ -82,37 +82,37 @@ func (mw *MultiWallet) ClearConfig() { } } -//SetBoolConfigValueForKey sets bool config value for key +// 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 +// 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 +// 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 +// 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 +// 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 +// 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 +// 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 @@ -120,7 +120,7 @@ func (mw *MultiWallet) ReadBoolConfigValueForKey(key string, defaultValue bool) return } -//ReadDoubleConfigValueForKey reads the float64 config value for key +// 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 @@ -128,7 +128,7 @@ func (mw *MultiWallet) ReadDoubleConfigValueForKey(key string, defaultValue floa return } -//ReadIntConfigValueForKey reads the int config value for key +// 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 @@ -136,7 +136,7 @@ func (mw *MultiWallet) ReadIntConfigValueForKey(key string, defaultValue int) (v return } -//ReadInt32ConfigValueForKey reads the int32 config value for key +// 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 @@ -144,7 +144,7 @@ func (mw *MultiWallet) ReadInt32ConfigValueForKey(key string, defaultValue int32 return } -//ReadLongConfigValueForKey reads the int64 config value for key +// 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 @@ -152,7 +152,7 @@ func (mw *MultiWallet) ReadLongConfigValueForKey(key string, defaultValue int64) return } -//ReadStringConfigValueForKey reads the string config value for key +// ReadStringConfigValueForKey reads the string config value for key. func (mw *MultiWallet) ReadStringConfigValueForKey(key string) (valueOut string) { mw.ReadUserConfigValue(key, &valueOut) return From 45dad17000dad994e23be430fe0f22d1818bbe04 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 11 Mar 2020 11:56:58 +0100 Subject: [PATCH 17/41] modifications to rescan, sync and ticket --- rescan.go | 13 ++++++++----- sync.go | 47 ++++++++++++++++++++++++----------------------- ticket.go | 7 ++++--- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/rescan.go b/rescan.go index 22c61b9a..ab92b8d5 100644 --- a/rescan.go +++ b/rescan.go @@ -9,8 +9,9 @@ import ( w "github.com/decred/dcrwallet/wallet/v3" ) -//RescanBlocks checks whether or not the blocks are scanned or synced. -//If they are not updated, it scans the the block header until is it manually canceled. +// RescanBlocks checks whether or not the blocks are scanned or synced. +// If they are not updated, it scans the the block +// header until is it manually canceled. func (mw *MultiWallet) RescanBlocks(walletID int) error { wallet := mw.WalletWithID(walletID) @@ -109,7 +110,7 @@ func (mw *MultiWallet) RescanBlocks(walletID int) error { return nil } -//CancelRescan locks the wallet out from syncing +// CancelRescan locks the wallet out from syncing. func (mw *MultiWallet) CancelRescan() { mw.syncData.mu.Lock() defer mw.syncData.mu.Unlock() @@ -121,14 +122,16 @@ func (mw *MultiWallet) CancelRescan() { } } -//IsRescanning bypasses the lock on wallet for syncing to be carried out +// IsRescanning bypasses the lock on wallet for syncing +// to be carried out. func (mw *MultiWallet) IsRescanning() bool { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() return mw.syncData.rescanning } -//SetBlocksRescanProgressListener sets a block for the scan progress listener +// SetBlocksRescanProgressListener sets a block for +// the scan progress listener. func (mw *MultiWallet) SetBlocksRescanProgressListener(blocksRescanProgressListener BlocksRescanProgressListener) { mw.blocksRescanProgressListener = blocksRescanProgressListener } diff --git a/sync.go b/sync.go index 39c11716..9b03fe85 100644 --- a/sync.go +++ b/sync.go @@ -90,7 +90,7 @@ func (mw *MultiWallet) initActiveSyncData() { mw.syncData.mu.Unlock() } -//IsSyncProgressListenerRegisteredFor checks for and returns a value that checks +// IsSyncProgressListenerRegisteredFor checks for and returns a value that checks // whether or not a progress listener was set for the wallet syncing. func (mw *MultiWallet) IsSyncProgressListenerRegisteredFor(uniqueIdentifier string) bool { mw.syncData.mu.RLock() @@ -99,7 +99,7 @@ func (mw *MultiWallet) IsSyncProgressListenerRegisteredFor(uniqueIdentifier stri return exists } -//AddSyncProgressListener checks and sets a new progress listener if there is +// 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) { @@ -114,7 +114,7 @@ func (mw *MultiWallet) AddSyncProgressListener(syncProgressListener SyncProgress return mw.PublishLastSyncProgress(uniqueIdentifier) } -//RemoveSyncProgressListener deletes an existing progress listener for wallet syncing. +// RemoveSyncProgressListener deletes an existing progress listener for wallet syncing. func (mw *MultiWallet) RemoveSyncProgressListener(uniqueIdentifier string) { mw.syncData.mu.Lock() delete(mw.syncData.syncProgressListeners, uniqueIdentifier) @@ -133,7 +133,7 @@ func (mw *MultiWallet) syncProgressListeners() []SyncProgressListener { return listeners } -//PublishLastSyncProgress fetches and publishes sync and scan data +// PublishLastSyncProgress fetches and publishes sync and scan data. func (mw *MultiWallet) PublishLastSyncProgress(uniqueIdentifier string) error { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -157,14 +157,14 @@ func (mw *MultiWallet) PublishLastSyncProgress(uniqueIdentifier string) error { return nil } -//EnableSyncLogs enables logging of scan logs +// EnableSyncLogs enables logging of scan logs. func (mw *MultiWallet) EnableSyncLogs() { mw.syncData.mu.Lock() mw.syncData.showLogs = true mw.syncData.mu.Unlock() } -//SyncInactiveForPeriod accounts for inactive sync period +// SyncInactiveForPeriod accounts for inactive sync period. func (mw *MultiWallet) SyncInactiveForPeriod(totalInactiveSeconds int64) { mw.syncData.mu.Lock() defer mw.syncData.mu.Unlock() @@ -181,7 +181,7 @@ func (mw *MultiWallet) SyncInactiveForPeriod(totalInactiveSeconds int64) { } } -//SpvSync sets a wallet syncing for spv peer to peer connections +// SpvSync sets a wallet syncing for 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() { @@ -267,7 +267,7 @@ func (mw *MultiWallet) SpvSync() error { return nil } -//RestartSpvSync sends a request to restart SpvSync +// RestartSpvSync sends a request to restart SpvSync. func (mw *MultiWallet) RestartSpvSync() error { mw.syncData.mu.Lock() mw.syncData.restartSyncRequested = true @@ -277,7 +277,7 @@ func (mw *MultiWallet) RestartSpvSync() error { return mw.SpvSync() } -//CancelSync cancels/stops any active wallet syncing +// CancelSync cancels/stops any active wallet syncing. func (mw *MultiWallet) CancelSync() { mw.syncData.mu.RLock() cancelSync := mw.syncData.cancelSync @@ -308,22 +308,23 @@ func (mw *MultiWallet) CancelSync() { } } -//IsWaiting returns whether or not a wallet is waiting to be synced +// IsWaiting returns whether or not a wallet is +// waiting to be synced. func (wallet *Wallet) IsWaiting() bool { return wallet.waiting } -//IsSynced returns whether or not a wallet has been synced +// IsSynced returns whether or not a wallet has been synced. func (wallet *Wallet) IsSynced() bool { return wallet.synced } -//IsSyncing returns whether or not a wallet is undergoing syncing +// IsSyncing returns whether or not a wallet is undergoing syncing. func (wallet *Wallet) IsSyncing() bool { return wallet.syncing } -//IsSynced returns the state of a wallet +// IsSynced returns the state of a wallet // being synced if it has been synced func (mw *MultiWallet) IsSynced() bool { mw.syncData.mu.RLock() @@ -331,15 +332,15 @@ func (mw *MultiWallet) IsSynced() bool { return mw.syncData.synced } -//IsSyncing returns the state of a wallet undergoing syncing, -//if it is syncing +// IsSyncing returns the state of a wallet undergoing syncing, +// if it is 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 wallet +// CurrentSyncStage returns the sync stage of the wallet. func (mw *MultiWallet) CurrentSyncStage() int32 { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -350,7 +351,7 @@ func (mw *MultiWallet) CurrentSyncStage() int32 { return InvalidSyncStage } -//GeneralSyncProgress returns the total sync progress +// GeneralSyncProgress returns the total sync progress. func (mw *MultiWallet) GeneralSyncProgress() *GeneralSyncProgress { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -369,14 +370,14 @@ func (mw *MultiWallet) GeneralSyncProgress() *GeneralSyncProgress { return nil } -//ConnectedPeers returns the number of connected peers via spv +// 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 the best block height of a loaded wallet +// GetBestBlock retrieves the best block height of a loaded wallet. func (mw *MultiWallet) GetBestBlock() *BlockInfo { var bestBlock int32 = -1 var blockInfo *BlockInfo @@ -395,7 +396,7 @@ func (mw *MultiWallet) GetBestBlock() *BlockInfo { return blockInfo } -//GetLowestBlock gets the lowest block height of a loaded wallet +// GetLowestBlock retrieves the lowest block height of a loaded wallet. func (mw *MultiWallet) GetLowestBlock() *BlockInfo { var lowestBlock int32 = -1 var blockInfo *BlockInfo @@ -413,7 +414,7 @@ func (mw *MultiWallet) GetLowestBlock() *BlockInfo { return blockInfo } -//GetBestBlock gets the best block height that the wallet is synced to +// 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. @@ -425,7 +426,7 @@ func (wallet *Wallet) GetBestBlock() int32 { return height } -//GetBestBlockTimeStamp gets the best Timestamp of a block header event +// GetBestBlockTimeStamp retrieves the best Timestamp of a block header event. func (wallet *Wallet) GetBestBlockTimeStamp() int64 { if wallet.internal == nil { // This method is sometimes called after a wallet is deleted and causes crash. @@ -444,7 +445,7 @@ func (wallet *Wallet) GetBestBlockTimeStamp() int64 { return info.Timestamp } -//GetLowestBlockTimestamp gets the lowest Timestamp of a block header event +// GetLowestBlockTimestamp gets the lowest Timestamp of a block header event. func (mw *MultiWallet) GetLowestBlockTimestamp() int64 { var timestamp int64 = -1 for _, wallet := range mw.wallets { diff --git a/ticket.go b/ticket.go index 08d1cac4..fdef392c 100644 --- a/ticket.go +++ b/ticket.go @@ -36,7 +36,7 @@ func (wallet *Wallet) StakeInfo() (*w.StakeInfoData, error) { return wallet.internal.StakeInfo(ctx) } -//GetTickets returns information about ticket request +// GetTickets returns information about ticket request. func (wallet *Wallet) GetTickets(startingBlockHash, endingBlockHash []byte, targetCount int32) ([]*TicketInfo, error) { return wallet.getTickets(&GetTicketsRequest{ StartingBlockHash: startingBlockHash, @@ -45,7 +45,7 @@ func (wallet *Wallet) GetTickets(startingBlockHash, endingBlockHash []byte, targ }) } -//GetTicketsForBlockHeightRange returns information about +// GetTicketsForBlockHeightRange returns information about // ticket request used for block height range. func (wallet *Wallet) GetTicketsForBlockHeightRange(startHeight, endHeight, targetCount int32) ([]*TicketInfo, error) { return wallet.getTickets(&GetTicketsRequest{ @@ -179,7 +179,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 from 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 From 36d01e4dbd1ebecbd46eda451a91967940a47066 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 11 Mar 2020 12:00:15 +0100 Subject: [PATCH 18/41] modifications to transaction and txandblocknotifcations --- transactions.go | 20 +++++++++++--------- txandblocknotifications.go | 8 ++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/transactions.go b/transactions.go index 372edef9..d578fc10 100644 --- a/transactions.go +++ b/transactions.go @@ -32,7 +32,8 @@ const ( TxTypeRevocation = txhelper.TxTypeRevocation ) -//GetTransaction returns the JSON encoding of transactions in a wallet +// GetTransaction returns the JSON encoded string of +// transactions in a wallet. func (wallet *Wallet) GetTransaction(txHash []byte) (string, error) { transaction, err := wallet.GetTransactionRaw(txHash) if err != nil { @@ -48,7 +49,7 @@ func (wallet *Wallet) GetTransaction(txHash []byte) (string, error) { return string(result), nil } -//GetTransactionRaw returns the details of transaction related to the wallet +// GetTransactionRaw returns the details of transaction related to the wallet. func (wallet *Wallet) GetTransactionRaw(txHash []byte) (*Transaction, error) { hash, err := chainhash.NewHash(txHash) if err != nil { @@ -65,8 +66,8 @@ func (wallet *Wallet) GetTransactionRaw(txHash []byte) (*Transaction, error) { return wallet.decodeTransactionWithTxSummary(txSummary, blockHash) } -//GetTransactions returns the JSON encoding of all transactions -// in a wallet starting from the most recent +// GetTransactions returns the JSON encoding of all transactions +// in a wallet starting from the most recent. func (wallet *Wallet) GetTransactions(offset, limit, txFilter int32, newestFirst bool) (string, error) { transactions, err := wallet.GetTransactionsRaw(offset, limit, txFilter, newestFirst) if err != nil { @@ -81,14 +82,15 @@ func (wallet *Wallet) GetTransactions(offset, limit, txFilter int32, newestFirst return string(jsonEncodedTransactions), nil } -//GetTransactionsRaw returns the details of transactions related to the wallet +// GetTransactionsRaw returns the details of transactions related to the wallet. 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 -// in several wallets starting from the newest wallet created +// GetTransactions returns the JSON encoded strings +// of all transactions in several wallets starting +// from the newest wallet created. func (mw *MultiWallet) GetTransactions(offset, limit, txFilter int32, newestFirst bool) (string, error) { transactions := make([]Transaction, 0) for _, wallet := range mw.wallets { @@ -120,8 +122,8 @@ func (mw *MultiWallet) GetTransactions(offset, limit, txFilter int32, newestFirs return string(jsonEncodedTransactions), nil } -//CountTransactions returns number of recorded transactions that -// occurred within a wallet at a given period of time +// CountTransactions returns number of recorded transactions that +// occurred within a wallet at a given period of time. func (wallet *Wallet) CountTransactions(txFilter int32) (int, error) { return wallet.txDB.Count(txFilter, &Transaction{}) } diff --git a/txandblocknotifications.go b/txandblocknotifications.go index b6b9440a..24fab038 100644 --- a/txandblocknotifications.go +++ b/txandblocknotifications.go @@ -61,8 +61,8 @@ func (mw *MultiWallet) listenForTransactions(walletID int) { } } -//AddTxAndBlockNotificationListener adds a notification listener -// for transaction and certain block height on wallet +// AddTxAndBlockNotificationListener adds a notification listener +// for transaction and certain block height on wallet. func (mw *MultiWallet) AddTxAndBlockNotificationListener(txAndBlockNotificationListener TxAndBlockNotificationListener, uniqueIdentifier string) error { _, ok := mw.txAndBlockNotificationListeners[uniqueIdentifier] if ok { @@ -74,8 +74,8 @@ func (mw *MultiWallet) AddTxAndBlockNotificationListener(txAndBlockNotificationL return nil } -//RemoveTxAndBlockNotificationListener deletes the notification -// listener set for transaction and block height in a wallet +// RemoveTxAndBlockNotificationListener deletes the notification +// listener set for transaction and block height in a wallet. func (mw *MultiWallet) RemoveTxAndBlockNotificationListener(uniqueIdentifier string) { delete(mw.txAndBlockNotificationListeners, uniqueIdentifier) } From 32d7c562ff97878dc22d576535d5368dff7cb2f0 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 11 Mar 2020 12:03:29 +0100 Subject: [PATCH 19/41] modifications to txauthor, txindex, utils, wallet --- txauthor.go | 2 +- txindex.go | 4 ++-- utils.go | 2 +- wallet.go | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/txauthor.go b/txauthor.go index f18476ed..5fd4a9aa 100644 --- a/txauthor.go +++ b/txauthor.go @@ -102,7 +102,7 @@ func (tx *TxAuthor) EstimateMaxSendAmount() (*Amount, error) { }, nil } -//Broadcast allows for pasting of raw transactions conducted in a wallet +// Broadcast allows for pasting of raw transactions conducted in a wallet. func (tx *TxAuthor) Broadcast(privatePassphrase []byte) ([]byte, error) { defer func() { for i := range privatePassphrase { diff --git a/txindex.go b/txindex.go index 50af8617..d340ffd8 100644 --- a/txindex.go +++ b/txindex.go @@ -6,8 +6,8 @@ import ( "github.com/raedahgroup/dcrlibwallet/txindex" ) -//IndexTransactions returns an index of all transactions -// from start to end of a full block height +// IndexTransactions returns an index of all transactions +// from start to end of a full block height. func (wallet *Wallet) IndexTransactions() error { ctx := wallet.shutdownContext() diff --git a/utils.go b/utils.go index c5d29de4..e4ffac44 100644 --- a/utils.go +++ b/utils.go @@ -71,7 +71,7 @@ func (mw *MultiWallet) contextWithShutdownCancel() (context.Context, context.Can return ctx, cancel } -//ValidateExtPubKey provides an instance of key extension required by the network type +// ValidateExtPubKey provides an instance of key extension required by the network type. 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 d2a9ab9c..7c126168 100644 --- a/wallet.go +++ b/wallet.go @@ -110,12 +110,12 @@ func (wallet *Wallet) Shutdown() { } } -//NetType returns a human-readable identifier for a Network +// NetType returns a human-readable identifier for a Network. func (wallet *Wallet) NetType() string { return wallet.chainParams.Name } -//WalletExists returns whether or not a wallet exists at the loaders' db path +// WalletExists returns whether or not a wallet exists at the loaders' db path. func (wallet *Wallet) WalletExists() (bool, error) { return wallet.loader.WalletExists() } @@ -161,7 +161,7 @@ func (wallet *Wallet) createWatchingOnlyWallet(extendedPublicKey string) error { return nil } -//IsWatchingOnlyWallet returns whether or not a wallet is in watching only mode +// IsWatchingOnlyWallet returns whether or not a wallet is in watching only mode. func (wallet *Wallet) IsWatchingOnlyWallet() bool { if w, ok := wallet.loader.LoadedWallet(); ok { return w.Manager.WatchingOnly() @@ -188,7 +188,7 @@ func (wallet *Wallet) WalletOpened() bool { return wallet.internal != nil } -//UnlockWallet unlocks the wallet allowing access to private keys +// UnlockWallet unlocks the wallet allowing access to private keys. func (wallet *Wallet) UnlockWallet(privPass []byte) error { loadedWallet, ok := wallet.loader.LoadedWallet() if !ok { @@ -210,14 +210,14 @@ func (wallet *Wallet) UnlockWallet(privPass []byte) error { return nil } -//LockWallet locks the wallet's address manager +// LockWallet locks the wallet's address manager. func (wallet *Wallet) LockWallet() { if !wallet.internal.Locked() { wallet.internal.Lock() } } -//IsLocked returns whether a wallet is locked +// IsLocked returns whether a wallet is locked. func (wallet *Wallet) IsLocked() bool { return wallet.internal.Locked() } From 4819e92fe8dd379dd381b04dc70af187e2f77bfb Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 11 Mar 2020 12:10:53 +0100 Subject: [PATCH 20/41] modifications to wallet_config and wallets --- wallet_config.go | 52 ++++++++++++++++++++++++------------------------ wallets.go | 12 ++++++----- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/wallet_config.go b/wallet_config.go index a6e4ce83..2075ed35 100644 --- a/wallet_config.go +++ b/wallet_config.go @@ -5,7 +5,7 @@ import ( "github.com/decred/dcrwallet/errors/v2" ) -//SaveUserConfigValue saves the provided key-value pair to a config database +// 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") @@ -18,7 +18,7 @@ func (wallet *Wallet) SaveUserConfigValue(key string, value interface{}) { } } -//ReadUserConfigValue returns the saved key-value pair in a config database +// 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") @@ -32,44 +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 +// 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 +// 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 +// 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 +// 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 +// 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 +// 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 +// 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 @@ -77,8 +77,8 @@ func (wallet *Wallet) ReadBoolConfigValueForKey(key string, defaultValue bool) ( return } -//ReadDoubleConfigValueForKey returns a float64 value -// for key-value pair from a config database +// 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 @@ -86,8 +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 +// 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 @@ -95,8 +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 +// 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 @@ -104,8 +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 +// 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 @@ -113,8 +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 +// 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 240eebc0..8b296d34 100644 --- a/wallets.go +++ b/wallets.go @@ -1,6 +1,6 @@ package dcrlibwallet -//AllWallets returns all the available wallets in a MultiWallet instance +// AllWallets returns all the available wallets in a MultiWallet instance. func (mw *MultiWallet) AllWallets() (wallets []*Wallet) { for _, wallet := range mw.wallets { wallets = append(wallets, wallet) @@ -8,7 +8,8 @@ func (mw *MultiWallet) AllWallets() (wallets []*Wallet) { return wallets } -//WalletsIterator returns all the available wallets and their index in a MultiWallet instance +// WalletsIterator returns all the available wallets and +// their index in a MultiWallet instance. func (mw *MultiWallet) WalletsIterator() *WalletsIterator { return &WalletsIterator{ currentIndex: 0, @@ -16,8 +17,9 @@ func (mw *MultiWallet) WalletsIterator() *WalletsIterator { } } -//Next iterates over the the wallets in a MultiWallet instance and returns a wallet -// that has an index within the length of the available wallets +// Next iterates over the the wallets in a MultiWallet +// instance and returns a wallet that has an index +// within the length of the available wallets. func (walletsIterator *WalletsIterator) Next() *Wallet { if walletsIterator.currentIndex < len(walletsIterator.wallets) { wallet := walletsIterator.wallets[walletsIterator.currentIndex] @@ -28,7 +30,7 @@ func (walletsIterator *WalletsIterator) Next() *Wallet { return nil } -//Reset sets the wallet to display at index 0 +// Reset sets the wallet to display at index 0. func (walletsIterator *WalletsIterator) Reset() { walletsIterator.currentIndex = 0 } From 52de6bd2d2ed8e46b1fdb2fd73d6f7ede56fa7e6 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 25 Mar 2020 17:13:16 +0100 Subject: [PATCH 21/41] go fmt --- addresshelper/helper.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/addresshelper/helper.go b/addresshelper/helper.go index ca740863..0f97ced0 100644 --- a/addresshelper/helper.go +++ b/addresshelper/helper.go @@ -10,10 +10,6 @@ import ( const scriptVersion = 0 - -// PkScript decodes the string encoding of an address -// and returns an error if process failed and a new -// script for pay transaction output. func PkScript(address string, net dcrutil.AddressParams) ([]byte, error) { addr, err := dcrutil.DecodeAddress(address, net) if err != nil { From 38eef3e71008211ad43be9d7129b3ade0704eca0 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 25 Mar 2020 21:41:36 +0100 Subject: [PATCH 22/41] cleanup --- accounts.go | 7 ++++--- badgerdb/db.go | 2 +- multiwallet.go | 3 ++- multiwallet_config.go | 2 +- wallet.go | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/accounts.go b/accounts.go index 9e9110e0..b626a09a 100644 --- a/accounts.go +++ b/accounts.go @@ -21,7 +21,7 @@ func (wallet *Wallet) GetAccounts(requiredConfirmations int32) (string, error) { return string(result), nil } -//GetAccountsRaw returns all the information about an existing account. +// GetAccountsRaw returns all the information about an existing account. func (wallet *Wallet) GetAccountsRaw(requiredConfirmations int32) (*Accounts, error) { resp, err := wallet.internal.Accounts(wallet.shutdownContext()) if err != nil { @@ -54,7 +54,8 @@ func (wallet *Wallet) GetAccountsRaw(requiredConfirmations int32) (*Accounts, er }, nil } -//AccountsIterator gets account information of an +// AccountsIterator gets account information of a wallet and returns +// the account index and the accompanying account information. func (wallet *Wallet) AccountsIterator(requiredConfirmations int32) (*AccountsIterator, error) { accounts, err := wallet.GetAccountsRaw(requiredConfirmations) if err != nil { @@ -197,7 +198,7 @@ func (wallet *Wallet) AccountNumber(accountName string) (uint32, error) { return wallet.internal.AccountNumber(wallet.shutdownContext(), accountName) } -//Checks and identifies the coin network type for the account +// Checks and identifies the coin network type for the account // and returns the path for any of the mainnet, testnet, or legacy. func (wallet *Wallet) HDPathForAccount(accountNumber int32) (string, error) { cointype, err := wallet.internal.CoinType(wallet.shutdownContext()) diff --git a/badgerdb/db.go b/badgerdb/db.go index 2a30a83b..887f4e39 100644 --- a/badgerdb/db.go +++ b/badgerdb/db.go @@ -194,7 +194,7 @@ func (b *Bucket) NestedReadWriteBucket(key []byte) walletdb.ReadWriteBucket { return nestedBucket } -// NestedReadBucket returns a +// NestedReadBucket returns a read and write bucket interface implementation. func (b *Bucket) NestedReadBucket(key []byte) walletdb.ReadBucket { if b.dbTransaction.db.closed { return nil diff --git a/multiwallet.go b/multiwallet.go index 2d9b8f69..2d121169 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -312,7 +312,8 @@ func (mw *MultiWallet) RestoreWallet(seedMnemonic, privatePassphrase string, pri }) } -//LinkExistingWallet links an already existing wallet to a new one +// +// LinkExistingWallet links an already existing wallet to a new one func (mw *MultiWallet) LinkExistingWallet(walletDataDir, originalPubPass string, privatePassphraseType int32) (*Wallet, error) { if mw.IsSyncing() { return nil, errors.New(ErrSyncAlreadyInProgress) diff --git a/multiwallet_config.go b/multiwallet_config.go index 52ffae7c..95dff824 100644 --- a/multiwallet_config.go +++ b/multiwallet_config.go @@ -49,7 +49,7 @@ func (mw *MultiWallet) walletConfigReadFn(walletID int) configReadFn { } } -//SaveUserConfigValue saves config value name for key +// SaveUserConfigValue saves config value name for key func (mw *MultiWallet) SaveUserConfigValue(key string, value interface{}) { err := mw.db.Set(userConfigBucketName, key, value) if err != nil { diff --git a/wallet.go b/wallet.go index 7c126168..23fd8f2b 100644 --- a/wallet.go +++ b/wallet.go @@ -85,7 +85,7 @@ func (wallet *Wallet) prepare(rootDir string, chainParams *chaincfg.Params, return nil } -//Shutdown closes the wallet and transaction db +// 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()`. From 0e6489027b3f7dc93d6c4cca97018475944bb6a2 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Sat, 28 Mar 2020 22:55:29 +0100 Subject: [PATCH 23/41] account correction --- accounts.go | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/accounts.go b/accounts.go index b626a09a..c5a2e0bc 100644 --- a/accounts.go +++ b/accounts.go @@ -54,8 +54,8 @@ func (wallet *Wallet) GetAccountsRaw(requiredConfirmations int32) (*Accounts, er }, nil } -// AccountsIterator gets account information of a wallet and returns -// the account index and the accompanying account information. +// AccountsIterator returns an iterator that can be +// used to loop through the accounts of a wallet. func (wallet *Wallet) AccountsIterator(requiredConfirmations int32) (*AccountsIterator, error) { accounts, err := wallet.GetAccountsRaw(requiredConfirmations) if err != nil { @@ -68,8 +68,8 @@ func (wallet *Wallet) AccountsIterator(requiredConfirmations int32) (*AccountsIt }, nil } -// Iterates over the available accounts in the wallet and -// returns the account within the length of the available accounts. +// 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] @@ -80,7 +80,7 @@ func (accountsInterator *AccountsIterator) Next() *Account { return nil } -// Sets the account index to default: 0 +// Reset sets the current iterator's index to 0. func (accountsInterator *AccountsIterator) Reset() { accountsInterator.currentIndex = 0 } @@ -112,9 +112,8 @@ func (wallet *Wallet) GetAccount(accountNumber int32, requiredConfirmations int3 return account, nil } -// GetAccountBalance sums up the amount of all unspent -// transaction output in given account of a wallet and -// returns the available balance. +// GetAccountBalance returns all the balance +// information in a given account. func (wallet *Wallet) GetAccountBalance(accountNumber int32, requiredConfirmations int32) (*Balance, error) { balance, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(accountNumber), requiredConfirmations) if err != nil { @@ -132,9 +131,8 @@ func (wallet *Wallet) GetAccountBalance(accountNumber int32, requiredConfirmatio }, nil } -// SpendableForAccount sums up the amount of all -// unspent transaction output in a given account -// of a wallet and returns the spendable amount. +// SpendableForAccount returns the spendable +// balance in a given account. func (wallet *Wallet) SpendableForAccount(account int32, requiredConfirmations int32) (int64, error) { bals, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(account), requiredConfirmations) if err != nil { @@ -144,9 +142,8 @@ func (wallet *Wallet) SpendableForAccount(account int32, requiredConfirmations i return int64(bals.Spendable), nil } -// NextAccount creates a new account an returns -// the account number with an account name unique -// to the account number. +// 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() { @@ -168,7 +165,7 @@ func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, e return int32(accountNumber), err } -// Sets the name of an account to a newName. +// 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 { @@ -178,7 +175,7 @@ func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error { return nil } -// Checks for an account and logs error if wallet is empty +// 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 { @@ -188,7 +185,7 @@ func (wallet *Wallet) AccountName(accountNumber int32) string { return name } -// Returns the account name for the corresponding account number. +// AccountNameRaw returns the name for the passed account number. func (wallet *Wallet) AccountNameRaw(accountNumber uint32) (string, error) { return wallet.internal.AccountName(wallet.shutdownContext(), accountNumber) } @@ -198,8 +195,8 @@ func (wallet *Wallet) AccountNumber(accountName string) (uint32, error) { return wallet.internal.AccountNumber(wallet.shutdownContext(), accountName) } -// Checks and identifies the coin network type for the account -// and returns the path for any of the mainnet, testnet, or legacy. +// 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 { From 7f2f9ebec6cb87563bc37883be9152c1728095df Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Sat, 28 Mar 2020 23:08:36 +0100 Subject: [PATCH 24/41] address correction --- address.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/address.go b/address.go index 5217293c..96e6fae8 100644 --- a/address.go +++ b/address.go @@ -21,8 +21,8 @@ type AddressInfo struct { AccountName string } -// IsAddressValid decodes the string coding of an address and -// returns whether the network param is valid. +// 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 @@ -43,8 +43,7 @@ func (wallet *Wallet) HaveAddress(address string) bool { return have } -// AccountOfAddress returns a detailed information of an -// account belonging to a wallet address. +// 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 { @@ -78,8 +77,7 @@ func (wallet *Wallet) AddressInfo(address string) (*AddressInfo, error) { return addressInfo, nil } -// CurrentAddress returns the string encoding of the -// most recent payment address. +// 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) @@ -93,7 +91,8 @@ func (wallet *Wallet) CurrentAddress(account int32) (string, error) { return addr.Address(), nil } -// NextAddress returns the string encoding an external address. +// 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) @@ -107,7 +106,7 @@ func (wallet *Wallet) NextAddress(account int32) (string, error) { return addr.Address(), nil } -// AddressPubKey returns the public key of an address in wallet. +// 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 { From 0731c4c3f516b9e20f6744b344f17d65182db218 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Sat, 28 Mar 2020 23:20:46 +0100 Subject: [PATCH 25/41] helper and message correction --- addresshelper/helper.go | 4 ++-- message.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addresshelper/helper.go b/addresshelper/helper.go index 0f97ced0..ce30e023 100644 --- a/addresshelper/helper.go +++ b/addresshelper/helper.go @@ -19,8 +19,8 @@ func PkScript(address string, net dcrutil.AddressParams) ([]byte, error) { return txscript.PayToAddrScript(addr) } -// PkScriptAddresses returns the type of -// script and associated addresses. +// 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/message.go b/message.go index 0627ece1..2937ee3c 100644 --- a/message.go +++ b/message.go @@ -9,7 +9,8 @@ import ( w "github.com/decred/dcrwallet/wallet/v3" ) -// SignMessage returns a signature of a signed message. +// 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() { @@ -46,7 +47,7 @@ func (wallet *Wallet) SignMessage(passphrase []byte, address string, message str return sig, nil } -// VerifyMessage returns whether or not the signature of a signed message is valid. +// VerifyMessage verifies that signatureBase64 is a valid signature. func (wallet *Wallet) VerifyMessage(address string, message string, signatureBase64 string) (bool, error) { var valid bool From 472b0d471acb6c3bafc99cbe94f617908a2b697f Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Sun, 29 Mar 2020 01:20:26 +0100 Subject: [PATCH 26/41] multiwallet correction --- multiwallet.go | 65 ++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/multiwallet.go b/multiwallet.go index 2d121169..7a2a1801 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -112,7 +112,8 @@ func NewMultiWallet(rootDir, dbDriver, netType string) (*MultiWallet, error) { return mw, nil } -// Shutdown closes all opened wallets and database in MultiWallet instance +// Shutdown closes all opened wallets and database +// in MultiWallet instance. func (mw *MultiWallet) Shutdown() { log.Info("Shutting down dcrlibwallet") @@ -140,13 +141,14 @@ func (mw *MultiWallet) Shutdown() { } } -// SetStartupPassPhrase sets the passPhrase of a wallet. +// 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 for and verifies the passPhrase of a wallet -// and returns an error respectively. +// 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) @@ -171,8 +173,7 @@ func (mw *MultiWallet) VerifyStartupPassphrase(startupPassphrase []byte) error { return nil } -// ChangeStartupPassPhrase verifies the current passPhrase -// and generates and sets a new one. +// ChangeStartupPassPhrase changes the startup passphrase. func (mw *MultiWallet) ChangeStartupPassphrase(oldPassphrase, newPassphrase []byte, passphraseType int32) error { if len(newPassphrase) == 0 { return mw.RemoveStartupPassphrase(oldPassphrase) @@ -199,7 +200,8 @@ func (mw *MultiWallet) ChangeStartupPassphrase(oldPassphrase, newPassphrase []by return nil } -// RemoveStartupPassphrase verifies the current passPhrase and deletes it. +// RemoveStartupPassphrase removes the startup security +// if oldPassphrase is valid. func (mw *MultiWallet) RemoveStartupPassphrase(oldPassphrase []byte) error { err := mw.VerifyStartupPassphrase(oldPassphrase) if err != nil { @@ -217,18 +219,18 @@ func (mw *MultiWallet) RemoveStartupPassphrase(oldPassphrase []byte) error { return nil } -// IsStartupSecuritySet returns whether ot not the startup security is set. +// IsStartupSecuritySet returns true if startup security is set. func (mw *MultiWallet) IsStartupSecuritySet() bool { return mw.ReadBoolConfigValueForKey(IsStartupSecuritySetConfigKey, false) } -// StartupSecurityType returns the type of security used for the startup passPhrase +// StartupSecurityType returns the PassPhraseType used +// for the startup security. func (mw *MultiWallet) StartupSecurityType() int32 { return mw.ReadInt32ConfigValueForKey(StartupSecurityTypeConfigKey, PassphraseTypePass) } -// OpenWallets checks whether or not the wallets is syncing, -// verifies the passPhrase and opens the wallet +// OpenWallets opens all loaded wallets. func (mw *MultiWallet) OpenWallets(startupPassphrase []byte) error { if mw.IsSyncing() { return errors.New(ErrSyncAlreadyInProgress) @@ -251,8 +253,8 @@ func (mw *MultiWallet) OpenWallets(startupPassphrase []byte) error { return nil } -// CreateWatchOnlyWallet creates a watch-only wallet, -// without neither a wallet seed nor a private keys. +// 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, @@ -293,8 +295,8 @@ func (mw *MultiWallet) CreateNewWallet(privatePassphrase string, privatePassphra }) } -// RestoreWallet uses a wallet seed, private passPhrase -// to restore a previously existing wallet. +// 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, @@ -312,8 +314,11 @@ func (mw *MultiWallet) RestoreWallet(seedMnemonic, privatePassphrase string, pri }) } +// LinkExistingWallet links an already existing wallet +// to the multi-wallet database. // -// LinkExistingWallet links an already existing wallet to a new one +// This is used as backward compatibility for wallets +// created before multi-wallet. func (mw *MultiWallet) LinkExistingWallet(walletDataDir, originalPubPass string, privatePassphraseType int32) (*Wallet, error) { if mw.IsSyncing() { return nil, errors.New(ErrSyncAlreadyInProgress) @@ -443,8 +448,7 @@ func (mw *MultiWallet) saveNewWallet(wallet *Wallet, setupWallet func() error) ( return wallet, nil } -// RenameWallet checks the newName if it contains an existing name -// and returns an updated walletName for the wallet. +// 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) @@ -465,7 +469,8 @@ func (mw *MultiWallet) RenameWallet(walletID int, newName string) error { return mw.db.Save(wallet) // update WalletName field } -// DeleteWallet checks whether or not wallet is syncing, then deletes the wallet with its accompanying Id +// DeleteWallet deletes a wallet data files and it's information +// from multi-wallet database. func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { if mw.IsSyncing() { return errors.New(ErrSyncAlreadyInProgress) @@ -491,7 +496,7 @@ func (mw *MultiWallet) DeleteWallet(walletID int, privPass []byte) error { return nil } -// WalletWithID returns wallet with an Id for easy selection +// 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 @@ -499,7 +504,8 @@ func (mw *MultiWallet) WalletWithID(walletID int) *Wallet { return nil } -// VerifySeedForWallet checks if a certain wallets' seed is a match. +// 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 { @@ -527,12 +533,12 @@ func (mw *MultiWallet) NumWalletsNeedingSeedBackup() int32 { return backupsNeeded } -// LoadedWalletsCount returns the number of loaded wallets +// LoadedWalletsCount returns the number of loaded wallets. func (mw *MultiWallet) LoadedWalletsCount() int32 { return int32(len(mw.wallets)) } -// OpenedWalletIDsRaw returns an array of int of walletIDs of wallets opened +// OpenedWalletIDsRaw returns a walletID array of opened wallets. func (mw *MultiWallet) OpenedWalletIDsRaw() []int { walletIDs := make([]int, 0) for _, wallet := range mw.wallets { @@ -543,19 +549,19 @@ func (mw *MultiWallet) OpenedWalletIDsRaw() []int { return walletIDs } -// OpenedWalletIDs returns a json.marshal of opened 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 +// OpenedWalletsCount returns the number of opened wallets. func (mw *MultiWallet) OpenedWalletsCount() int32 { return int32(len(mw.OpenedWalletIDsRaw())) } -// SyncedWalletsCount returns an int of synced wallets +// SyncedWalletsCount returns the number of synced wallets. func (mw *MultiWallet) SyncedWalletsCount() int32 { var syncedWallets int32 for _, wallet := range mw.wallets { @@ -567,7 +573,7 @@ func (mw *MultiWallet) SyncedWalletsCount() int32 { return syncedWallets } -// WalletNameExists returns whether or not a chosen walletName exists +// 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) @@ -583,7 +589,7 @@ func (mw *MultiWallet) WalletNameExists(walletName string) (bool, error) { return false, nil } -// UnlockWallet unlocks a wallet using the said wallets ID and privatePassPhrase +// UnlockWallet unlocks a wallet using the private pass. func (mw *MultiWallet) UnlockWallet(walletID int, privPass []byte) error { wallet := mw.WalletWithID(walletID) if wallet == nil { @@ -593,7 +599,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. +// 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) From 44e0d2b561ef168e67ae3972a9c58354f95aa8c2 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 14:24:54 +0100 Subject: [PATCH 27/41] accounts cleanup --- accounts.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/accounts.go b/accounts.go index c5a2e0bc..0ba6de8e 100644 --- a/accounts.go +++ b/accounts.go @@ -9,8 +9,8 @@ import ( "github.com/decred/dcrwallet/errors/v2" ) -// GetAccounts returns a json.Marshal of an -// account information in a wallet. +// GetAccounts returns a json array of all +// accounts information in a wallet. func (wallet *Wallet) GetAccounts(requiredConfirmations int32) (string, error) { accountsResponse, err := wallet.GetAccountsRaw(requiredConfirmations) if err != nil { @@ -21,7 +21,7 @@ func (wallet *Wallet) GetAccounts(requiredConfirmations int32) (string, error) { return string(result), nil } -// GetAccountsRaw returns all the information about an existing account. +// GetAccountsRaw returns an Accounts pointer containing all accounts information in a wallet. func (wallet *Wallet) GetAccountsRaw(requiredConfirmations int32) (*Accounts, error) { resp, err := wallet.internal.Accounts(wallet.shutdownContext()) if err != nil { @@ -190,7 +190,7 @@ func (wallet *Wallet) AccountNameRaw(accountNumber uint32) (string, error) { return wallet.internal.AccountName(wallet.shutdownContext(), accountNumber) } -// Returns an account number for the corresponding account name. +// AccountNumber returns an account number for the passed account. func (wallet *Wallet) AccountNumber(accountName string) (uint32, error) { return wallet.internal.AccountNumber(wallet.shutdownContext(), accountName) } From 176b85aba906e217842624be1138a61b56f1b0e8 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 14:43:03 +0100 Subject: [PATCH 28/41] multiwallet cleanup --- multiwallet.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/multiwallet.go b/multiwallet.go index 7a2a1801..07056f3e 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -271,8 +271,8 @@ func (mw *MultiWallet) CreateWatchOnlyWallet(walletName, extendedPublicKey strin }) } -// CreateNewWallet creates a new wallet with -// wallet seed as well as private PassPhrase +// 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 { @@ -295,7 +295,7 @@ func (mw *MultiWallet) CreateNewWallet(privatePassphrase string, privatePassphra }) } -// RestoreWallet uses a wallet seed and private passPhrase +// 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{ @@ -520,8 +520,8 @@ func (mw *MultiWallet) VerifySeedForWallet(walletID int, seedMnemonic string) er return errors.New(ErrInvalid) } -// NumWalletsNeedingSeedBackup iterates over the available -// wallets and checks and returns a list of any needing backups. +// NumWalletsNeedingSeedBackup returns the number of +// wallets that requires seed backup. func (mw *MultiWallet) NumWalletsNeedingSeedBackup() int32 { var backupsNeeded int32 for _, wallet := range mw.wallets { From 434d19123cdfd2e75f28f46a2b79d358d9a3b9d4 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 14:44:25 +0100 Subject: [PATCH 29/41] multiwallet_config cleanup --- multiwallet_config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multiwallet_config.go b/multiwallet_config.go index 95dff824..a4762e4b 100644 --- a/multiwallet_config.go +++ b/multiwallet_config.go @@ -49,7 +49,7 @@ func (mw *MultiWallet) walletConfigReadFn(walletID int) configReadFn { } } -// SaveUserConfigValue saves config value name for key +// SaveUserConfigValue saves config value for key func (mw *MultiWallet) SaveUserConfigValue(key string, value interface{}) { err := mw.db.Set(userConfigBucketName, key, value) if err != nil { @@ -74,7 +74,7 @@ func (mw *MultiWallet) DeleteUserConfigValueForKey(key string) { } } -// ClearConfig drops a config bucket name. +// ClearConfig clears all saved config. func (mw *MultiWallet) ClearConfig() { err := mw.db.Drop(userConfigBucketName) if err != nil { From 9e977f883ead17623a296322bc52b9e299fb7500 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 14:49:13 +0100 Subject: [PATCH 30/41] rescan cleanup --- rescan.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/rescan.go b/rescan.go index ab92b8d5..bf2a21c9 100644 --- a/rescan.go +++ b/rescan.go @@ -9,9 +9,8 @@ import ( w "github.com/decred/dcrwallet/wallet/v3" ) -// RescanBlocks checks whether or not the blocks are scanned or synced. -// If they are not updated, it scans the the block -// header until is it manually canceled. +// RescanBlocks rescans for relevant transactions in +// all blocks in the main chain. func (mw *MultiWallet) RescanBlocks(walletID int) error { wallet := mw.WalletWithID(walletID) @@ -110,7 +109,7 @@ func (mw *MultiWallet) RescanBlocks(walletID int) error { return nil } -// CancelRescan locks the wallet out from syncing. +// CancelRescan cancels an ongoing scans. func (mw *MultiWallet) CancelRescan() { mw.syncData.mu.Lock() defer mw.syncData.mu.Unlock() @@ -122,16 +121,15 @@ func (mw *MultiWallet) CancelRescan() { } } -// IsRescanning bypasses the lock on wallet for syncing -// to be carried out. +// 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 block for -// the scan progress listener. +// SetBlocksRescanProgressListener sets a listener to +// receive block rescan progress. func (mw *MultiWallet) SetBlocksRescanProgressListener(blocksRescanProgressListener BlocksRescanProgressListener) { mw.blocksRescanProgressListener = blocksRescanProgressListener } From 01af3d77f3371e2ce64a9966e998451a0fb31c88 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 15:03:39 +0100 Subject: [PATCH 31/41] sync cleanup --- sync.go | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/sync.go b/sync.go index 9b03fe85..b39904cd 100644 --- a/sync.go +++ b/sync.go @@ -90,8 +90,8 @@ func (mw *MultiWallet) initActiveSyncData() { mw.syncData.mu.Unlock() } -// IsSyncProgressListenerRegisteredFor checks for and returns a value that checks -// whether or not a progress listener was set for the wallet syncing. +// 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] @@ -114,7 +114,7 @@ func (mw *MultiWallet) AddSyncProgressListener(syncProgressListener SyncProgress return mw.PublishLastSyncProgress(uniqueIdentifier) } -// RemoveSyncProgressListener deletes an existing progress listener for wallet syncing. +// RemoveSyncProgressListener deletes an existing sync progress listener. func (mw *MultiWallet) RemoveSyncProgressListener(uniqueIdentifier string) { mw.syncData.mu.Lock() delete(mw.syncData.syncProgressListeners, uniqueIdentifier) @@ -133,7 +133,8 @@ func (mw *MultiWallet) syncProgressListeners() []SyncProgressListener { return listeners } -// PublishLastSyncProgress fetches and publishes sync and scan data. +// 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() @@ -157,7 +158,7 @@ func (mw *MultiWallet) PublishLastSyncProgress(uniqueIdentifier string) error { return nil } -// EnableSyncLogs enables logging of scan logs. +// EnableSyncLogs enables logging of sync logs. func (mw *MultiWallet) EnableSyncLogs() { mw.syncData.mu.Lock() mw.syncData.showLogs = true @@ -181,7 +182,7 @@ func (mw *MultiWallet) SyncInactiveForPeriod(totalInactiveSeconds int64) { } } -// SpvSync sets a wallet syncing for spv peer to peer connections. +// 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() { @@ -267,7 +268,7 @@ func (mw *MultiWallet) SpvSync() error { return nil } -// RestartSpvSync sends a request to restart SpvSync. +// RestartSpvSync restarts ongoing SpvSync. func (mw *MultiWallet) RestartSpvSync() error { mw.syncData.mu.Lock() mw.syncData.restartSyncRequested = true @@ -277,7 +278,7 @@ func (mw *MultiWallet) RestartSpvSync() error { return mw.SpvSync() } -// CancelSync cancels/stops any active wallet syncing. +// CancelSync stops any active wallet syncing. func (mw *MultiWallet) CancelSync() { mw.syncData.mu.RLock() cancelSync := mw.syncData.cancelSync @@ -308,39 +309,37 @@ func (mw *MultiWallet) CancelSync() { } } -// IsWaiting returns whether or not a wallet is -// waiting to be synced. +// 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 whether or not a wallet has been synced. +// IsSynced returns true if a wallet is synced. func (wallet *Wallet) IsSynced() bool { return wallet.synced } -// IsSyncing returns whether or not a wallet is undergoing syncing. +// IsSyncing returns true if a wallet is syncing. func (wallet *Wallet) IsSyncing() bool { return wallet.syncing } -// IsSynced returns the state of a wallet -// being synced if it has been synced +// IsSynced returns true if all wallets are synced. func (mw *MultiWallet) IsSynced() bool { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() return mw.syncData.synced } -// IsSyncing returns the state of a wallet undergoing syncing, -// if it is syncing. +// 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 wallet. +// CurrentSyncStage returns the sync stage of the wallets. func (mw *MultiWallet) CurrentSyncStage() int32 { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -351,7 +350,7 @@ func (mw *MultiWallet) CurrentSyncStage() int32 { return InvalidSyncStage } -// GeneralSyncProgress returns the total sync progress. +// GeneralSyncProgress returns the general sync progress. func (mw *MultiWallet) GeneralSyncProgress() *GeneralSyncProgress { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() @@ -377,7 +376,7 @@ func (mw *MultiWallet) ConnectedPeers() int32 { return mw.syncData.connectedPeers } -// GetBestBlock retrieves the best block height of a loaded wallet. +// GetBestBlock retrieves highest block height from the loaded wallets. func (mw *MultiWallet) GetBestBlock() *BlockInfo { var bestBlock int32 = -1 var blockInfo *BlockInfo @@ -396,7 +395,7 @@ func (mw *MultiWallet) GetBestBlock() *BlockInfo { return blockInfo } -// GetLowestBlock retrieves the lowest block height of a loaded wallet. +// GetLowestBlock retrieves the lowest block height from the loaded wallets. func (mw *MultiWallet) GetLowestBlock() *BlockInfo { var lowestBlock int32 = -1 var blockInfo *BlockInfo @@ -426,7 +425,7 @@ func (wallet *Wallet) GetBestBlock() int32 { return height } -// GetBestBlockTimeStamp retrieves the best Timestamp of a block header event. +// 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. @@ -445,7 +444,8 @@ func (wallet *Wallet) GetBestBlockTimeStamp() int64 { return info.Timestamp } -// GetLowestBlockTimestamp gets the lowest Timestamp of a block header event. +// 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 { From 35e94873b2a15a3b7dd9a9775e2dd71e8fe92aa2 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 19:49:19 +0100 Subject: [PATCH 32/41] ticket cleanup --- ticket.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ticket.go b/ticket.go index fdef392c..a97e7f19 100644 --- a/ticket.go +++ b/ticket.go @@ -36,7 +36,8 @@ func (wallet *Wallet) StakeInfo() (*w.StakeInfoData, error) { return wallet.internal.StakeInfo(ctx) } -// GetTickets returns information about ticket request. +// 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, @@ -45,8 +46,8 @@ func (wallet *Wallet) GetTickets(startingBlockHash, endingBlockHash []byte, targ }) } -// GetTicketsForBlockHeightRange returns information about -// ticket request used for block height range. +// 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, @@ -179,7 +180,7 @@ func (wallet *Wallet) TicketPrice(ctx context.Context) (*TicketPriceResponse, er }, nil } -// PurchaseTickets purchases tickets from the wallet. Returns a slice +// 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 From 8b2489038b01b36fcd8e8c39cbd8c34bba8fe952 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 20:29:45 +0100 Subject: [PATCH 33/41] transactions cleanup --- transactions.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/transactions.go b/transactions.go index d578fc10..4821d347 100644 --- a/transactions.go +++ b/transactions.go @@ -33,7 +33,7 @@ const ( ) // GetTransaction returns the JSON encoded string of -// transactions in a wallet. +// transaction details. func (wallet *Wallet) GetTransaction(txHash []byte) (string, error) { transaction, err := wallet.GetTransactionRaw(txHash) if err != nil { @@ -49,7 +49,7 @@ func (wallet *Wallet) GetTransaction(txHash []byte) (string, error) { return string(result), nil } -// GetTransactionRaw returns the details of transaction related to the wallet. +// 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 { @@ -67,7 +67,7 @@ func (wallet *Wallet) GetTransactionRaw(txHash []byte) (*Transaction, error) { } // GetTransactions returns the JSON encoding of all transactions -// in a wallet starting from the most recent. +// 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 { @@ -82,15 +82,15 @@ func (wallet *Wallet) GetTransactions(offset, limit, txFilter int32, newestFirst return string(jsonEncodedTransactions), nil } -// GetTransactionsRaw returns the details of transactions related to the wallet. +// 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 encoded strings -// of all transactions in several wallets starting -// from the newest wallet created. +// 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 { @@ -122,8 +122,8 @@ func (mw *MultiWallet) GetTransactions(offset, limit, txFilter int32, newestFirs return string(jsonEncodedTransactions), nil } -// CountTransactions returns number of recorded transactions that -// occurred within a wallet at a given period of time. +// CountTransactions returns number of transactions matching +// the txFilter. func (wallet *Wallet) CountTransactions(txFilter int32) (int, error) { return wallet.txDB.Count(txFilter, &Transaction{}) } From b74e2b3724538491d8e3db26e9f63536847df1d1 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 20:50:28 +0100 Subject: [PATCH 34/41] txandblocknotifications cleanup --- txandblocknotifications.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/txandblocknotifications.go b/txandblocknotifications.go index 24fab038..569d739d 100644 --- a/txandblocknotifications.go +++ b/txandblocknotifications.go @@ -62,7 +62,7 @@ func (mw *MultiWallet) listenForTransactions(walletID int) { } // AddTxAndBlockNotificationListener adds a notification listener -// for transaction and certain block height on wallet. +// for new transactions and blocks received. func (mw *MultiWallet) AddTxAndBlockNotificationListener(txAndBlockNotificationListener TxAndBlockNotificationListener, uniqueIdentifier string) error { _, ok := mw.txAndBlockNotificationListeners[uniqueIdentifier] if ok { @@ -74,8 +74,8 @@ func (mw *MultiWallet) AddTxAndBlockNotificationListener(txAndBlockNotificationL return nil } -// RemoveTxAndBlockNotificationListener deletes the notification -// listener set for transaction and block height in a wallet. +// RemoveTxAndBlockNotificationListener deletes existing +// TxAndBlockNotificationListener matching uniqueIdentifier. func (mw *MultiWallet) RemoveTxAndBlockNotificationListener(uniqueIdentifier string) { delete(mw.txAndBlockNotificationListeners, uniqueIdentifier) } From 462a8468856d6cb6b5719bcf845d42478882e020 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 20:55:10 +0100 Subject: [PATCH 35/41] txauthor and txindex cleanup --- txauthor.go | 4 ++-- txindex.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/txauthor.go b/txauthor.go index 5fd4a9aa..4f4608bd 100644 --- a/txauthor.go +++ b/txauthor.go @@ -22,7 +22,7 @@ type TxAuthor struct { wallet *Wallet } -//NewUnsignedTx returns information on the account of transaction author +//NewUnsignedTx returns a TxAuthor instance to construct a transaction. func (wallet *Wallet) NewUnsignedTx(sourceAccountNumber, requiredConfirmations int32) *TxAuthor { return &TxAuthor{ sendFromAccount: uint32(sourceAccountNumber), @@ -32,7 +32,7 @@ func (wallet *Wallet) NewUnsignedTx(sourceAccountNumber, requiredConfirmations i } } -//SetSourceAccount sets the particular account from which to carry out transaction +//SetSourceAccount sets the particular account from which to carry out the transaction. func (tx *TxAuthor) SetSourceAccount(accountNumber int32) { tx.sendFromAccount = uint32(accountNumber) } diff --git a/txindex.go b/txindex.go index d340ffd8..373c521e 100644 --- a/txindex.go +++ b/txindex.go @@ -6,8 +6,8 @@ import ( "github.com/raedahgroup/dcrlibwallet/txindex" ) -// IndexTransactions returns an index of all transactions -// from start to end of a full block height. +// IndexTransactions saves all wallet transactions +// into storm db. func (wallet *Wallet) IndexTransactions() error { ctx := wallet.shutdownContext() From 8fdf5cec7dfa6636fb065fe227674d80be5fb66e Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 21:05:00 +0100 Subject: [PATCH 36/41] save and utils cleanup --- txindex/save.go | 7 +++---- utils.go | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/txindex/save.go b/txindex/save.go index 0a5c608f..95acb1f9 100644 --- a/txindex/save.go +++ b/txindex/save.go @@ -33,8 +33,8 @@ func (db *DB) SaveOrUpdate(emptyTxPointer, tx interface{}) (overwritten bool, er return } -// SaveLastIndexPoint this saves the last index -// of of block height height achieved. +// 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 { @@ -43,8 +43,7 @@ func (db *DB) SaveLastIndexPoint(endBlockHeight int32) error { return nil } -// ClearSavedTransactions deletes a bucket -// saved on the transaction database. +// 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 e4ffac44..1fe03db5 100644 --- a/utils.go +++ b/utils.go @@ -71,7 +71,8 @@ func (mw *MultiWallet) contextWithShutdownCancel() (context.Context, context.Can return ctx, cancel } -// ValidateExtPubKey provides an instance of key extension required by the network type. +// 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 { From 846e29a0832708c0da17e2b07ab516e6e15a21c2 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Tue, 31 Mar 2020 21:14:30 +0100 Subject: [PATCH 37/41] wallet and wallets cleanup --- wallet.go | 7 ++++--- wallets.go | 12 +++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/wallet.go b/wallet.go index 23fd8f2b..680f68a8 100644 --- a/wallet.go +++ b/wallet.go @@ -115,7 +115,7 @@ func (wallet *Wallet) NetType() string { return wallet.chainParams.Name } -// WalletExists returns whether or not a wallet exists at the loaders' db path. +// WalletExists returns true if a wallet exists at the loaders' DB path. func (wallet *Wallet) WalletExists() (bool, error) { return wallet.loader.WalletExists() } @@ -161,7 +161,8 @@ func (wallet *Wallet) createWatchingOnlyWallet(extendedPublicKey string) error { return nil } -// IsWatchingOnlyWallet returns whether or not a wallet is in watching only mode. +// 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() @@ -217,7 +218,7 @@ func (wallet *Wallet) LockWallet() { } } -// IsLocked returns whether a wallet is locked. +// IsLocked returns true if a wallet is locked. func (wallet *Wallet) IsLocked() bool { return wallet.internal.Locked() } diff --git a/wallets.go b/wallets.go index 8b296d34..28ab0eaa 100644 --- a/wallets.go +++ b/wallets.go @@ -1,6 +1,6 @@ package dcrlibwallet -// AllWallets returns all the available wallets in a MultiWallet instance. +// AllWallets returns an array of loaded wallets. func (mw *MultiWallet) AllWallets() (wallets []*Wallet) { for _, wallet := range mw.wallets { wallets = append(wallets, wallet) @@ -8,8 +8,7 @@ func (mw *MultiWallet) AllWallets() (wallets []*Wallet) { return wallets } -// WalletsIterator returns all the available wallets and -// their index in a MultiWallet instance. +// WalletsIterator returns an iterator for mw wallets. func (mw *MultiWallet) WalletsIterator() *WalletsIterator { return &WalletsIterator{ currentIndex: 0, @@ -17,9 +16,8 @@ func (mw *MultiWallet) WalletsIterator() *WalletsIterator { } } -// Next iterates over the the wallets in a MultiWallet -// instance and returns a wallet that has an index -// within the length of the available wallets. +// 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] @@ -30,7 +28,7 @@ func (walletsIterator *WalletsIterator) Next() *Wallet { return nil } -// Reset sets the wallet to display at index 0. +// Reset sets the iterator index to 0. func (walletsIterator *WalletsIterator) Reset() { walletsIterator.currentIndex = 0 } From c43cf3f0821124e78986c25b8041da590c3b2550 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Thu, 2 Apr 2020 00:09:25 +0100 Subject: [PATCH 38/41] txauthor cleanup --- txauthor.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/txauthor.go b/txauthor.go index 4f4608bd..e166190d 100644 --- a/txauthor.go +++ b/txauthor.go @@ -22,7 +22,7 @@ type TxAuthor struct { wallet *Wallet } -//NewUnsignedTx returns a TxAuthor instance to construct a transaction. +// NewUnsignedTx returns a TxAuthor instance to construct a transaction. func (wallet *Wallet) NewUnsignedTx(sourceAccountNumber, requiredConfirmations int32) *TxAuthor { return &TxAuthor{ sendFromAccount: uint32(sourceAccountNumber), @@ -32,12 +32,13 @@ func (wallet *Wallet) NewUnsignedTx(sourceAccountNumber, requiredConfirmations i } } -//SetSourceAccount sets the particular account from which to carry out the transaction. +// SetSourceAccount sets account to fund the transaction. func (tx *TxAuthor) SetSourceAccount(accountNumber int32) { tx.sendFromAccount = uint32(accountNumber) } -//AddSendDestination sets the wallet address to which funds are sent to +// 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, @@ -46,7 +47,7 @@ func (tx *TxAuthor) AddSendDestination(address string, atomAmount int64, sendMax }) } -//UpdateSendDestination allows for a change in wallet address to which funds are sent to +//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, @@ -55,14 +56,15 @@ func (tx *TxAuthor) UpdateSendDestination(index int, address string, atomAmount } } -//RemoveSendDestination deletes an address that was set for receiving funds +//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:]...) } } -//EstimateFeeAndSize returns the information about transaction fee and estimated size of transaction +//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 { @@ -81,8 +83,8 @@ func (tx *TxAuthor) EstimateFeeAndSize() (*TxFeeAndSize, error) { }, nil } -//EstimateMaxSendAmount returns the estimated limit of funds to send -//or an error if no amount is set +//EstimateMaxSendAmount returns the maximum spendable amount +// excluding the transaction fee. func (tx *TxAuthor) EstimateMaxSendAmount() (*Amount, error) { txFeeAndSize, err := tx.EstimateFeeAndSize() if err != nil { @@ -102,7 +104,7 @@ func (tx *TxAuthor) EstimateMaxSendAmount() (*Amount, error) { }, nil } -// Broadcast allows for pasting of raw transactions conducted in a wallet. +// Broadcast signs and publishes the transactions to the network. func (tx *TxAuthor) Broadcast(privatePassphrase []byte) ([]byte, error) { defer func() { for i := range privatePassphrase { From 6ed8767421c9a34650587a0a7b899919cbc56684 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 8 Apr 2020 19:04:58 +0100 Subject: [PATCH 39/41] go lint --- accounts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts.go b/accounts.go index 6ef0a740..a65d6c56 100644 --- a/accounts.go +++ b/accounts.go @@ -115,7 +115,7 @@ func (wallet *Wallet) GetAccount(accountNumber int32) (*Account, error) { // 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() + balance, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(accountNumber), wallet.RequiredConfirmations()) if err != nil { return nil, err } From 673a1efe34ecea7918786775191d599035b0e139 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 8 Apr 2020 19:59:16 +0100 Subject: [PATCH 40/41] replacing missing fucntion --- sync.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sync.go b/sync.go index d5df1ace..4f870556 100644 --- a/sync.go +++ b/sync.go @@ -325,6 +325,16 @@ 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() + return mw.syncData.syncing || mw.syncData.synced +} + + + func (mw *MultiWallet) IsSynced() bool { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock() From 9547db4f3d577dbe80d18fdb9176f0e8ea493454 Mon Sep 17 00:00:00 2001 From: ReevesAkwa Date: Wed, 8 Apr 2020 19:59:28 +0100 Subject: [PATCH 41/41] replacing missing fucntion --- sync.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/sync.go b/sync.go index 4f870556..f7d04478 100644 --- a/sync.go +++ b/sync.go @@ -333,8 +333,6 @@ func (mw *MultiWallet) IsConnectedToDecredNetwork() bool { return mw.syncData.syncing || mw.syncData.synced } - - func (mw *MultiWallet) IsSynced() bool { mw.syncData.mu.RLock() defer mw.syncData.mu.RUnlock()