Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
Wallet Class Referenceabstract

Interface for accessing a wallet. More...

#include <wallet.h>

Public Types

using CoinsList = std::map<CTxDestination, std::vector<std::tuple<COutPoint, WalletTxOut>>>
using UnloadFn = std::function<void()>
 Register handler for unload message.
using ShowProgressFn = std::function<void(const std::string& title, int progress)>
 Register handler for show progress messages.
using StatusChangedFn = std::function<void()>
 Register handler for status changed messages.
using AddressBookChangedFn
 Register handler for address book changed messages.
using TransactionChangedFn = std::function<void(const Txid& txid, ChangeType status)>
 Register handler for transaction changed messages.
using CanGetAddressesChangedFn = std::function<void()>
 Register handler for keypool changed messages.

Public Member Functions

virtual ~Wallet ()=default
virtual bool encryptWallet (const SecureString &wallet_passphrase)=0
 Encrypt wallet.
virtual bool isCrypted ()=0
 Return whether wallet is encrypted.
virtual bool lock ()=0
 Lock wallet.
virtual bool unlock (const SecureString &wallet_passphrase)=0
 Unlock wallet.
virtual bool isLocked ()=0
 Return whether wallet is locked.
virtual bool changeWalletPassphrase (const SecureString &old_wallet_passphrase, const SecureString &new_wallet_passphrase)=0
 Change wallet passphrase.
virtual void abortRescan ()=0
 Abort a rescan.
virtual bool backupWallet (const std::string &filename)=0
 Back up wallet.
virtual std::string getWalletName ()=0
 Get wallet name.
virtual util::Result< CTxDestinationgetNewDestination (OutputType type, const std::string &label)=0
virtual bool getPubKey (const CScript &script, const CKeyID &address, CPubKey &pub_key)=0
 Get public key.
virtual SigningResult signMessage (const std::string &message, const PKHash &pkhash, std::string &str_sig)=0
 Sign message.
virtual bool isSpendable (const CTxDestination &dest)=0
 Return whether wallet has private key.
virtual bool setAddressBook (const CTxDestination &dest, const std::string &name, const std::optional< wallet::AddressPurpose > &purpose)=0
 Add or update address.
virtual bool delAddressBook (const CTxDestination &dest)=0
virtual bool getAddress (const CTxDestination &dest, std::string *name, wallet::AddressPurpose *purpose)=0
 Look up address in wallet, return whether exists.
virtual std::vector< WalletAddressgetAddresses ()=0
 Get wallet address list.
virtual std::vector< std::string > getAddressReceiveRequests ()=0
 Get receive requests.
virtual bool setAddressReceiveRequest (const CTxDestination &dest, const std::string &id, const std::string &value)=0
 Save or remove receive request.
virtual util::Result< void > displayAddress (const CTxDestination &dest)=0
 Display address on external signer.
virtual bool lockCoin (const COutPoint &output, bool write_to_db)=0
 Lock coin.
virtual bool unlockCoin (const COutPoint &output)=0
 Unlock coin.
virtual bool isLockedCoin (const COutPoint &output)=0
 Return whether coin is locked.
virtual void listLockedCoins (std::vector< COutPoint > &outputs)=0
 List locked coins.
virtual util::Result< wallet::CreatedTransactionResultcreateTransaction (const std::vector< wallet::CRecipient > &recipients, const wallet::CCoinControl &coin_control, bool sign, std::optional< unsigned int > change_pos)=0
 Create transaction.
