59    for (
const auto& txin : wtx.
tx->vin) {
 
   65    for (
const auto& txout : wtx.
tx->vout) {
 
  105    result.
txout = wtx.
tx->vout[n];
 
  112class WalletImpl : 
public Wallet 
  117    bool encryptWallet(
const SecureString& wallet_passphrase)
 override 
  119        return m_wallet->EncryptWallet(wallet_passphrase);
 
  121    bool isCrypted()
 override { 
return m_wallet->IsCrypted(); }
 
  122    bool lock()
 override { 
return m_wallet->Lock(); }
 
  123    bool unlock(
const SecureString& wallet_passphrase)
 override { 
return m_wallet->Unlock(wallet_passphrase); }
 
  124    bool isLocked()
 override { 
return m_wallet->IsLocked(); }
 
  125    bool changeWalletPassphrase(
const SecureString& old_wallet_passphrase,
 
  128        return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
 
  130    void abortRescan()
 override { 
m_wallet->AbortRescan(); }
 
  131    bool backupWallet(
const std::string& filename)
 override { 
return m_wallet->BackupWallet(filename); }
 
  132    std::string getWalletName()
 override { 
return m_wallet->GetName(); }
 
  137        return m_wallet->GetNewDestination(type, label, dest, 
error);
 
  141        std::unique_ptr<SigningProvider> provider = 
m_wallet->GetSolvingProvider(script);
 
  143            return provider->GetPubKey(address, pub_key);
 
  147    SigningResult signMessage(
const std::string& message, 
const PKHash& pkhash, std::string& str_sig)
 override 
  149        return m_wallet->SignMessage(message, pkhash, str_sig);
 
  156    bool haveWatchOnly()
 override 
  158        auto spk_man = 
m_wallet->GetLegacyScriptPubKeyMan();
 
  160            return spk_man->HaveWatchOnly();
 
  164    bool setAddressBook(
const CTxDestination& dest, 
const std::string& 
name, 
const std::string& purpose)
 override 
  170        return m_wallet->DelAddressBook(dest);
 
  175        std::string* purpose)
 override 
  178        auto it = 
m_wallet->m_address_book.find(dest);
 
  179        if (it == 
m_wallet->m_address_book.end() || it->second.IsChange()) {
 
  183            *
name = it->second.GetLabel();
 
  189            *purpose = it->second.purpose;
 
  193    std::vector<WalletAddress> getAddresses()
 override 
  196        std::vector<WalletAddress> result;
 
  197        for (
const auto& item : 
m_wallet->m_address_book) {
 
  198            if (item.second.IsChange()) 
continue;
 
  199            result.emplace_back(item.first, 
m_wallet->IsMine(item.first), item.second.GetLabel(), item.second.purpose);
 
  203    std::vector<std::string> getAddressReceiveRequests()
 override {
 
  205        return m_wallet->GetAddressReceiveRequests();
 
  207    bool setAddressReceiveRequest(
const CTxDestination& dest, 
const std::string& 
id, 
const std::string& value)
 override {
 
  210        return m_wallet->SetAddressReceiveRequest(batch, dest, 
id, value);
 
  215        return m_wallet->DisplayAddress(dest);
 
  217    bool lockCoin(
const COutPoint& output, 
const bool write_to_db)
 override 
  220        std::unique_ptr<WalletBatch> batch = write_to_db ? std::make_unique<WalletBatch>(
m_wallet->GetDatabase()) : 
nullptr;
 
  221        return m_wallet->LockCoin(output, batch.get());
 
  223    bool unlockCoin(
const COutPoint& output)
 override 
  226        std::unique_ptr<WalletBatch> batch = std::make_unique<WalletBatch>(
m_wallet->GetDatabase());
 
  227        return m_wallet->UnlockCoin(output, batch.get());
 
  229    bool isLockedCoin(
const COutPoint& output)
 override 
  234    void listLockedCoins(std::vector<COutPoint>& outputs)
 override 
  237        return m_wallet->ListLockedCoins(outputs);
 
  239    CTransactionRef createTransaction(
const std::vector<CRecipient>& recipients,
 
  250                fail_reason, coin_control, fee_calc_out, sign)) {
 
  260        m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
 
  262    bool transactionCanBeAbandoned(
const uint256& txid)
 override { 
return m_wallet->TransactionCanBeAbandoned(txid); }
 
  263    bool abandonTransaction(
const uint256& txid)
 override 
  266        return m_wallet->AbandonTransaction(txid);
 
  268    bool transactionCanBeBumped(
const uint256& txid)
 override 
  272    bool createBumpTransaction(
const uint256& txid,
 
  274        std::vector<bilingual_str>& errors,
 
  282    bool commitBumpTransaction(
const uint256& txid,
 
  284        std::vector<bilingual_str>& errors,
 
  293        auto mi = 
m_wallet->mapWallet.find(txid);
 
  294        if (mi != 
m_wallet->mapWallet.end()) {
 
  295            return mi->second.tx;
 
  302        auto mi = 
m_wallet->mapWallet.find(txid);
 
  303        if (mi != 
m_wallet->mapWallet.end()) {
 
  304            return MakeWalletTx(*
m_wallet, mi->second);
 
  308    std::vector<WalletTx> getWalletTxs()
 override 
  311        std::vector<WalletTx> result;
 
  312        result.reserve(
m_wallet->mapWallet.size());
 
  313        for (
const auto& entry : 
m_wallet->mapWallet) {
 
  314            result.emplace_back(MakeWalletTx(*
m_wallet, entry.second));
 
  318    bool tryGetTxStatus(
const uint256& txid,
 
  321        int64_t& block_time)
 override 
  324        if (!locked_wallet) {
 
  327        auto mi = 
m_wallet->mapWallet.find(txid);
 
  328        if (mi == 
m_wallet->mapWallet.end()) {
 
  331        num_blocks = 
m_wallet->GetLastBlockHeight();
 
  334        tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
 
  341        int& num_blocks)
 override 
  344        auto mi = 
m_wallet->mapWallet.find(txid);
 
  345        if (mi != 
m_wallet->mapWallet.end()) {
 
  346            num_blocks = 
m_wallet->GetLastBlockHeight();
 
  347            in_mempool = mi->second.InMempool();
 
  348            order_form = mi->second.vOrderForm;
 
  349            tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
 
  350            return MakeWalletTx(*
m_wallet, mi->second);
 
  359        bool& complete)
 override 
  361        return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs, n_signed);
 
  367        result.
balance = bal.m_mine_trusted;
 
  381        if (!locked_wallet) {
 
  384        block_hash = 
m_wallet->GetLastBlockHash();
 
  385        balances = getBalances();
 
  406        return m_wallet->GetDebit(txin, filter);
 
  413    CoinsList listCoins()
 override 
  418            auto& group = result[entry.first];
 
  419            for (
const auto& coin : entry.second) {
 
  420                group.emplace_back(
COutPoint(coin.tx->GetHash(), coin.i),
 
  421                    MakeWalletTxOut(*
m_wallet, *coin.tx, coin.i, coin.nDepth));
 
  426    std::vector<WalletTxOut> getCoins(
const std::vector<COutPoint>& outputs)
 override 
  429        std::vector<WalletTxOut> result;
 
  430        result.reserve(outputs.size());
 
  431        for (
const auto& output : outputs) {
 
  432            result.emplace_back();
 
  434            if (it != 
m_wallet->mapWallet.end()) {
 
  435                int depth = 
m_wallet->GetTxDepthInMainChain(it->second);
 
  437                    result.back() = MakeWalletTxOut(*
m_wallet, it->second, output.
n, depth);
 
  444    CAmount getMinimumFee(
unsigned int tx_bytes,
 
  446        int* returned_target,
 
  453        if (reason) *reason = fee_calc.
reason;
 
  456    unsigned int getConfirmTarget()
 override { 
return m_wallet->m_confirm_target; }
 
  457    bool hdEnabled()
 override { 
return m_wallet->IsHDEnabled(); }
 
  458    bool canGetAddresses()
 override { 
return m_wallet->CanGetAddresses(); }
 
  461    OutputType getDefaultAddressType()
 override { 
return m_wallet->m_default_address_type; }
 
  462    CAmount getDefaultMaxTxFee()
 override { 
return m_wallet->m_default_max_tx_fee; }
 
  463    void remove()
 override 
  467    bool isLegacy()
 override { 
return m_wallet->IsLegacy(); }
 
  468    std::unique_ptr<Handler> handleUnload(UnloadFn fn)
 override 
  472    std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn)
 override 
  476    std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn)
 override 
  480    std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn)
 override 
  483            [fn](
const CTxDestination& address, 
const std::string& label, 
bool is_mine,
 
  484                 const std::string& purpose, 
ChangeType status) { fn(address, label, is_mine, purpose, status); }));
 
  486    std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn)
 override 
  491    std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn)
 override 
  495    std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
 override 
  516    void registerRpcs()
 override 
  520                JSONRPCRequest wallet_request = request;
 
  521                wallet_request.context = &m_context;
 
  522                return command.actor(wallet_request, result, last_handler);
 
  523            }, command.argNames, command.unique_id);
 
  532    void setMockTime(int64_t time)
 override { 
return SetMockTime(time); }
 
  535    std::unique_ptr<Wallet> createWallet(
const std::string& 
name, 
const SecureString& passphrase, uint64_t wallet_creation_flags, 
bilingual_str& 
error, std::vector<bilingual_str>& warnings)
 override 
  537        std::shared_ptr<CWallet> 
wallet;
 
  545    std::unique_ptr<Wallet> loadWallet(
const std::string& 
name, 
bilingual_str& 
error, std::vector<bilingual_str>& warnings)
 override 
  552    std::string getWalletDir()
 override 
  556    std::vector<std::string> listWalletDir()
 override 
  558        std::vector<std::string> paths;
 
  564    std::vector<std::unique_ptr<Wallet>> getWallets()
 override 
  566        std::vector<std::unique_ptr<Wallet>> wallets;
 
  572    std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
 override 
  591    return std::make_unique<wallet::WalletClientImpl>(chain, args);
 
int64_t CAmount
Amount in satoshis (Can be negative)
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
A reference to a CKey: the Hash160 of its serialized public key.
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
Simple class for background tasks that should be run periodically or once "after a while".
Serialized script, used inside transaction inputs and outputs.
An input of a transaction.
An output of a transaction.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
mapValue_t mapValue
Key/value map with information about the transaction.
const uint256 & GetHash() const
int64_t GetTxTime() const
unsigned int nTimeReceived
time received by this node
Access to the wallet database.
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Helper for findBlock to selectively return pieces of block data.
Generic interface for managing an event handler or callback function registered with another interfac...
Wallet chain client that in addition to having chain client methods for starting up,...
Interface for accessing a wallet.
std::vector< fs::path > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
void FlushWallets(WalletContext &context)
Flush all wallets in preparation for shutdown.
void StopWallets(WalletContext &context)
Stop all wallets. Wallets will be flushed first.
void StartWallets(WalletContext &context, CScheduler &scheduler)
Complete startup of wallets.
bool LoadWallets(WalletContext &context)
Load wallet databases.
bool VerifyWallets(WalletContext &context)
Responsible for reading and validating the -wallet arguments and verifying the wallet database.
void UnloadWallets(WalletContext &context)
Close all wallets.
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Result CreateRateBumpTransaction(CWallet &wallet, const uint256 &txid, const CCoinControl &coin_control, std::vector< bilingual_str > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction based on feerate estimates.
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
static std::string PathToString(const path &path)
Convert path object to byte string.
std::unique_ptr< Wallet > MakeWallet(const std::shared_ptr< CWallet > &wallet)
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
std::vector< std::pair< std::string, std::string > > WalletOrderForm
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
std::map< std::string, std::string > WalletValueMap
std::shared_ptr< const CTransaction > CTransactionRef
CAmount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
CAmount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< uint256 > &trusted_parents)
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
Span< const CRPCCommand > GetWalletRPCCommands()
static bool verify(const CScriptNum10 &bignum, const CScriptNum &scriptnum)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
CAmount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, FeeCalculation &fee_calc_out, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
A mutable version of CTransaction.
SecureString create_passphrase
std::unique_ptr< interfaces::Chain > chain
A version of CTransaction with the PSBT format.
WalletContext struct containing references to state shared between CWallet instances,...
Information about one wallet address.
Collection of wallet balances.
CAmount watch_only_balance
CAmount unconfirmed_balance
CAmount unconfirmed_watch_only_balance
CAmount immature_watch_only_balance
std::vector< CTxDestination > txout_address
std::vector< isminetype > txout_is_mine
std::map< std::string, std::string > value_map
std::vector< isminetype > txout_address_is_mine
std::vector< isminetype > txin_is_mine
Wallet transaction output.
Updated transaction status.
unsigned int time_received
#define TRY_LOCK(cs, name)
bool error(const char *fmt, const Args &... args)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
ChangeType
General change type (added, updated, removed).
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
CAmount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control, FeeCalculation *feeCalc)
Estimate the minimum fee considering user set parameters and the required fee.
std::list< CRPCCommand > m_rpc_commands
std::shared_ptr< CWallet > m_wallet
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
const std::vector< std::string > m_wallet_filenames
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
std::shared_ptr< CWallet > CreateWallet(WalletContext &context, const std::string &name, std::optional< bool > load_on_start, DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
std::shared_ptr< CWallet > LoadWallet(WalletContext &context, const std::string &name, std::optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
fs::path GetWalletDir()
Get the path of the wallet directory.
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS