56 for (
const auto& txin : wtx.
tx->vin) {
62 for (
const auto& txout : wtx.
tx->vout) {
102 result.
txout = wtx.
tx->vout[n];
109 class WalletImpl :
public Wallet 114 bool encryptWallet(
const SecureString& wallet_passphrase)
override 116 return m_wallet->EncryptWallet(wallet_passphrase);
118 bool isCrypted()
override {
return m_wallet->IsCrypted(); }
119 bool lock()
override {
return m_wallet->Lock(); }
120 bool unlock(
const SecureString& wallet_passphrase)
override {
return m_wallet->Unlock(wallet_passphrase); }
121 bool isLocked()
override {
return m_wallet->IsLocked(); }
122 bool changeWalletPassphrase(
const SecureString& old_wallet_passphrase,
125 return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
127 void abortRescan()
override {
m_wallet->AbortRescan(); }
128 bool backupWallet(
const std::string& filename)
override {
return m_wallet->BackupWallet(filename); }
129 std::string getWalletName()
override {
return m_wallet->GetName(); }
134 return m_wallet->GetNewDestination(type, label, dest,
error);
138 std::unique_ptr<SigningProvider> provider =
m_wallet->GetSolvingProvider(script);
140 return provider->GetPubKey(address, pub_key);
144 SigningResult signMessage(
const std::string& message,
const PKHash& pkhash, std::string& str_sig)
override 146 return m_wallet->SignMessage(message, pkhash, str_sig);
153 bool haveWatchOnly()
override 155 auto spk_man =
m_wallet->GetLegacyScriptPubKeyMan();
157 return spk_man->HaveWatchOnly();
161 bool setAddressBook(
const CTxDestination& dest,
const std::string&
name,
const std::string& purpose)
override 167 return m_wallet->DelAddressBook(dest);
172 std::string* purpose)
override 175 auto it =
m_wallet->m_address_book.find(dest);
176 if (it ==
m_wallet->m_address_book.end() || it->second.IsChange()) {
180 *
name = it->second.GetLabel();
186 *purpose = it->second.purpose;
190 std::vector<WalletAddress> getAddresses()
override 193 std::vector<WalletAddress> result;
194 for (
const auto& item :
m_wallet->m_address_book) {
195 if (item.second.IsChange())
continue;
196 result.emplace_back(item.first,
m_wallet->IsMine(item.first), item.second.GetLabel(), item.second.purpose);
200 std::vector<std::string> getAddressReceiveRequests()
override {
202 return m_wallet->GetAddressReceiveRequests();
204 bool setAddressReceiveRequest(
const CTxDestination& dest,
const std::string&
id,
const std::string& value)
override {
207 return m_wallet->SetAddressReceiveRequest(batch, dest,
id, value);
212 return m_wallet->DisplayAddress(dest);
214 void lockCoin(
const COutPoint& output)
override 219 void unlockCoin(
const COutPoint& output)
override 222 return m_wallet->UnlockCoin(output);
224 bool isLockedCoin(
const COutPoint& output)
override 229 void listLockedCoins(std::vector<COutPoint>& outputs)
override 232 return m_wallet->ListLockedCoins(outputs);
234 CTransactionRef createTransaction(
const std::vector<CRecipient>& recipients,
244 if (!
m_wallet->CreateTransaction(recipients, tx, fee, change_pos,
245 fail_reason, coin_control, fee_calc_out, sign)) {
255 m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
257 bool transactionCanBeAbandoned(
const uint256& txid)
override {
return m_wallet->TransactionCanBeAbandoned(txid); }
258 bool abandonTransaction(
const uint256& txid)
override 261 return m_wallet->AbandonTransaction(txid);
263 bool transactionCanBeBumped(
const uint256& txid)
override 267 bool createBumpTransaction(
const uint256& txid,
269 std::vector<bilingual_str>& errors,
277 bool commitBumpTransaction(
const uint256& txid,
279 std::vector<bilingual_str>& errors,
288 auto mi =
m_wallet->mapWallet.find(txid);
289 if (mi !=
m_wallet->mapWallet.end()) {
290 return mi->second.tx;
297 auto mi =
m_wallet->mapWallet.find(txid);
298 if (mi !=
m_wallet->mapWallet.end()) {
299 return MakeWalletTx(*
m_wallet, mi->second);
303 std::vector<WalletTx> getWalletTxs()
override 306 std::vector<WalletTx> result;
307 result.reserve(
m_wallet->mapWallet.size());
308 for (
const auto& entry :
m_wallet->mapWallet) {
309 result.emplace_back(MakeWalletTx(*
m_wallet, entry.second));
313 bool tryGetTxStatus(
const uint256& txid,
316 int64_t& block_time)
override 319 if (!locked_wallet) {
322 auto mi =
m_wallet->mapWallet.find(txid);
323 if (mi ==
m_wallet->mapWallet.end()) {
326 num_blocks =
m_wallet->GetLastBlockHeight();
329 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
336 int& num_blocks)
override 339 auto mi =
m_wallet->mapWallet.find(txid);
340 if (mi !=
m_wallet->mapWallet.end()) {
341 num_blocks =
m_wallet->GetLastBlockHeight();
342 in_mempool = mi->second.InMempool();
343 order_form = mi->second.vOrderForm;
344 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
345 return MakeWalletTx(*
m_wallet, mi->second);
354 bool& complete)
override 356 return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs, n_signed);
360 const auto bal =
m_wallet->GetBalance();
362 result.
balance = bal.m_mine_trusted;
376 if (!locked_wallet) {
379 block_hash =
m_wallet->GetLastBlockHash();
380 balances = getBalances();
383 CAmount getBalance()
override {
return m_wallet->GetBalance().m_mine_trusted; }
386 return m_wallet->GetAvailableBalance(&coin_control);
401 return m_wallet->GetDebit(txin, filter);
406 return m_wallet->GetCredit(txout, filter);
408 CoinsList listCoins()
override 412 for (
const auto& entry :
m_wallet->ListCoins()) {
413 auto& group = result[entry.first];
414 for (
const auto& coin : entry.second) {
415 group.emplace_back(
COutPoint(coin.tx->GetHash(), coin.i),
416 MakeWalletTxOut(*
m_wallet, *coin.tx, coin.i, coin.nDepth));
421 std::vector<WalletTxOut> getCoins(
const std::vector<COutPoint>& outputs)
override 424 std::vector<WalletTxOut> result;
425 result.reserve(outputs.size());
426 for (
const auto& output : outputs) {
427 result.emplace_back();
429 if (it !=
m_wallet->mapWallet.end()) {
430 int depth = it->second.GetDepthInMainChain();
432 result.back() = MakeWalletTxOut(*
m_wallet, it->second, output.
n, depth);
439 CAmount getMinimumFee(
unsigned int tx_bytes,
441 int* returned_target,
448 if (reason) *reason = fee_calc.
reason;
451 unsigned int getConfirmTarget()
override {
return m_wallet->m_confirm_target; }
452 bool hdEnabled()
override {
return m_wallet->IsHDEnabled(); }
453 bool canGetAddresses()
override {
return m_wallet->CanGetAddresses(); }
456 OutputType getDefaultAddressType()
override {
return m_wallet->m_default_address_type; }
457 CAmount getDefaultMaxTxFee()
override {
return m_wallet->m_default_max_tx_fee; }
458 void remove()
override 462 bool isLegacy()
override {
return m_wallet->IsLegacy(); }
463 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override 467 std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn)
override 471 std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn)
override 475 std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn)
override 478 [fn](
const CTxDestination& address,
const std::string& label,
bool is_mine,
479 const std::string& purpose,
ChangeType status) { fn(address, label, is_mine, purpose, status); }));
481 std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn)
override 486 std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn)
override 490 std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
override 510 void registerRpcs()
override 514 JSONRPCRequest wallet_request = request;
515 wallet_request.context = &m_context;
516 return command.actor(wallet_request, result, last_handler);
517 }, command.argNames, command.unique_id);
526 void setMockTime(int64_t time)
override {
return SetMockTime(time); }
529 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 531 std::shared_ptr<CWallet>
wallet;
539 std::unique_ptr<Wallet> loadWallet(
const std::string&
name,
bilingual_str&
error, std::vector<bilingual_str>& warnings)
override 546 std::string getWalletDir()
override 550 std::vector<std::string> listWalletDir()
override 552 std::vector<std::string> paths;
554 paths.push_back(path.string());
558 std::vector<std::unique_ptr<Wallet>> getWallets()
override 560 std::vector<std::unique_ptr<Wallet>> wallets;
566 std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
override 580 std::unique_ptr<Wallet>
MakeWallet(
const std::shared_ptr<CWallet>&
wallet) {
return wallet ? std::make_unique<wallet::WalletImpl>(
wallet) :
nullptr; }
584 return std::make_unique<wallet::WalletClientImpl>(chain, args);
std::shared_ptr< const CTransaction > CTransactionRef
Helper for findBlock to selectively return pieces of block data.
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
std::vector< CTxDestination > txout_address
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
bool LoadWallets(interfaces::Chain &chain)
Load wallet databases.
const std::vector< std::string > m_wallet_filenames
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
#define TRY_LOCK(cs, name)
unsigned int time_received
std::vector< isminetype > txin_is_mine
std::vector< isminetype > txout_is_mine
std::shared_ptr< CWallet > m_wallet
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
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.
CAmount GetCredit(const isminefilter &filter) const
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
std::unique_ptr< interfaces::Chain > chain
bool IsInMainChain() const
A version of CTransaction with the PSBT format.
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
Indicates that the wallet needs an external signer.
std::map< std::string, std::string > WalletValueMap
Wallet chain client that in addition to having chain client methods for starting up, shutting down, and registering RPCs, also has additional methods (called by the GUI) to load and create wallets.
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.
Access to the wallet database.
mapValue_t mapValue
Key/value map with information about the transaction.
void StopWallets()
Stop all wallets. Wallets will be flushed first.
int64_t CAmount
Amount in satoshis (Can be negative)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
bool VerifyWallets(interfaces::Chain &chain)
Responsible for reading and validating the -wallet arguments and verifying the wallet database...
CAmount watch_only_balance
std::shared_ptr< CWallet > LoadWallet(interfaces::Chain &chain, 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.
Collection of wallet balances.
An input of a transaction.
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
An encapsulated public key.
int GetBlocksToMaturity() const
CAmount GetChange() const
Interface for accessing a wallet.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
An output of a transaction.
CAmount immature_watch_only_balance
const uint256 & GetHash() const
An outpoint - a combination of a transaction hash and an index n into its vout.
std::unique_ptr< Wallet > MakeWallet(const std::shared_ptr< CWallet > &wallet)
Return implementation of Wallet interface.
void FlushWallets()
Flush all wallets in preparation for shutdown.
A transaction with a bunch of additional info that only the owner cares about.
Generic interface for managing an event handler or callback function registered with another interfac...
std::vector< std::shared_ptr< CWallet > > GetWallets()
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
CAmount unconfirmed_balance
Span< const CRPCCommand > GetWalletRPCCommands()
#define EXCLUSIVE_LOCKS_REQUIRED(...)
std::vector< isminetype > txout_address_is_mine
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
CAmount unconfirmed_watch_only_balance
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Serialized script, used inside transaction inputs and outputs.
int64_t GetTxTime() const
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
A reference to a CKey: the Hash160 of its serialized public key.
int GetDepthInMainChain() const NO_THREAD_SAFETY_ANALYSIS
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
std::vector< std::pair< std::string, std::string > > WalletOrderForm
Information about one wallet address.
WalletContext struct containing references to state shared between CWallet instances, like the reference to the chain interface, and the list of opened wallets.
std::vector< fs::path > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
A mutable version of CTransaction.
SecureString create_passphrase
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
std::map< std::string, std::string > value_map
unsigned int nTimeReceived
time received by this node
void UnloadWallets()
Close all wallets.
Simple class for background tasks that should be run periodically or once "after a while"...
ChangeType
General change type (added, updated, removed).
std::list< CRPCCommand > m_rpc_commands
Wallet transaction output.
bool error(const char *fmt, const Args &... args)
Updated transaction status.
FoundBlock & time(int64_t &time)
std::shared_ptr< CWallet > CreateWallet(interfaces::Chain &chain, const std::string &name, std::optional< bool > load_on_start, DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
#define Assert(val)
Identity function.
void StartWallets(CScheduler &scheduler, const ArgsManager &args)
Complete startup of wallets.