virtual void commitTransaction (CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
 Commit transaction.
virtual bool transactionCanBeAbandoned (const Txid &txid)=0
 Return whether transaction can be abandoned.
virtual bool abandonTransaction (const Txid &txid)=0
 Abandon transaction.
virtual bool transactionCanBeBumped (const Txid &txid)=0
 Return whether transaction can be bumped.
virtual bool createBumpTransaction (const Txid &txid, const wallet::CCoinControl &coin_control, std::vector< bilingual_str > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)=0
 Create bump transaction.
virtual bool signBumpTransaction (CMutableTransaction &mtx)=0
 Sign bump transaction.
virtual bool commitBumpTransaction (const Txid &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, Txid &bumped_txid)=0
 Commit bump transaction.
virtual CTransactionRef getTx (const Txid &txid)=0
 Get a transaction.
virtual WalletTx getWalletTx (const Txid &txid)=0
 Get transaction information.
virtual std::set< WalletTxgetWalletTxs ()=0
 Get list of all wallet transactions.
virtual bool tryGetTxStatus (const Txid &txid, WalletTxStatus &tx_status, int &num_blocks, int64_t &block_time)=0
 Try to get updated status for a particular transaction, if possible without blocking.
virtual WalletTx getWalletTxDetails (const Txid &txid, WalletTxStatus &tx_status, WalletOrderForm &order_form, bool &in_mempool, int &num_blocks)=0
 Get transaction details.
virtual std::optional< common::PSBTErrorfillPSBT (std::optional< int > sighash_type, bool sign, bool bip32derivs, size_t *n_signed, PartiallySignedTransaction &psbtx, bool &complete)=0
 Fill PSBT.
virtual WalletBalances getBalances ()=0
 Get balances.
virtual bool tryGetBalances (WalletBalances &balances, uint256 &block_hash)=0
 Get balances if possible without blocking.
virtual CAmount getBalance ()=0
 Get balance.
virtual CAmount getAvailableBalance (const wallet::CCoinControl &coin_control)=0
 Get available balance.
virtual bool txinIsMine (const CTxIn &txin)=0
 Return whether transaction input belongs to wallet.
virtual bool txoutIsMine (const CTxOut &txout)=0
 Return whether transaction output belongs to wallet.
virtual CAmount getDebit (const CTxIn &txin)=0
 Return debit amount if transaction input belongs to wallet.
virtual CAmount getCredit (const CTxOut &txout)=0
 Return credit amount if transaction input belongs to wallet.
virtual CoinsList listCoins ()=0
virtual std::vector< WalletTxOutgetCoins (const std::vector< COutPoint > &outputs)=0
 Return wallet transaction output information.
virtual CAmount getRequiredFee (unsigned int tx_bytes)=0
 Get required fee.
virtual CAmount getMinimumFee (unsigned int tx_bytes, const wallet::CCoinControl &coin_control, int *returned_target, FeeReason *reason)=0
 Get minimum fee.
virtual unsigned int getConfirmTarget ()=0
 Get tx confirm target.
virtual bool hdEnabled ()=0
virtual bool canGetAddresses ()=0
virtual bool privateKeysDisabled ()=0
virtual bool taprootEnabled ()=0
virtual bool hasExternalSigner ()=0
virtual OutputType getDefaultAddressType ()=0
virtual CAmount getDefaultMaxTxFee ()=0
 Get max tx fee.
virtual void remove ()=0
virtual std::unique_ptr< HandlerhandleUnload (UnloadFn fn)=0
virtual std::unique_ptr< HandlerhandleShowProgress (ShowProgressFn fn)=0
virtual std::unique_ptr< HandlerhandleStatusChanged (StatusChangedFn fn)=0
virtual std::unique_ptr< HandlerhandleAddressBookChanged (AddressBookChangedFn fn)=0
virtual std::unique_ptr< HandlerhandleTransactionChanged (TransactionChangedFn fn)=0
virtual std::unique_ptr< HandlerhandleCanGetAddressesChanged (CanGetAddressesChangedFn fn)=0
virtual wallet::CWalletwallet ()
 Return pointer to internal wallet class, useful for testing.

Detailed Description

Interface for accessing a wallet.

Definition at line 65 of file wallet.h.

Member Typedef Documentation

◆ AddressBookChangedFn

Initial value:
std::function<void(const CTxDestination& address,
const std::string& label,
bool is_mine,
ChangeType status)>
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
Definition types.h:28
ChangeType
General change type (added, updated, removed).

Register handler for address book changed messages.

Definition at line 293 of file wallet.h.

◆ CanGetAddressesChangedFn

using interfaces::Wallet::CanGetAddressesChangedFn = std::function<void()>

Register handler for keypool changed messages.

Definition at line 305 of file wallet.h.

◆ CoinsList

using interfaces::Wallet::CoinsList = std::map<CTxDestination, std::vector<std::tuple<COutPoint, WalletTxOut>>>

Return AvailableCoins + LockedCoins grouped by wallet address. (put change in one group with wallet address)

Definition at line 238 of file wallet.h.

◆ ShowProgressFn

using interfaces::Wallet::ShowProgressFn = std::function<void(const std::string& title, int progress)>

Register handler for show progress messages.

Definition at line 285 of file wallet.h.

◆ StatusChangedFn

using interfaces::Wallet::StatusChangedFn = std::function<void()>

Register handler for status changed messages.

Definition at line 289 of file wallet.h.

◆ TransactionChangedFn

using interfaces::Wallet::TransactionChangedFn = std::function<void(const Txid& txid, ChangeType status)>

Register handler for transaction changed messages.

Definition at line 301 of file wallet.h.

◆ UnloadFn

using interfaces::Wallet::UnloadFn = std::function<void()>

Register handler for unload message.

Definition at line 281 of file wallet.h.

Constructor & Destructor Documentation

◆ ~Wallet()

virtual interfaces::Wallet::~Wallet ( )
virtualdefault

Member Function Documentation

◆ abandonTransaction()

virtual bool interfaces::Wallet::abandonTransaction ( const Txid & txid)
pure virtual

Abandon transaction.

◆ abortRescan()

virtual void interfaces::Wallet::abortRescan ( )
pure virtual

Abort a rescan.

◆ backupWallet()

virtual bool interfaces::Wallet::backupWallet ( const std::string & filename)
pure virtual

Back up wallet.

◆ canGetAddresses()

virtual bool interfaces::Wallet::canGetAddresses ( )
pure virtual

◆ changeWalletPassphrase()

virtual bool interfaces::Wallet::changeWalletPassphrase ( const SecureString & old_wallet_passphrase,
const SecureString & new_wallet_passphrase )
pure virtual

Change wallet passphrase.

◆ commitBumpTransaction()

virtual bool interfaces::Wallet::commitBumpTransaction ( const Txid & txid,
CMutableTransaction && mtx,
std::vector< bilingual_str > & errors,
Txid & bumped_txid )
pure virtual

Commit bump transaction.

◆ commitTransaction()

virtual void interfaces::Wallet::commitTransaction ( CTransactionRef tx,
WalletValueMap value_map,
WalletOrderForm order_form )
pure virtual

Commit transaction.

◆ createBumpTransaction()

virtual bool interfaces::Wallet::createBumpTransaction ( const Txid & txid,
const wallet::CCoinControl & coin_control,
std::vector< bilingual_str > & errors,
CAmount & old_fee,
CAmount & new_fee,
CMutableTransaction & mtx )
pure virtual

Create bump transaction.

◆ createTransaction()

virtual util::Result< wallet::CreatedTransactionResult > interfaces::Wallet::createTransaction ( const std::vector< wallet::CRecipient > & recipients,
const wallet::CCoinControl & coin_control,
bool sign,
std::optional< unsigned int > change_pos )
pure virtual

Create transaction.

◆ delAddressBook()

virtual bool interfaces::Wallet::delAddressBook ( const CTxDestination & dest)
pure virtual

◆ displayAddress()

virtual util::Result< void > interfaces::Wallet::displayAddress ( const CTxDestination & dest)
pure virtual

Display address on external signer.

◆ encryptWallet()

virtual bool interfaces::Wallet::encryptWallet ( const SecureString & wallet_passphrase)
pure virtual

Encrypt wallet.

◆ fillPSBT()

virtual std::optional< common::PSBTError > interfaces::Wallet::fillPSBT ( std::optional< int > sighash_type,
bool sign,
bool bip32derivs,
size_t * n_signed,
PartiallySignedTransaction & psbtx,
bool & complete )
pure virtual

Fill PSBT.

◆ getAddress()

virtual bool interfaces::Wallet::getAddress ( const CTxDestination & dest,
std::string * name,
wallet::AddressPurpose * purpose )
pure virtual

Look up address in wallet, return whether exists.

◆ getAddresses()

virtual std::vector< WalletAddress > interfaces::Wallet::getAddresses ( )
pure virtual

Get wallet address list.

◆ getAddressReceiveRequests()

virtual std::vector< std::string > interfaces::Wallet::getAddressReceiveRequests ( )
pure virtual

Get receive requests.

◆ getAvailableBalance()

virtual CAmount interfaces::Wallet::getAvailableBalance ( const wallet::CCoinControl & coin_control)
pure virtual

Get available balance.

◆ getBalance()

virtual CAmount interfaces::Wallet::getBalance ( )
pure virtual

Get balance.

◆ getBalances()

Get balances.

◆ getCoins()

virtual std::vector< WalletTxOut > interfaces::Wallet::getCoins ( const std::vector< COutPoint > & outputs)
pure virtual

Return wallet transaction output information.

◆ getConfirmTarget()

virtual unsigned int interfaces::Wallet::getConfirmTarget ( )
pure virtual

Get tx confirm target.

◆ getCredit()

virtual CAmount interfaces::Wallet::getCredit ( const CTxOut & txout)
pure virtual

Return credit amount if transaction input belongs to wallet.

◆ getDebit()

virtual CAmount interfaces::Wallet::getDebit ( const CTxIn & txin)
pure virtual

Return debit amount if transaction input belongs to wallet.

◆ getDefaultAddressType()

◆ getDefaultMaxTxFee()

Get max tx fee.

◆ getMinimumFee()

virtual CAmount interfaces::Wallet::getMinimumFee ( unsigned int tx_bytes,
const wallet::CCoinControl & coin_control,
int * returned_target,
FeeReason * reason )
pure virtual

Get minimum fee.

◆ getNewDestination()

virtual util::Result< CTxDestination > interfaces::Wallet::getNewDestination ( OutputType type,
const std::string & label )
pure virtual

◆ getPubKey()

virtual bool interfaces::Wallet::getPubKey ( const CScript & script,
const CKeyID & address,
CPubKey & pub_key )
pure virtual

Get public key.

◆ getRequiredFee()

virtual CAmount interfaces::Wallet::getRequiredFee ( unsigned int tx_bytes)
pure virtual

Get required fee.

◆ getTx()

virtual CTransactionRef interfaces::Wallet::getTx ( const Txid & txid)
pure virtual

Get a transaction.

◆ getWalletName()

virtual std::string interfaces::Wallet::getWalletName ( )
pure virtual

Get wallet name.

◆ getWalletTx()

virtual WalletTx interfaces::Wallet::getWalletTx ( const Txid & txid)
pure virtual

Get transaction information.

◆ getWalletTxDetails()

virtual WalletTx interfaces::Wallet::getWalletTxDetails ( const Txid & txid,
WalletTxStatus & tx_status,
WalletOrderForm & order_form,
bool & in_mempool,
int & num_blocks )
pure virtual

Get transaction details.

◆ getWalletTxs()

virtual std::set< WalletTx > interfaces::Wallet::getWalletTxs ( )
pure virtual

Get list of all wallet transactions.

◆ handleAddressBookChanged()

virtual std::unique_ptr< Handler > interfaces::Wallet::handleAddressBookChanged ( AddressBookChangedFn fn)
pure virtual

◆ handleCanGetAddressesChanged()

◆ handleShowProgress()

virtual std::unique_ptr< Handler > interfaces::Wallet::handleShowProgress ( ShowProgressFn fn)
pure virtual

◆ handleStatusChanged()

virtual std::unique_ptr< Handler > interfaces::Wallet::handleStatusChanged ( StatusChangedFn fn)
pure virtual

◆ handleTransactionChanged()

virtual std::unique_ptr< Handler > interfaces::Wallet::handleTransactionChanged ( TransactionChangedFn fn)
pure virtual

◆ handleUnload()

virtual std::unique_ptr< Handler > interfaces::Wallet::handleUnload ( UnloadFn fn)
pure virtual

◆ hasExternalSigner()

virtual bool interfaces::Wallet::hasExternalSigner ( )
pure virtual

◆ hdEnabled()

virtual bool interfaces::Wallet::hdEnabled ( )
pure virtual

◆ isCrypted()

virtual bool interfaces::Wallet::isCrypted ( )
pure virtual

Return whether wallet is encrypted.

◆ isLocked()

virtual bool interfaces::Wallet::isLocked ( )
pure virtual

Return whether wallet is locked.

◆ isLockedCoin()

virtual bool interfaces::Wallet::isLockedCoin ( const COutPoint & output)
pure virtual

Return whether coin is locked.

◆ isSpendable()

virtual bool interfaces::Wallet::isSpendable ( const CTxDestination & dest)
pure virtual

Return whether wallet has private key.

◆ listCoins()

virtual CoinsList interfaces::Wallet::listCoins ( )
pure virtual

◆ listLockedCoins()

virtual void interfaces::Wallet::listLockedCoins ( std::vector< COutPoint > & outputs)
pure virtual

List locked coins.

◆ lock()

virtual bool interfaces::Wallet::lock ( )
pure virtual

Lock wallet.

◆ lockCoin()

virtual bool interfaces::Wallet::lockCoin ( const COutPoint & output,
bool write_to_db )
pure virtual

Lock coin.

◆ privateKeysDisabled()

virtual bool interfaces::Wallet::privateKeysDisabled ( )
pure virtual

◆ remove()

virtual void interfaces::Wallet::remove ( )
pure virtual

◆ setAddressBook()

virtual bool interfaces::Wallet::setAddressBook ( const CTxDestination & dest,
const std::string & name,
const std::optional< wallet::AddressPurpose > & purpose )
pure virtual

Add or update address.

◆ setAddressReceiveRequest()

virtual bool interfaces::Wallet::setAddressReceiveRequest ( const CTxDestination & dest,
const std::string & id,
const std::string & value )
pure virtual

Save or remove receive request.

◆ signBumpTransaction()

Sign bump transaction.

◆ signMessage()

virtual SigningResult interfaces::Wallet::signMessage ( const std::string & message,
const PKHash & pkhash,
std::string & str_sig )
pure virtual

Sign message.

◆ taprootEnabled()

virtual bool interfaces::Wallet::taprootEnabled ( )
pure virtual

◆ transactionCanBeAbandoned()

virtual bool interfaces::Wallet::transactionCanBeAbandoned ( const Txid & txid)
pure virtual

Return whether transaction can be abandoned.

◆ transactionCanBeBumped()

virtual bool interfaces::Wallet::transactionCanBeBumped ( const Txid & txid)
pure virtual

Return whether transaction can be bumped.

◆ tryGetBalances()

virtual bool interfaces::Wallet::tryGetBalances ( WalletBalances & balances,
uint256 & block_hash )
pure virtual

Get balances if possible without blocking.

◆ tryGetTxStatus()

virtual bool interfaces::Wallet::tryGetTxStatus ( const Txid & txid,
WalletTxStatus & tx_status,
int & num_blocks,
int64_t & block_time )
pure virtual

Try to get updated status for a particular transaction, if possible without blocking.

◆ txinIsMine()

virtual bool interfaces::Wallet::txinIsMine ( const CTxIn & txin)
pure virtual

Return whether transaction input belongs to wallet.

◆ txoutIsMine()

virtual bool interfaces::Wallet::txoutIsMine ( const CTxOut & txout)
pure virtual

Return whether transaction output belongs to wallet.

◆ unlock()

virtual bool interfaces::Wallet::unlock ( const SecureString & wallet_passphrase)
pure virtual

Unlock wallet.

◆ unlockCoin()

virtual bool interfaces::Wallet::unlockCoin ( const COutPoint & output)
pure virtual

Unlock coin.

◆ wallet()

virtual wallet::CWallet * interfaces::Wallet::wallet ( )
inlinevirtual

Return pointer to internal wallet class, useful for testing.

Definition at line 309 of file wallet.h.


The documentation for this class was generated from the following file: