Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
678a6b4
documentation for accounts
ReevesAk Mar 6, 2020
41c58fc
documentation for address
ReevesAk Mar 6, 2020
2081259
documentation for message and multiwallet
ReevesAk Mar 6, 2020
0b8564e
spell check
ReevesAk Mar 7, 2020
76f9321
documentation for multiwallet_config
ReevesAk Mar 7, 2020
a6dd0c6
documentation for rescan.go
ReevesAk Mar 7, 2020
54ecea8
documentation for sync.go
ReevesAk Mar 8, 2020
f4863d0
documentations for tickets, tx, txnblocknotification
ReevesAk Mar 9, 2020
d9e945a
documentation for txauthor, txindex, utils, and wallet
ReevesAk Mar 9, 2020
d91fe07
documentation for wallets and wallet_config
ReevesAk Mar 9, 2020
d6b0d01
corrected multiwallet
ReevesAk Mar 10, 2020
778174e
corrected MultiWallet
ReevesAk Mar 10, 2020
b9af142
documentation for helper.go
ReevesAk Mar 10, 2020
9ce932e
documentation for db.go
ReevesAk Mar 10, 2020
9056562
documentation for save.go
ReevesAk Mar 10, 2020
15cca52
modifications to accounts, address, message and multiWallet_config
ReevesAk Mar 11, 2020
45dad17
modifications to rescan, sync and ticket
ReevesAk Mar 11, 2020
36d01e4
modifications to transaction and txandblocknotifcations
ReevesAk Mar 11, 2020
32d7c56
modifications to txauthor, txindex, utils, wallet
ReevesAk Mar 11, 2020
4819e92
modifications to wallet_config and wallets
ReevesAk Mar 11, 2020
52de6bd
go fmt
ReevesAk Mar 25, 2020
38eef3e
cleanup
ReevesAk Mar 25, 2020
0e64890
account correction
ReevesAk Mar 28, 2020
7f2f9eb
address correction
ReevesAk Mar 28, 2020
0731c4c
helper and message correction
ReevesAk Mar 28, 2020
472b0d4
multiwallet correction
ReevesAk Mar 29, 2020
44e0d2b
accounts cleanup
ReevesAk Mar 31, 2020
176b85a
multiwallet cleanup
ReevesAk Mar 31, 2020
434d191
multiwallet_config cleanup
ReevesAk Mar 31, 2020
9e977f8
rescan cleanup
ReevesAk Mar 31, 2020
01af3d7
sync cleanup
ReevesAk Mar 31, 2020
35e9487
ticket cleanup
ReevesAk Mar 31, 2020
8b24890
transactions cleanup
ReevesAk Mar 31, 2020
b74e2b3
txandblocknotifications cleanup
ReevesAk Mar 31, 2020
462a846
txauthor and txindex cleanup
ReevesAk Mar 31, 2020
8fdf5ce
save and utils cleanup
ReevesAk Mar 31, 2020
846e29a
wallet and wallets cleanup
ReevesAk Mar 31, 2020
c43cf3f
txauthor cleanup
ReevesAk Apr 1, 2020
2ebce25
Merge branch 'master' into documentations
ReevesAk Apr 3, 2020
6ed8767
go lint
ReevesAk Apr 8, 2020
673a1ef
replacing missing fucntion
ReevesAk Apr 8, 2020
9547db4
replacing missing fucntion
ReevesAk Apr 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/decred/dcrwallet/errors/v2"
)

