60 result.
tx = wtx.GetTx();
62 for (
const auto& txin : result.
tx->vin) {
68 for (
const auto& txout : result.
tx->vout) {
79 result.
time = wtx.GetTxTime();
80 result.
from = wtx.m_from;
96 wtx.state<TxStateConfirmed>() ? wtx.state<TxStateConfirmed>()->confirmed_block_height :
97 wtx.state<TxStateBlockConflicted>() ? wtx.state<TxStateBlockConflicted>()->conflicting_block_height :
98 std::numeric_limits<int>::max();
102 result.
lock_time = wtx.GetTx()->nLockTime;
112 const CWalletTx& wtx,
117 result.
txout = wtx.GetTx()->vout[n];
118 result.
time = wtx.GetTxTime();
128 result.
txout = output.txout;
129 result.
time = output.time;
135class WalletImpl :
public Wallet
140 bool encryptWallet(
const SecureString& wallet_passphrase)
override
142 return m_wallet->EncryptWallet(wallet_passphrase);
144 bool isCrypted()
override {
return m_wallet->HasEncryptionKeys(); }
145 bool lock()
override {
return m_wallet->Lock(); }
146 bool unlock(
const SecureString& wallet_passphrase)
override {
return m_wallet->Unlock(wallet_passphrase); }
147 bool isLocked()
override {
return m_wallet->IsLocked(); }
148 bool changeWalletPassphrase(
const SecureString& old_wallet_passphrase,
151 return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
153 void abortRescan()
override {
m_wallet->AbortRescan(); }
154 bool backupWallet(
const std::string& filename)
override {
return m_wallet->BackupWallet(filename); }
155 std::string getWalletName()
override {
return m_wallet->GetName(); }
159 return m_wallet->GetNewDestination(type, label);
165 return provider->GetPubKey(address, pub_key);
169 SigningResult signMessage(
const std::string& message,
const PKHash& pkhash, std::string& str_sig)
override
171 return m_wallet->SignMessage(message, pkhash, str_sig);
178 bool setAddressBook(
const CTxDestination& dest,
const std::string&
name,
const std::optional<AddressPurpose>& purpose)
override
184 return m_wallet->DelAddressBook(dest);
191 const auto& entry =
m_wallet->FindAddressBookEntry(dest,
false);
192 if (!entry)
return false;
194 *
name = entry->GetLabel();
202 std::vector<WalletAddress> getAddresses()
override
205 std::vector<WalletAddress> result;
207 if (is_change) return;
208 bool is_mine = m_wallet->IsMine(dest);
210 result.emplace_back(dest, is_mine, purpose.value_or(is_mine ? AddressPurpose::RECEIVE : AddressPurpose::SEND), label);
214 std::vector<std::string> getAddressReceiveRequests()
override {
216 return m_wallet->GetAddressReceiveRequests();
218 bool setAddressReceiveRequest(
const CTxDestination& dest,
const std::string&
id,
const std::string& value)
override {
232 WalletBatch batch{
m_wallet->GetDatabase()};
233 return value.empty() ?
m_wallet->EraseAddressReceiveRequest(batch, dest,
id)
234 :
m_wallet->SetAddressReceiveRequest(batch, dest,
id, value);
239 return m_wallet->DisplayAddress(dest);
241 bool lockCoin(
const COutPoint& output,
const bool write_to_db)
override
244 return m_wallet->LockCoin(output, write_to_db);
246 bool unlockCoin(
const COutPoint& output)
override
249 return m_wallet->UnlockCoin(output);
251 bool isLockedCoin(
const COutPoint& output)
override
254 return m_wallet->IsLockedCoin(output);
256 void listLockedCoins(std::vector<COutPoint>& outputs)
override
259 return m_wallet->ListLockedCoins(outputs);
262 const CCoinControl& coin_control,
264 std::optional<unsigned int> change_pos)
override
272 m_wallet->CommitTransaction(std::move(tx), std::nullopt, std::nullopt, std::nullopt,
messages);
274 bool transactionCanBeAbandoned(
const Txid& txid)
override {
return m_wallet->TransactionCanBeAbandoned(txid); }
275 bool abandonTransaction(
const Txid& txid)
override
278 return m_wallet->AbandonTransaction(txid);
280 bool transactionCanBeBumped(
const Txid& txid)
override
284 bool createBumpTransaction(
const Txid& txid,
285 const CCoinControl& coin_control,
286 std::vector<bilingual_str>& errors,
291 std::vector<CTxOut> outputs;
295 bool commitBumpTransaction(
const Txid& txid,
297 std::vector<bilingual_str>& errors,
298 Txid& bumped_txid)
override
306 auto mi =
m_wallet->mapWallet.find(txid);
307 if (mi !=
m_wallet->mapWallet.end()) {
308 return mi->second.GetTx();
315 auto mi =
m_wallet->mapWallet.find(txid);
316 if (mi !=
m_wallet->mapWallet.end()) {
317 return MakeWalletTx(*
m_wallet, mi->second);
321 std::set<WalletTx> getWalletTxs()
override
324 std::set<WalletTx> result;
325 for (
const auto& entry :
m_wallet->mapWallet) {
326 result.emplace(MakeWalletTx(*
m_wallet, entry.second));
330 bool tryGetTxStatus(
const Txid& txid,
333 int64_t& block_time)
override
336 if (!locked_wallet) {
339 auto mi =
m_wallet->mapWallet.find(txid);
340 if (mi ==
m_wallet->mapWallet.end()) {
343 num_blocks =
m_wallet->GetLastBlockHeight();
346 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
352 std::vector<std::string>& payment_requests,
354 int& num_blocks)
override
357 auto mi =
m_wallet->mapWallet.find(txid);
358 if (mi !=
m_wallet->mapWallet.end()) {
359 num_blocks =
m_wallet->GetLastBlockHeight();
360 in_mempool = mi->second.InMempool();
362 payment_requests = mi->second.m_payment_requests;
363 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
364 return MakeWalletTx(*
m_wallet, mi->second);
371 bool& complete)
override
373 return m_wallet->FillPSBT(psbtx, options, complete, n_signed);
379 result.
balance = bal.m_mine_trusted;
389 if (!locked_wallet) {
392 block_hash =
m_wallet->GetLastBlockHash();
393 balances = getBalances();
397 CAmount getAvailableBalance(
const CCoinControl& coin_control)
override
402 if (coin_control.HasSelected()) {
404 CoinSelectionParams params(
rng);
407 total_amount += res->GetTotalAmount();
412 if (coin_control.m_allow_other_inputs) {
418 bool txinIsMine(
const CTxIn& txin)
override
423 bool txoutIsMine(
const CTxOut& txout)
override
438 CoinsList listCoins()
override
443 auto&
group = result[entry.first];
444 for (
const auto& coin : entry.second) {
445 group.emplace_back(coin.outpoint,
451 std::vector<WalletTxOut> getCoins(
const std::vector<COutPoint>& outputs)
override
454 std::vector<WalletTxOut> result;
455 result.reserve(outputs.size());
456 for (
const auto& output : outputs) {
457 result.emplace_back();
459 if (it !=
m_wallet->mapWallet.end()) {
460 int depth =
m_wallet->GetTxDepthInMainChain(it->second);
462 result.back() = MakeWalletTxOut(*
m_wallet, it->second, output.
n, depth);
469 CAmount getMinimumFee(
unsigned int tx_bytes,
470 const CCoinControl& coin_control,
471 std::optional<int>* returned_target,
476 if (returned_target) *returned_target = min_fee_rate.returned_target;
477 if (reason) *reason = min_fee_rate.fee_reason;
480 unsigned int getConfirmTarget()
override {
return m_wallet->m_confirm_target; }
481 bool hdEnabled()
override {
return m_wallet->IsHDEnabled(); }
482 bool canGetAddresses()
override {
return m_wallet->CanGetAddresses(); }
485 bool taprootEnabled()
override {
487 return spk_man !=
nullptr;
489 OutputType getDefaultAddressType()
override {
return m_wallet->m_default_address_type; }
490 CAmount getDefaultMaxTxFee()
override {
return m_wallet->m_default_max_tx_fee; }
491 void remove()
override
495 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override
499 std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn)
override
503 std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn)
override
507 std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn)
override
510 [fn](
const CTxDestination& address,
const std::string& label,
bool is_mine,
513 std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn)
override
516 [fn](
const Txid& txid,
ChangeType status) { fn(txid, status); }));
518 std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
override
542 ~WalletLoaderImpl()
override {
stop(); }
545 void registerRpcs()
override
549 JSONRPCRequest wallet_request = request;
550 wallet_request.context = &m_context;
551 return command.actor(wallet_request, result, last_handler);
565 void setMockTime(int64_t time)
override {
return SetMockTime(std::chrono::seconds{time}); }
566 void schedulerMockForward(std::chrono::seconds delta)
override {
Assert(
m_context.scheduler)->MockForward(delta); }
571 DatabaseOptions options;
574 options.require_create =
true;
575 options.create_flags = wallet_creation_flags;
576 options.create_passphrase = passphrase;
587 DatabaseOptions options;
590 options.require_existing =
true;
599 util::Result<std::unique_ptr<Wallet>> restoreWallet(
const fs::path& backup_file,
const std::string& wallet_name, std::vector<bilingual_str>& warnings,
bool load_after_restore)
override
604 if (!error.
empty()) {
615 .watchonly_wallet_name = res->watchonly_wallet_name,
616 .solvables_wallet_name = res->solvables_wallet_name,
617 .backup_path = res->backup_path,
621 bool isEncrypted(
const std::string& wallet_name)
override
624 auto it = std::find_if(wallets.begin(), wallets.end(), [&](std::shared_ptr<CWallet> w){ return w->GetName() == wallet_name; });
625 if (it != wallets.end())
return (*it)->HasEncryptionKeys();
628 DatabaseOptions options;
629 options.require_existing =
true;
637 if (!
db)
return false;
638 return WalletBatch(*db).IsEncrypted();
640 std::string getWalletDir()
override
644 std::vector<std::pair<std::string, std::string>> listWalletDir()
override
646 std::vector<std::pair<std::string, std::string>> paths;
648 paths.emplace_back(fs::PathToString(path),
format);
652 std::vector<std::unique_ptr<Wallet>> getWallets()
override
654 std::vector<std::unique_ptr<Wallet>> wallets;
660 std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
override
664 WalletContext* context()
override {
return &
m_context; }
679 return std::make_unique<wallet::WalletLoaderImpl>(chain,
args);
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
int64_t CAmount
Amount in satoshis (Can be negative)
#define CHECK_NONFATAL(condition)
Identity function.
#define Assert(val)
Identity function.
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 version of CTransaction with the PSBT format.
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...
Interface for accessing a wallet.
Wallet chain client that in addition to having chain client methods for starting up,...
static std::string PathToString(const path &path)
Convert path object to a byte string.
static int sign(const secp256k1_context *ctx, struct signer_secrets *signer_secrets, struct signer *signer, const secp256k1_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64)
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
std::unique_ptr< Handler > MakeSignalHandler(btcsignals::connection connection)
Return handler wrapping a btcsignals connection.
std::unique_ptr< Wallet > MakeWallet(wallet::WalletContext &context, const std::shared_ptr< wallet::CWallet > &wallet)
Return implementation of Wallet interface.
bilingual_str ErrorString(const Result< T > &result)
Result CreateRateBumpTransaction(CWallet &wallet, const Txid &txid, const CCoinControl &coin_control, std::vector< bilingual_str > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx, bool require_mine, const std::vector< CTxOut > &outputs, std::optional< uint32_t > original_change_index)
Create bumpfee transaction based on feerate estimates.
bool TransactionCanBeBumped(const CWallet &wallet, const Txid &txid)
Return whether transaction can be bumped.
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Result CommitTransaction(CWallet &wallet, const Txid &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, Txid &bumped_txid)
Commit the bumpfee transaction.
void StartWallets(WalletContext &context)
Complete startup of wallets.
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
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)
util::Result< CreatedTransactionResult > CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, std::optional< unsigned int > change_pos, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
util::Result< MigrationResult > MigrateLegacyToDescriptor(const std::string &wallet_name, const SecureString &passphrase, WalletContext &context, bool load_wallet)
Do all steps to migrate a legacy wallet to a descriptor wallet.
util::Result< CoinsResult > FetchSelectedInputs(const CWallet &wallet, const CCoinControl &coin_control, const CoinSelectionParams &coin_selection_params)
Fetch and validate coin control selected inputs.
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< Txid > &trusted_parents)
MinimumFeeRateResult GetMinimumFeeRate(const CWallet &wallet, const CCoinControl &coin_control)
Estimate the minimum fee rate considering user set parameters and the required fee.
CAmount GetMinimumFee(const MinimumFeeRateResult &min_fee_rate, unsigned int nTxBytes)
Return the minimum fee for this size given a fee rate result.
bool VerifyWallets(WalletContext &context)
Responsible for reading and validating the -wallet arguments and verifying the wallet database.
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
fs::path GetWalletDir()
Get the path of the wallet directory.
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
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 CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, bool avoid_reuse)
std::shared_ptr< CWallet > RestoreWallet(WalletContext &context, const fs::path &backup_file, const std::string &wallet_name, std::optional< bool > load_on_start, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings, bool load_after_restore, bool allow_unnamed)
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, bool avoid_reuse)
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
util::Result< std::string > ExportWatchOnlyWallet(const CWallet &wallet, const fs::path &destination, WalletContext &context)
Make a new watchonly wallet file containing the public descriptors from this wallet The exported watc...
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse, bool include_nonmempool)
void UnloadWallets(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)
bool LoadWallets(WalletContext &context)
Load wallet databases.
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
std::span< const CRPCCommand > GetWalletRPCCommands()
bool InputIsMine(const CWallet &wallet, const CTxIn &txin)
CTxDestination getNewDestination(CWallet &w, OutputType output_type)
Returns a new destination, of an specific type, from the wallet.
CAmount OutputGetCredit(const CWallet &wallet, const CTxOut &txout)
std::vector< std::pair< fs::path, std::string > > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
CoinsResult AvailableCoins(const CWallet &wallet, const CCoinControl *coinControl, std::optional< CFeeRate > feerate, const CoinFilterParams ¶ms)
Populate the CoinsResult struct with vectors of available COutputs, organized by OutputType.
is a home for public enum and struct type definitions that are used internally by node code,...
std::shared_ptr< const CTransaction > CTransactionRef
static bool verify(const CScriptNum10 &bignum, const CScriptNum &scriptnum)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
A mutable version of CTransaction.
Instructions for how a PSBT should be signed or filled with information.
Information about one wallet address.
Collection of wallet balances.
CAmount nonmempool_balance
CAmount unconfirmed_balance
std::vector< bool > txin_is_mine
std::optional< std::string > comment
std::vector< CTxDestination > txout_address
std::vector< bool > txout_address_is_mine
std::optional< std::string > comment_to
std::vector< bool > txout_is_change
std::vector< bool > txout_is_mine
std::optional< std::string > message
std::optional< std::string > from
Wallet transaction output.
Updated transaction status.
unsigned int time_received
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
CAmount GetTotalAmount() const
WalletContext struct containing references to state shared between CWallet instances,...
#define TRY_LOCK(cs, name)
FuzzedDataProvider provider
#define EXCLUSIVE_LOCKS_REQUIRED(...)
ChangeType
General change type (added, updated, removed).
void SetMockTime(std::chrono::time_point< NodeClock, std::chrono::seconds > mock)
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::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn