Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #116

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 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
22 changes: 22 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.
ReevesAk marked this conversation as resolved.
Show resolved Hide resolved
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.
ReevesAk marked this conversation as resolved.
Show resolved Hide resolved
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 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 {
Expand All @@ -63,6 +68,8 @@ func (wallet *Wallet) AccountsIterator(requiredConfirmations int32) (*AccountsIt
}, nil
}

// Next returns the account on the current iterator
// index and increments the current index.
func (accountsInterator *AccountsIterator) Next() *Account {
if accountsInterator.currentIndex < len(accountsInterator.accounts) {
account := accountsInterator.accounts[accountsInterator.currentIndex]
Expand All @@ -73,10 +80,13 @@ func (accountsInterator *AccountsIterator) Next() *Account {
return nil
}

// Reset sets the current iterator's index to 0.
func (accountsInterator *AccountsIterator) Reset() {
accountsInterator.currentIndex = 0
}

// GetAccount fetches an account and all the accompanying
// information and properties of the said account.
func (wallet *Wallet) GetAccount(accountNumber int32, requiredConfirmations int32) (*Account, error) {
props, err := wallet.internal.AccountProperties(wallet.shutdownContext(), uint32(accountNumber))
if err != nil {
Expand All @@ -102,6 +112,8 @@ func (wallet *Wallet) GetAccount(accountNumber int32, requiredConfirmations int3
return account, nil
}

// 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 {
Expand All @@ -119,6 +131,8 @@ func (wallet *Wallet) GetAccountBalance(accountNumber int32, requiredConfirmatio
}, nil
}

// 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 {
Expand All @@ -128,6 +142,8 @@ func (wallet *Wallet) SpendableForAccount(account int32, requiredConfirmations i
return int64(bals.Spendable), nil
}

// NextAccount creates the account and returns the
// account number.
func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, error) {
lock := make(chan time.Time, 1)
defer func() {
Expand All @@ -149,6 +165,7 @@ func (wallet *Wallet) NextAccount(accountName string, privPass []byte) (int32, e
return int32(accountNumber), err
}

// RenameAccount sets the name for an account number to newName.
func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error {
err := wallet.internal.RenameAccount(wallet.shutdownContext(), uint32(accountNumber), newName)
if err != nil {
Expand All @@ -158,6 +175,7 @@ func (wallet *Wallet) RenameAccount(accountNumber int32, newName string) error {
return nil
}

// AccountName returns the name for the passed account number.
func (wallet *Wallet) AccountName(accountNumber int32) string {
name, err := wallet.AccountNameRaw(uint32(accountNumber))
if err != nil {
Expand All @@ -167,14 +185,18 @@ func (wallet *Wallet) AccountName(accountNumber int32) string {
return name
}

// AccountNameRaw returns the name for the passed account number.
func (wallet *Wallet) AccountNameRaw(accountNumber uint32) (string, error) {
return wallet.internal.AccountName(wallet.shutdownContext(), accountNumber)
}

// Returns an account number for the corresponding account name.
ReevesAk marked this conversation as resolved.
Show resolved Hide resolved
ReevesAk marked this conversation as resolved.
Show resolved Hide resolved
func (wallet *Wallet) AccountNumber(accountName string) (uint32, error) {
return wallet.internal.AccountNumber(wallet.shutdownContext(), accountName)
}

// HDPathForAccount returns the HD path for the passed account based
// on the coin-type and the net type of the wallet.
func (wallet *Wallet) HDPathForAccount(accountNumber int32) (string, error) {
cointype, err := wallet.internal.CoinType(wallet.shutdownContext())
if err != nil {
Expand Down
14 changes: 13 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 an address string and checks if
// it is valid for the current net type.
func (wallet *Wallet) IsAddressValid(address string) bool {
_, err := dcrutil.DecodeAddress(address, wallet.chainParams)
return err == nil
}

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

// AccountOfAddress returns the account name of the passed wallet address.
func (wallet *Wallet) AccountOfAddress(address string) string {
addr, err := dcrutil.DecodeAddress(address, wallet.chainParams)
if err != nil {
Expand All @@ -48,6 +54,8 @@ func (wallet *Wallet) AccountOfAddress(address string) string {
return wallet.AccountName(int32(info.Account()))
}

// AddressInfo returns information for an address such as
// the address, account number and name of the account.
func (wallet *Wallet) AddressInfo(address string) (*AddressInfo, error) {
addr, err := dcrutil.DecodeAddress(address, wallet.chainParams)
if err != nil {
Expand All @@ -69,6 +77,7 @@ func (wallet *Wallet) AddressInfo(address string) (*AddressInfo, error) {
return addressInfo, nil
}

// CurrentAddress returns the next unused address of an account.
func (wallet *Wallet) CurrentAddress(account int32) (string, error) {
if wallet.IsRestored && !wallet.HasDiscoveredAccounts {
return "", errors.E(ErrAddressDiscoveryNotDone)
Expand All @@ -82,6 +91,8 @@ func (wallet *Wallet) CurrentAddress(account int32) (string, error) {
return addr.Address(), nil
}

// NextAddress returns a new external address
// for the passed account.
func (wallet *Wallet) NextAddress(account int32) (string, error) {
if wallet.IsRestored && !wallet.HasDiscoveredAccounts {
return "", errors.E(ErrAddressDiscoveryNotDone)
Expand All @@ -95,6 +106,7 @@ func (wallet *Wallet) NextAddress(account int32) (string, error) {
return addr.Address(), nil
}

// AddressPubKey returns the public key of the passed address.
func (wallet *Wallet) AddressPubKey(address string) (string, error) {
addr, err := dcrutil.DecodeAddress(address, wallet.chainParams)
if err != nil {
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 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 {
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
3 changes: 3 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
w "github.com/decred/dcrwallet/wallet/v3"
)

// SignMessage returns the signature of a signed message
// using an address associated private key.
func (wallet *Wallet) SignMessage(passphrase []byte, address string, message string) ([]byte, error) {
lock := make(chan time.Time, 1)
defer func() {
Expand Down Expand Up @@ -45,6 +47,7 @@ func (wallet *Wallet) SignMessage(passphrase []byte, address string, message str
return sig, nil
}

// VerifyMessage verifies that signatureBase64 is a valid signature.
func (wallet *Wallet) VerifyMessage(address string, message string, signatureBase64 string) (bool, error) {
var valid bool

Expand Down
Loading