// GetAccounts returns a json.Marshal of an
// account information in a wallet.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) GetAccounts(requiredConfirmations int32) (string, error) {
accountsResponse, err := wallet.GetAccountsRaw(requiredConfirmations)
if err != nil {
Expand All @@ -19,6 +21,7 @@ func (wallet *Wallet) GetAccounts(requiredConfirmations int32) (string, error) {
return string(result), nil
}

// GetAccountsRaw returns all the information about an existing account.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) GetAccountsRaw(requiredConfirmations int32) (*Accounts, error) {
resp, err := wallet.internal.Accounts(wallet.shutdownContext())
if err != nil {
Expand Down Expand Up @@ -51,6 +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.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) AccountsIterator(requiredConfirmations int32) (*AccountsIterator, error) {
accounts, err := wallet.GetAccountsRaw(requiredConfirmations)
if err != nil {
Expand All @@ -63,6 +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.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (accountsInterator *AccountsIterator) Next() *Account {
if accountsInterator.currentIndex < len(accountsInterator.accounts) {
account := accountsInterator.accounts[accountsInterator.currentIndex]
Expand All @@ -73,10 +80,13 @@ func (accountsInterator *AccountsIterator) Next() *Account {
return nil
}

// Sets the account index to default: 0
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
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 {
Expand All @@ -102,6 +112,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.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) GetAccountBalance(accountNumber int32, requiredConfirmations int32) (*Balance, error) {
balance, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(accountNumber), requiredConfirmations)
if err != nil {
Expand All @@ -119,6 +132,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.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) SpendableForAccount(account int32, requiredConfirmations int32) (int64, error) {
bals, err := wallet.internal.CalculateAccountBalance(wallet.shutdownContext(), uint32(account), requiredConfirmations)
if err != nil {
Expand All @@ -128,6 +144,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.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, error) {
lock := make(chan time.Time, 1)
defer func() {
Expand All @@ -149,6 +168,7 @@ func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, e
return int32(accountNumber), err
}

// Sets the name of an account to a newName.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error {
err := wallet.internal.RenameAccount(wallet.shutdownContext(), uint32(accountNumber), newName)
if err != nil {
Expand All @@ -158,6 +178,7 @@ func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error {
return nil
}

// Checks for an account and logs error if wallet is empty
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) AccountName(accountNumber int32) string {
name, err := wallet.AccountNameRaw(uint32(accountNumber))
if err != nil {
Expand All @@ -167,14 +188,18 @@ func (wallet *Wallet) AccountName(accountNumber int32) string {
return name
}

// Returns the account name for the corresponding account number.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) AccountNameRaw(accountNumber uint32) (string, error) {
return wallet.internal.AccountName(wallet.shutdownContext(), accountNumber)
}

// Returns an account number for the corresponding account name.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
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.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) HDPathForAccount(accountNumber int32) (string, error) {
cointype, err := wallet.internal.CoinType(wallet.shutdownContext())
if err != nil {
Expand Down
15 changes: 14 additions & 1 deletion address.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ 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
AccountNumber uint32
AccountName string
}

// IsAddressValid decodes the string coding of an address and
// returns whether the network param is valid.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) IsAddressValid(address string) bool {
_, err := dcrutil.DecodeAddress(address, wallet.chainParams)
return err == nil
}

// HaveAddress returns whether wallet is the owner of the address.
func (wallet *Wallet) HaveAddress(address string) bool {
addr, err := dcrutil.DecodeAddress(address, wallet.chainParams)
if err != nil {
Expand All @@ -38,6 +43,8 @@ func (wallet *Wallet) HaveAddress(address string) bool {
return have
}

// AccountOfAddress returns a detailed information of an
// account belonging to a wallet address.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) AccountOfAddress(address string) string {
addr, err := dcrutil.DecodeAddress(address, wallet.chainParams)
if err != nil {
Expand All @@ -48,6 +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.
func (wallet *Wallet) AddressInfo(address string) (*AddressInfo, error) {
addr, err := dcrutil.DecodeAddress(address, wallet.chainParams)
if err != nil {
Expand All @@ -69,6 +78,8 @@ func (wallet *Wallet) AddressInfo(address string) (*AddressInfo, error) {
return addressInfo, nil
}

// CurrentAddress returns the string encoding of the
// most recent payment address.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) CurrentAddress(account int32) (string, error) {
if wallet.IsRestored && !wallet.HasDiscoveredAccounts {
return "", errors.E(ErrAddressDiscoveryNotDone)
Expand All @@ -82,6 +93,7 @@ func (wallet *Wallet) CurrentAddress(account int32) (string, error) {
return addr.Address(), nil
}

// NextAddress returns the string encoding an external address.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) NextAddress(account int32) (string, error) {
if wallet.IsRestored && !wallet.HasDiscoveredAccounts {
return "", errors.E(ErrAddressDiscoveryNotDone)
Expand All @@ -95,6 +107,7 @@ func (wallet *Wallet) NextAddress(account int32) (string, error) {
return addr.Address(), nil
}

// AddressPubKey returns the public key of an address in wallet.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) AddressPubKey(address string) (string, error) {
addr, err := dcrutil.DecodeAddress(address, wallet.chainParams)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions addresshelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func PkScript(address string, net dcrutil.AddressParams) ([]byte, error) {
return txscript.PayToAddrScript(addr)
}

// PkScriptAddresses returns the type of
// script and associated addresses.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func PkScriptAddresses(params *chaincfg.Params, pkScript []byte) ([]string, error) {
_, addresses, _, err := txscript.ExtractPkScriptAddrs(scriptVersion, pkScript, params)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions badgerdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ 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
}
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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -186,6 +194,7 @@ func (b *Bucket) NestedReadWriteBucket(key []byte) walletdb.ReadWriteBucket {
return nestedBucket
}

// NestedReadBucket returns a read and write bucket interface implementation.
func (b *Bucket) NestedReadBucket(key []byte) walletdb.ReadBucket {
if b.dbTransaction.db.closed {
return nil
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
w "github.com/decred/dcrwallet/wallet/v3"
)

// SignMessage returns a signature of a signed message.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) SignMessage(passphrase []byte, address string, message string) ([]byte, error) {
lock := make(chan time.Time, 1)
defer func() {
Expand Down Expand Up @@ -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.
Comment thread
ReevesAk marked this conversation as resolved.
Outdated
func (wallet *Wallet) VerifyMessage(address string, message string, signatureBase64 string) (bool, error) {
var valid bool

Expand Down
Loading