Documentation
¶
Overview ¶
Package wallet provides ... TODO: Flesh out this section
Overview
Index ¶
- Constants
- Variables
- func Create(db walletdb.DB, pubPass, privPass []byte, seedInput []byte, ...) er.R
- func DropTransactionHistory(db walletdb.DB, keepLabels bool) er.R
- func NilComparator(a, b interface{}) int
- func PreferBiggest(a, b interface{}) int
- func PreferOldest(a, b interface{}) int
- func UnstableAPI(w *Wallet) unstableAPI
- func WalletDbPath(netDir, walletName string) string
- type AccountBalance
- type Balances
- type Block
- type BlockIdentifier
- type CreateTxReq
- type CreditCategory
- type GetTransactionsResult
- type Loader
- func (l *Loader) CreateNewWallet(pubPassphrase, privPassphrase []byte, seedInput []byte, seedBirthday time.Time, ...) (*Wallet, er.R)
- func (l *Loader) LoadedWallet() (*Wallet, bool)
- func (l *Loader) OpenExistingWallet(pubPassphrase []byte, canConsolePrompt bool) (*Wallet, er.R)
- func (l *Loader) RunAfterLoad(fn func(*Wallet))
- func (l *Loader) UnloadWallet() er.R
- func (l *Loader) WalletExists() (bool, er.R)
- type NotificationServer
- type PrivKeyTweaker
- type SignatureError
- type SyncerResp
- type TransactionNotifications
- type TransactionNotificationsClient
- type TransactionSummary
- type TransactionSummaryInput
- type TransactionSummaryOutput
- type Wallet
- func (w *Wallet) AccountAddresses(account uint32) (addrs []btcutil.Address, err er.R)
- func (w *Wallet) AccountName(scope waddrmgr.KeyScope, accountNumber uint32) (string, er.R)
- func (w *Wallet) AccountOfAddress(a btcutil.Address) (uint32, er.R)
- func (w *Wallet) AddressInfo(a btcutil.Address) (waddrmgr.ManagedAddress, er.R)
- func (w *Wallet) CalculateAddressBalances(confirms int32, showZeroBalances bool) (map[btcutil.Address]*Balances, er.R)
- func (w *Wallet) CalculateBalance(confirms int32) (btcutil.Amount, er.R)
- func (w *Wallet) ChainClient() chain.Interface
- func (w *Wallet) ChainParams() *chaincfg.Params
- func (w *Wallet) ChainSynced() bool
- func (w *Wallet) ChangePassphrases(publicOld, publicNew, privateOld, privateNew []byte) er.R
- func (w *Wallet) ChangePrivatePassphrase(oldPass, newPass []byte) er.R
- func (w *Wallet) ComputeInputScript(tx *wire.MsgTx, output *wire.TxOut, inputIndex int, ...) (wire.TxWitness, []byte, er.R)
- func (w *Wallet) CreateSimpleTx(r CreateTxReq) (*txauthor.AuthoredTx, er.R)
- func (w *Wallet) CurrentAddress(account uint32, scope waddrmgr.KeyScope) (btcutil.Address, er.R)
- func (w *Wallet) Database() walletdb.DB
- func (w *Wallet) DumpWIFPrivateKey(addr btcutil.Address) (string, er.R)
- func (w *Wallet) FetchInputInfo(prevOut *wire.OutPoint) (*wire.MsgTx, *wire.TxOut, int64, er.R)
- func (w *Wallet) FinalizePsbt(packet *psbt.Packet) er.R
- func (w *Wallet) FundPsbt(packet *psbt.Packet, account uint32, feeSatPerKB btcutil.Amount) (int32, er.R)
- func (w *Wallet) GetSecret(name string) (*string, er.R)
- func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel <-chan struct{}) (*GetTransactionsResult, er.R)
- func (w *Wallet) HaveAddress(a btcutil.Address) (bool, er.R)
- func (w *Wallet) ImportP2SHRedeemScript(script []byte) (*btcutil.AddressScriptHash, er.R)
- func (w *Wallet) ImportP2WSHRedeemScript(script []byte) (*btcutil.AddressWitnessScriptHash, er.R)
- func (w *Wallet) ImportPrivateKey(scope waddrmgr.KeyScope, wif *btcutil.WIF, bs *waddrmgr.BlockStamp, ...) (string, er.R)
- func (w *Wallet) LabelTransaction(hash chainhash.Hash, label string, overwrite bool) er.R
- func (w *Wallet) LeaseOutput(id wtxmgr.LockID, op wire.OutPoint) (time.Time, er.R)
- func (w *Wallet) ListAddressTransactions(pkHashes map[string]struct{}) ([]btcjson.ListTransactionsResult, er.R)
- func (w *Wallet) ListAllTransactions() ([]btcjson.ListTransactionsResult, er.R)
- func (w *Wallet) ListSinceBlock(start, end, syncHeight int32) ([]btcjson.ListTransactionsResult, er.R)
- func (w *Wallet) ListTransactions(from, count int) ([]btcjson.ListTransactionsResult, er.R)
- func (w *Wallet) ListUnspent(minconf, maxconf int32, addresses map[string]struct{}) ([]*btcjson.ListUnspentResult, er.R)
- func (w *Wallet) Lock()
- func (w *Wallet) LockOutpoint(op wire.OutPoint, name string)
- func (w *Wallet) Locked() bool
- func (w *Wallet) LockedOutpoint(op wire.OutPoint) bool
- func (w *Wallet) LockedOutpoints() []btcjson.LockedUnspent
- func (w *Wallet) MakeMultiSigScript(addrs []btcutil.Address, nRequired int) ([]byte, er.R)
- func (w *Wallet) NetworkStewardVote(accountNumber uint32, scope waddrmgr.KeyScope) (vote *waddrmgr.NetworkStewardVote, err er.R)
- func (w *Wallet) NewAddress(account uint32, scope waddrmgr.KeyScope) (btcutil.Address, er.R)
- func (w *Wallet) PrivKeyForAddress(a btcutil.Address) (*btcec.PrivateKey, er.R)
- func (w *Wallet) PubKeyForAddress(a btcutil.Address) (*btcec.PublicKey, er.R)
- func (w *Wallet) PublishTransaction(tx *wire.MsgTx, label string) er.R
- func (w *Wallet) PutNetworkStewardVote(accountNumber uint32, scope waddrmgr.KeyScope, ...) er.R
- func (w *Wallet) ReadStats(f func(ws *btcjson.WalletStats))
- func (w *Wallet) ReleaseOutput(id wtxmgr.LockID, op wire.OutPoint) er.R
- func (w *Wallet) ResetLockedOutpoints(lockName *string)
- func (w *Wallet) ResyncChain(fromHeight, toHeight int32, addresses []string, dropDb bool) er.R
- func (w *Wallet) SendOutputs(txr CreateTxReq) (*txauthor.AuthoredTx, er.R)
- func (w *Wallet) SetChainSynced(synced bool)
- func (w *Wallet) ShuttingDown() bool
- func (w *Wallet) SignTransaction(tx *wire.MsgTx, hashType params.SigHashType, ...) ([]SignatureError, er.R)
- func (w *Wallet) SortedActivePaymentAddresses() ([]string, er.R)
- func (w *Wallet) Start()
- func (w *Wallet) Stop()
- func (w *Wallet) StopResync() (string, er.R)
- func (w *Wallet) SynchronizeRPC(chainClient chain.Interface)
- func (w *Wallet) TotalReceivedForAddr(addr btcutil.Address, minConf int32) (btcutil.Amount, er.R)
- func (w *Wallet) Unlock(passphrase []byte, lock <-chan time.Time) er.R
- func (w *Wallet) UnlockOutpoint(op wire.OutPoint)
- func (w *Wallet) UpdateStats(f func(ws *btcjson.WalletStats))
- func (w *Wallet) WaitForShutdown()
- func (w *Wallet) WalletMempool() ([]wtxmgr.TxDetails, er.R)
Constants ¶
const ( // InsecurePubPassphrase is the default outer encryption passphrase used // for public data (everything but private keys). Using a non-default // public passphrase can prevent an attacker without the public // passphrase from discovering all past and future wallet addresses if // they gain access to the wallet database. // // NOTE: at time of writing, public encryption only applies to public // data in the waddrmgr namespace. Transactions are not yet encrypted. InsecurePubPassphrase = "public" )
const MaxInputsPerTx = 1460
Maximum number of inputs which will be included in a transaction
const MaxInputsPerTxLegacy = 499
Maximum number of inputs which can be included in a transaction if there is at least one legacy non-segwit input
Variables ¶
var ( // ErrLoaded describes the error condition of attempting to load or // create a wallet when the loader has already done so. ErrLoaded = Err.CodeWithDetail("ErrLoaded", "wallet already loaded") // ErrNotLoaded describes the error condition of attempting to close a // loaded wallet when a wallet has not been loaded. ErrNotLoaded = Err.CodeWithDetail("ErrNotLoaded", "wallet is not loaded") // ErrExists describes the error condition of attempting to create a new // wallet when one exists already. ErrExists = Err.CodeWithDetail("ErrExists", "wallet already exists") )
var ( // ErrWalletShuttingDown is an error returned when we attempt to make a // request to the wallet but it is in the process of or has already shut // down. ErrWalletShuttingDown = Err.CodeWithDetail("ErrWalletShuttingDown", "wallet shutting down") // ErrUnknownTransaction is returned when an attempt is made to label // a transaction that is not known to the wallet. ErrUnknownTransaction = Err.CodeWithDetail("ErrUnknownTransaction", "cannot label transaction not known to wallet") // ErrTxLabelExists is returned when a transaction already has a label // and an attempt has been made to label it without setting overwrite // to true. ErrTxLabelExists = Err.CodeWithDetail("ErrTxLabelExists", "transaction already labelled") )
var Err er.ErrorType = er.NewErrorType("wallet.Err")
var ( // ErrNotMine is an error denoting that a Wallet instance is unable to // spend a specified output. ErrNotMine = er.GenericErrorType.CodeWithDetail("ErrNotMine", "the passed output does not belong to the wallet") )
var InsufficientFundsError = er.GenericErrorType.CodeWithDetail("InsufficientFundsError",
"insufficient funds available to construct transaction")
var TooManyInputsError = er.GenericErrorType.CodeWithDetail("TooManyInputsError",
"unable to construct transaction because there are too many inputs, you may need to fold coins")
var UnconfirmedCoinsError = er.GenericErrorType.CodeWithDetail("UnconfirmedCoinsError",
"unable to construct transaction, there are coins but they are not yet confirmed")
Functions ¶
func Create ¶
func Create(db walletdb.DB, pubPass, privPass []byte, seedInput []byte, seedBirthday time.Time, seedx *seedwords.Seed, params *chaincfg.Params) er.R
Create creates an new wallet, writing it to an empty database. If the passed seed is non-nil, it is used. Otherwise, a secure random seed of the recommended length is generated.
func DropTransactionHistory ¶
DropTransactionHistory completely removes and re-creates the transaction manager namespace from the given wallet database. This can be used to force a full chain rescan of all wallet transaction and UTXO data. User-defined transaction labels can optionally be kept by setting keepLabels to true.
func NilComparator ¶
func NilComparator(a, b interface{}) int
NilComparator compares by txid/index in order to make the red-black tree functions
func PreferBiggest ¶
func PreferBiggest(a, b interface{}) int
PreferBiggest prefers biggest (coin value) outputs first
func PreferOldest ¶
func PreferOldest(a, b interface{}) int
PreferOldest prefers oldest outputs first
func UnstableAPI ¶
func UnstableAPI(w *Wallet) unstableAPI
UnstableAPI exposes additional unstable public APIs for a Wallet. These APIs may be changed or removed at any time. Currently this type exists to ease the transation (particularly for the legacy JSON-RPC server) from using exported manager packages to a unified wallet package that exposes all functionality by itself. New code should not be written using this API.
func WalletDbPath ¶
Types ¶
type AccountBalance ¶
AccountBalance associates a total (zero confirmation) balance with an account. Balances for other minimum confirmation counts require more expensive logic and it is not clear which minimums a client is interested in, so they are not included.
type Balances ¶
type Balances struct { Total btcutil.Amount Spendable btcutil.Amount ImmatureReward btcutil.Amount Unconfirmed btcutil.Amount OutputCount int32 }
Balances records total, spendable (by policy), and immature coinbase reward balance amounts.
type Block ¶
type Block struct { Hash *chainhash.Hash Height int32 Timestamp int64 Transactions []TransactionSummary }
Block contains the properties and all relevant transactions of an attached block.
type BlockIdentifier ¶
type BlockIdentifier struct {
// contains filtered or unexported fields
}
BlockIdentifier identifies a block by either a height or a hash.
func NewBlockIdentifierFromHash ¶
func NewBlockIdentifierFromHash(hash *chainhash.Hash) *BlockIdentifier
NewBlockIdentifierFromHash constructs a BlockIdentifier for a block hash.
func NewBlockIdentifierFromHeight ¶
func NewBlockIdentifierFromHeight(height int32) *BlockIdentifier
NewBlockIdentifierFromHeight constructs a BlockIdentifier for a block height.
type CreateTxReq ¶
type CreditCategory ¶
type CreditCategory byte
CreditCategory describes the type of wallet transaction output. The category of "sent transactions" (debits) is always "send", and is not expressed by this type.
TODO: This is a requirement of the RPC server and should be moved.
const ( CreditReceive CreditCategory = iota CreditGenerate CreditImmature )
These constants define the possible credit categories.
func RecvCategory ¶
RecvCategory returns the category of received credit outputs from a transaction record. The passed block chain height is used to distinguish immature from mature coinbase outputs.
TODO: This is intended for use by the RPC server and should be moved out of this package at a later time.
func (CreditCategory) String ¶
func (c CreditCategory) String() string
String returns the category as a string. This string may be used as the JSON string for categories as part of listtransactions and gettransaction RPC responses.
type GetTransactionsResult ¶
type GetTransactionsResult struct { MinedTransactions []Block UnminedTransactions []TransactionSummary }
GetTransactionsResult is the result of the wallet's GetTransactions method. See GetTransactions for more details.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader implements the creating of new and opening of existing wallets, while providing a callback system for other subsystems to handle the loading of a wallet. This is primarily intended for use by the RPC servers, to enable methods and services which require the wallet when the wallet is loaded by another subsystem.
Loader is safe for concurrent access.
func NewLoader ¶
func NewLoader(chainParams *chaincfg.Params, dbDirPath, walletName string, noFreelistSync bool, recoveryWindow uint32) *Loader
NewLoader constructs a Loader with an optional recovery window. If the recovery window is non-zero, the wallet will attempt to recovery addresses starting from the last SyncedTo height.
func (*Loader) CreateNewWallet ¶
func (l *Loader) CreateNewWallet(pubPassphrase, privPassphrase []byte, seedInput []byte, seedBirthday time.Time, seed *seedwords.Seed) (*Wallet, er.R)
CreateNewWallet creates a new wallet using the provided public and private passphrases. The seed is optional. If non-nil, addresses are derived from this seed. If nil, a secure random seed is generated.
func (*Loader) LoadedWallet ¶
LoadedWallet returns the loaded wallet, if any, and a bool for whether the wallet has been loaded or not. If true, the wallet pointer should be safe to dereference.
func (*Loader) OpenExistingWallet ¶
OpenExistingWallet opens the wallet from the loader's wallet database path and the public passphrase. If the loader is being called by a context where standard input prompts may be used during wallet upgrades, setting canConsolePrompt will enables these prompts.
func (*Loader) RunAfterLoad ¶
RunAfterLoad adds a function to be executed when the loader creates or opens a wallet. Functions are executed in a single goroutine in the order they are added.
func (*Loader) UnloadWallet ¶
UnloadWallet stops the loaded wallet, if any, and closes the wallet database. This returns ErrNotLoaded if the wallet has not been loaded with CreateNewWallet or LoadExistingWallet. The Loader may be reused if this function returns without error.
type NotificationServer ¶
type NotificationServer struct {
// contains filtered or unexported fields
}
NotificationServer is a server that interested clients may hook into to receive notifications of changes in a wallet. A client is created for each registered notification. Clients are guaranteed to receive messages in the order wallet created them, but there is no guaranteed synchronization between different clients.
func (*NotificationServer) TransactionNotifications ¶
func (s *NotificationServer) TransactionNotifications() TransactionNotificationsClient
TransactionNotifications returns a client for receiving TransactionNotifiations notifications over a channel. The channel is unbuffered.
When finished, the Done method should be called on the client to disassociate it from the server.
type PrivKeyTweaker ¶
type PrivKeyTweaker func(*btcec.PrivateKey) (*btcec.PrivateKey, er.R)
PrivKeyTweaker is a function type that can be used to pass in a callback for tweaking a private key before it's used to sign an input.
type SignatureError ¶
SignatureError records the underlying error when validating a transaction input signature.
type SyncerResp ¶
type SyncerResp struct {
// contains filtered or unexported fields
}
type TransactionNotifications ¶
type TransactionNotifications struct { AttachedBlocks []Block DetachedBlocks []*chainhash.Hash UnminedTransactions []TransactionSummary UnminedTransactionHashes []*chainhash.Hash NewBalances []AccountBalance }
TransactionNotifications is a notification of changes to the wallet's transaction set and the current chain tip that wallet is considered to be synced with. All transactions added to the blockchain are organized by the block they were mined in.
During a chain switch, all removed block hashes are included. Detached blocks are sorted in the reverse order they were mined. Attached blocks are sorted in the order mined.
All newly added unmined transactions are included. Removed unmined transactions are not explicitly included. Instead, the hashes of all transactions still unmined are included.
If any transactions were involved, each affected account's new total balance is included.
TODO: Because this includes stuff about blocks and can be fired without any changes to transactions, it needs a better name.
type TransactionNotificationsClient ¶
type TransactionNotificationsClient struct { C <-chan *TransactionNotifications // contains filtered or unexported fields }
TransactionNotificationsClient receives TransactionNotifications from the NotificationServer over the channel C.
func (*TransactionNotificationsClient) Done ¶
func (c *TransactionNotificationsClient) Done()
Done deregisters the client from the server and drains any remaining messages. It must be called exactly once when the client is finished receiving notifications.
type TransactionSummary ¶
type TransactionSummary struct { Hash *chainhash.Hash Transaction []byte MyInputs []TransactionSummaryInput MyOutputs []TransactionSummaryOutput Fee btcutil.Amount Timestamp int64 Label string }
TransactionSummary contains a transaction relevant to the wallet and marks which inputs and outputs were relevant.
type TransactionSummaryInput ¶
type TransactionSummaryInput struct { Index uint32 PreviousAccount uint32 PreviousAmount btcutil.Amount }
TransactionSummaryInput describes a transaction input that is relevant to the wallet. The Index field marks the transaction input index of the transaction (not included here). The PreviousAccount and PreviousAmount fields describe how much this input debits from a wallet account.
type TransactionSummaryOutput ¶
TransactionSummaryOutput describes wallet properties of a transaction output controlled by the wallet. The Index field marks the transaction output index of the transaction (not included here).
type Wallet ¶
type Wallet struct { Manager *waddrmgr.Manager TxStore *wtxmgr.Store NtfnServer *NotificationServer // contains filtered or unexported fields }
Wallet is a structure containing all the components for a complete wallet. It contains the Armory-style key store addresses and keys),
func Open ¶
func Open(db walletdb.DB, pubPass []byte, cbs *waddrmgr.OpenCallbacks, params *chaincfg.Params, recoveryWindow uint32) (*Wallet, er.R)
Open loads an already-created wallet from the passed database and namespaces.
func (*Wallet) AccountAddresses ¶
AccountAddresses returns the addresses for every created address for an account.
func (*Wallet) AccountName ¶
AccountName returns the name of an account.
func (*Wallet) AccountOfAddress ¶
AccountOfAddress finds the account that an address is associated with.
func (*Wallet) AddressInfo ¶
AddressInfo returns detailed information regarding a wallet address.
func (*Wallet) CalculateAddressBalances ¶
func (*Wallet) CalculateBalance ¶
CalculateBalance sums the amounts of all unspent transaction outputs to addresses of a wallet and returns the balance.
If confirmations is 0, all UTXOs, even those not present in a block (height -1), will be used to get the balance. Otherwise, a UTXO must be in a block. If confirmations is 1 or greater, the balance will be calculated based on how many how many blocks include a UTXO.
func (*Wallet) ChainClient ¶
ChainClient returns the optional consensus RPC client associated with the wallet.
This function is unstable and will be removed once sync logic is moved out of the wallet.
func (*Wallet) ChainParams ¶
ChainParams returns the network parameters for the blockchain the wallet belongs to.
func (*Wallet) ChainSynced ¶
ChainSynced returns whether the wallet has been attached to a chain server and synced up to the best block on the main chain.
func (*Wallet) ChangePassphrases ¶
ChangePassphrases modifies the public and private passphrase of the wallet atomically.
func (*Wallet) ChangePrivatePassphrase ¶
ChangePrivatePassphrase attempts to change the passphrase for a wallet from old to new. Changing the passphrase is synchronized with all other address manager locking and unlocking. The lock state will be the same as it was before the password change.
func (*Wallet) ComputeInputScript ¶
func (w *Wallet) ComputeInputScript(tx *wire.MsgTx, output *wire.TxOut, inputIndex int, sigHashes *txscript.TxSigHashes, hashType params.SigHashType, tweaker PrivKeyTweaker) (wire.TxWitness, []byte, er.R)
ComputeInputScript generates a complete InputScript for the passed transaction with the signature as defined within the passed SignDescriptor. This method is capable of generating the proper input script for both regular p2wkh output and p2wkh outputs nested within a regular p2sh output.
func (*Wallet) CreateSimpleTx ¶
func (w *Wallet) CreateSimpleTx(r CreateTxReq) (*txauthor.AuthoredTx, er.R)
CreateSimpleTx creates a new signed transaction spending unspent P2PKH outputs with at least minconf confirmations spending to any number of address/amount pairs. Change and an appropriate transaction fee are automatically included, if necessary. All transaction creation through this function is serialized to prevent the creation of many transactions which spend the same outputs.
NOTE: The dryRun argument can be set true to create a tx that doesn't alter the database. A tx created with this set to true SHOULD NOT be broadcasted.
func (*Wallet) CurrentAddress ¶
CurrentAddress gets the most recently requested Bitcoin payment address from a wallet for a particular key-chain scope. If the address has already been used (there is at least one transaction spending to it in the blockchain or cjdcoind mempool), the next chained address is returned.
func (*Wallet) DumpWIFPrivateKey ¶
DumpWIFPrivateKey returns the WIF encoded private key for a single wallet address.
func (*Wallet) FetchInputInfo ¶
FetchInputInfo queries for the wallet's knowledge of the passed outpoint. If the wallet determines this output is under its control, then the original full transaction, the target txout and the number of confirmations are returned. Otherwise, a non-nil error value of ErrNotMine is returned instead.
func (*Wallet) FinalizePsbt ¶
FinalizePsbt expects a partial transaction with all inputs and outputs fully declared and tries to sign all inputs that belong to the wallet. Our wallet must be the last signer of the transaction. That means, if there are any unsigned non-witness inputs or inputs without UTXO information attached or inputs without witness data that do not belong to the wallet, this method will fail. If no error is returned, the PSBT is ready to be extracted and the final TX within to be broadcast.
NOTE: This method does NOT publish the transaction after it's been finalized successfully.
func (*Wallet) FundPsbt ¶
func (w *Wallet) FundPsbt(packet *psbt.Packet, account uint32, feeSatPerKB btcutil.Amount) (int32, er.R)
FundPsbt creates a fully populated PSBT packet that contains enough inputs to fund the outputs specified in the passed in packet with the specified fee rate. If there is change left, a change output from the wallet is added and the index of the change output is returned. Otherwise no additional output is created and the index -1 is returned.
NOTE: If the packet doesn't contain any inputs, coin selection is performed automatically. If the packet does contain any inputs, it is assumed that full coin selection happened externally and no additional inputs are added. If the specified inputs aren't enough to fund the outputs with the given fee rate, an error is returned.
NOTE: A caller of the method should hold the global coin selection lock of the wallet. However, no UTXO specific lock lease is acquired for any of the selected/validated inputs by this method. It is in the caller's responsibility to lock the inputs before handing the partial transaction out.
func (*Wallet) GetTransactions ¶
func (w *Wallet) GetTransactions( startBlock, endBlock *BlockIdentifier, cancel <-chan struct{}, ) (*GetTransactionsResult, er.R)
GetTransactions returns transaction results between a starting and ending block. Blocks in the block range may be specified by either a height or a hash.
Because this is a possibly lenghtly operation, a cancel channel is provided to cancel the task. If this channel unblocks, the results created thus far will be returned.
Transaction results are organized by blocks in ascending order and unmined transactions in an unspecified order. Mined transactions are saved in a Block structure which records properties about the block.
func (*Wallet) HaveAddress ¶
HaveAddress returns whether the wallet is the owner of the address a.
func (*Wallet) ImportP2SHRedeemScript ¶
ImportP2SHRedeemScript adds a P2SH redeem script to the wallet.
func (*Wallet) ImportP2WSHRedeemScript ¶
ImportP2WSHRedeemScript adds a P2WSH redeem script to the wallet.
func (*Wallet) ImportPrivateKey ¶
func (w *Wallet) ImportPrivateKey(scope waddrmgr.KeyScope, wif *btcutil.WIF, bs *waddrmgr.BlockStamp, rescan bool) (string, er.R)
ImportPrivateKey imports a private key to the wallet and writes the new wallet to disk.
NOTE: If a block stamp is not provided, then the wallet's birthday will be set to the genesis block of the corresponding chain.
func (*Wallet) LabelTransaction ¶
LabelTransaction adds a label to the transaction with the hash provided. The call will fail if the label is too long, or if the transaction already has a label and the overwrite boolean is not set.
func (*Wallet) LeaseOutput ¶
LeaseOutput locks an output to the given ID, preventing it from being available for coin selection. The absolute time of the lock's expiration is returned. The expiration of the lock can be extended by successive invocations of this call.
Outputs can be unlocked before their expiration through `UnlockOutput`. Otherwise, they are unlocked lazily through calls which iterate through all known outputs, e.g., `CalculateBalance`, `ListUnspent`.
If the output is not known, ErrUnknownOutput is returned. If the output has already been locked to a different ID, then ErrOutputAlreadyLocked is returned.
NOTE: This differs from LockOutpoint in that outputs are locked for a limited amount of time and their locks are persisted to disk.
func (*Wallet) ListAddressTransactions ¶
func (w *Wallet) ListAddressTransactions(pkHashes map[string]struct{}) ([]btcjson.ListTransactionsResult, er.R)
ListAddressTransactions returns a slice of objects with details about recorded transactions to or from any address belonging to a set. This is intended to be used for listaddresstransactions RPC replies.
func (*Wallet) ListAllTransactions ¶
func (w *Wallet) ListAllTransactions() ([]btcjson.ListTransactionsResult, er.R)
ListAllTransactions returns a slice of objects with details about a recorded transaction. This is intended to be used for listalltransactions RPC replies.
func (*Wallet) ListSinceBlock ¶
func (w *Wallet) ListSinceBlock(start, end, syncHeight int32) ([]btcjson.ListTransactionsResult, er.R)
ListSinceBlock returns a slice of objects with details about transactions since the given block. If the block is -1 then all transactions are included. This is intended to be used for listsinceblock RPC replies.
func (*Wallet) ListTransactions ¶
ListTransactions returns a slice of objects with details about a recorded transaction. This is intended to be used for listtransactions RPC replies.
func (*Wallet) ListUnspent ¶
func (w *Wallet) ListUnspent(minconf, maxconf int32, addresses map[string]struct{}) ([]*btcjson.ListUnspentResult, er.R)
ListUnspent returns a slice of objects representing the unspent wallet transactions fitting the given criteria. The confirmations will be more than minconf, less than maxconf and if addresses is populated only the addresses contained within it will be considered. If we know nothing about a transaction an empty array will be returned.
func (*Wallet) LockOutpoint ¶
LockOutpoint marks an outpoint as locked, that is, it should not be used as an input for newly created transactions.
func (*Wallet) LockedOutpoint ¶
LockedOutpoint returns whether an outpoint has been marked as locked and should not be used as an input for created transactions.
func (*Wallet) LockedOutpoints ¶
func (w *Wallet) LockedOutpoints() []btcjson.LockedUnspent
LockedOutpoints returns a slice of currently locked outpoints. This is intended to be used by marshaling the result as a JSON array for listlockunspent RPC results.
func (*Wallet) MakeMultiSigScript ¶
MakeMultiSigScript creates a multi-signature script that can be redeemed with nRequired signatures of the passed keys and addresses. If the address is a P2PKH address, the associated pubkey is looked up by the wallet if possible, otherwise an error is returned for a missing pubkey.
This function only works with pubkeys and P2PKH addresses derived from them.
func (*Wallet) NetworkStewardVote ¶
func (w *Wallet) NetworkStewardVote(accountNumber uint32, scope waddrmgr.KeyScope) (vote *waddrmgr.NetworkStewardVote, err er.R)
NetworkStewardVote gets the network steward which this account is voting for
func (*Wallet) NewAddress ¶
NewAddress returns the next external chained address for a wallet.
func (*Wallet) PrivKeyForAddress ¶
PrivKeyForAddress looks up the associated private key for a P2PKH or P2PK address.
func (*Wallet) PubKeyForAddress ¶
PubKeyForAddress looks up the associated public key for a P2PKH address.
func (*Wallet) PublishTransaction ¶
PublishTransaction sends the transaction to the consensus RPC server so it can be propagated to other nodes and eventually mined.
This function is unstable and will be removed once syncing code is moved out of the wallet.
func (*Wallet) PutNetworkStewardVote ¶
func (w *Wallet) PutNetworkStewardVote(accountNumber uint32, scope waddrmgr.KeyScope, vote *waddrmgr.NetworkStewardVote) er.R
PutNetworkStewardVote gets the network steward which this account is voting for
func (*Wallet) ReadStats ¶
func (w *Wallet) ReadStats(f func(ws *btcjson.WalletStats))
func (*Wallet) ReleaseOutput ¶
ReleaseOutput unlocks an output, allowing it to be available for coin selection if it remains unspent. The ID should match the one used to originally lock the output.
func (*Wallet) ResetLockedOutpoints ¶
ResetLockedOutpoints resets the set of locked outpoints so all may be used as inputs for new transactions.
func (*Wallet) ResyncChain ¶
ResyncChain re-synchronizes the wallet from the very first block
func (*Wallet) SendOutputs ¶
func (w *Wallet) SendOutputs(txr CreateTxReq) (*txauthor.AuthoredTx, er.R)
SendOutputs creates and sends payment transactions. It returns the transaction upon success.
func (*Wallet) SetChainSynced ¶
SetChainSynced marks whether the wallet is connected to and currently in sync with the latest block notified by the chain server.
NOTE: Due to an API limitation with rpcclient, this may return true after the client disconnected (and is attempting a reconnect). This will be unknown until the reconnect notification is received, at which point the wallet can be marked out of sync again until after the next rescan completes.
func (*Wallet) ShuttingDown ¶
ShuttingDown returns whether the wallet is currently in the process of shutting down or not.
func (*Wallet) SignTransaction ¶
func (w *Wallet) SignTransaction(tx *wire.MsgTx, hashType params.SigHashType, additionalPrevScripts map[wire.OutPoint][]byte, additionalKeysByAddress map[string]*btcutil.WIF, p2shRedeemScriptsByAddress map[string][]byte, ) ([]SignatureError, er.R)
SignTransaction uses secrets of the wallet, as well as additional secrets passed in by the caller, to create and add input signatures to a transaction.
Transaction input script validation is used to confirm that all signatures are valid. For any invalid input, a SignatureError is added to the returns. The final error return is reserved for unexpected or fatal errors, such as being unable to determine a previous output script to redeem.
The transaction pointed to by tx is modified by this function.
func (*Wallet) SortedActivePaymentAddresses ¶
SortedActivePaymentAddresses returns a slice of all active payment addresses in a wallet.
func (*Wallet) Start ¶
func (w *Wallet) Start()
Start starts the goroutines necessary to manage a wallet.
func (*Wallet) SynchronizeRPC ¶
SynchronizeRPC associates the wallet with the consensus RPC client, synchronizes the wallet with the latest changes to the blockchain, and continuously updates the wallet through RPC notifications.
This method is unstable and will be removed when all syncing logic is moved outside of the wallet package.
func (*Wallet) TotalReceivedForAddr ¶
TotalReceivedForAddr iterates through a wallet's transaction history, returning the total amount of bitcoins received for a single wallet address.
func (*Wallet) Unlock ¶
Unlock unlocks the wallet's address manager and relocks it after timeout has expired. If the wallet is already unlocked and the new passphrase is correct, the current timeout is replaced with the new one. The wallet will be locked if the passphrase is incorrect or any other error occurs during the unlock.
func (*Wallet) UnlockOutpoint ¶
UnlockOutpoint marks an outpoint as unlocked, that is, it may be used as an input for newly created transactions.
func (*Wallet) UpdateStats ¶
func (w *Wallet) UpdateStats(f func(ws *btcjson.WalletStats))
func (*Wallet) WaitForShutdown ¶
func (w *Wallet) WaitForShutdown()
WaitForShutdown blocks until all wallet goroutines have finished executing.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
Package txauthor provides transaction creation code for wallets.
|
Package txauthor provides transaction creation code for wallets. |
Package txrules provides transaction rules that should be followed by transaction authors for wide mempool acceptance and quick mining.
|
Package txrules provides transaction rules that should be followed by transaction authors for wide mempool acceptance and quick mining. |