65 for (
const auto& txin : wtx.tx->vin) {
71 for (
const auto& txout : wtx.tx->vout) {
82 result.
time = wtx.GetTxTime();
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();
112 const CWalletTx& wtx,
117 result.
txout = wtx.tx->vout[n];
118 result.
time = wtx.GetTxTime();
128 result.
txout = output.txout;
129 result.
time = output.time;
135 class 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->IsCrypted(); }
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);
163 std::unique_ptr<SigningProvider> provider =
m_wallet->GetSolvingProvider(
script);
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 haveWatchOnly()
override 180 auto spk_man =
m_wallet->GetLegacyScriptPubKeyMan();
182 return spk_man->HaveWatchOnly();
186 bool setAddressBook(
const CTxDestination& dest,
const std::string&
name,
const std::optional<AddressPurpose>& purpose)
override 192 return m_wallet->DelAddressBook(dest);
200 const auto& entry =
m_wallet->FindAddressBookEntry(dest,
false);
201 if (!entry)
return false;
203 *
name = entry->GetLabel();
205 std::optional<isminetype> dest_is_mine;
206 if (is_mine || purpose) {
207 dest_is_mine =
m_wallet->IsMine(dest);
210 *is_mine = *dest_is_mine;
218 std::vector<WalletAddress> getAddresses()
override 221 std::vector<WalletAddress> result;
223 if (is_change) return;
224 isminetype is_mine = m_wallet->IsMine(dest);
226 result.emplace_back(dest, is_mine, purpose.value_or(is_mine ? AddressPurpose::RECEIVE : AddressPurpose::SEND), label);
230 std::vector<std::string> getAddressReceiveRequests()
override {
232 return m_wallet->GetAddressReceiveRequests();
234 bool setAddressReceiveRequest(
const CTxDestination& dest,
const std::string&
id,
const std::string& value)
override {
248 WalletBatch batch{
m_wallet->GetDatabase()};
249 return value.empty() ?
m_wallet->EraseAddressReceiveRequest(batch, dest,
id)
250 :
m_wallet->SetAddressReceiveRequest(batch, dest,
id, value);
255 return m_wallet->DisplayAddress(dest);
257 bool lockCoin(
const COutPoint& output,
const bool write_to_db)
override 260 std::unique_ptr<WalletBatch> batch = write_to_db ? std::make_unique<WalletBatch>(
m_wallet->GetDatabase()) :
nullptr;
261 return m_wallet->LockCoin(output, batch.get());
263 bool unlockCoin(
const COutPoint& output)
override 266 std::unique_ptr<WalletBatch> batch = std::make_unique<WalletBatch>(
m_wallet->GetDatabase());
267 return m_wallet->UnlockCoin(output, batch.get());
269 bool isLockedCoin(
const COutPoint& output)
override 272 return m_wallet->IsLockedCoin(output);
274 void listLockedCoins(std::vector<COutPoint>& outputs)
override 277 return m_wallet->ListLockedCoins(outputs);
280 const CCoinControl& coin_control,
289 const auto& txr = *res;
291 change_pos = txr.change_pos ? int(*txr.change_pos) : -1;
300 m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
302 bool transactionCanBeAbandoned(
const uint256& txid)
override {
return m_wallet->TransactionCanBeAbandoned(txid); }
303 bool abandonTransaction(
const uint256& txid)
override 306 return m_wallet->AbandonTransaction(txid);
308 bool transactionCanBeBumped(
const uint256& txid)
override 312 bool createBumpTransaction(
const uint256& txid,
313 const CCoinControl& coin_control,
314 std::vector<bilingual_str>& errors,
319 std::vector<CTxOut> outputs;
323 bool commitBumpTransaction(
const uint256& txid,
325 std::vector<bilingual_str>& errors,
334 auto mi =
m_wallet->mapWallet.find(txid);
335 if (mi !=
m_wallet->mapWallet.end()) {
336 return mi->second.tx;
343 auto mi =
m_wallet->mapWallet.find(txid);
344 if (mi !=
m_wallet->mapWallet.end()) {
345 return MakeWalletTx(*
m_wallet, mi->second);
349 std::set<WalletTx> getWalletTxs()
override 352 std::set<WalletTx> result;
353 for (
const auto& entry :
m_wallet->mapWallet) {
354 result.emplace(MakeWalletTx(*
m_wallet, entry.second));
358 bool tryGetTxStatus(
const uint256& txid,
361 int64_t& block_time)
override 364 if (!locked_wallet) {
367 auto mi =
m_wallet->mapWallet.find(txid);
368 if (mi ==
m_wallet->mapWallet.end()) {
371 num_blocks =
m_wallet->GetLastBlockHeight();
374 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
381 int& num_blocks)
override 384 auto mi =
m_wallet->mapWallet.find(txid);
385 if (mi !=
m_wallet->mapWallet.end()) {
386 num_blocks =
m_wallet->GetLastBlockHeight();
387 in_mempool = mi->second.InMempool();
388 order_form = mi->second.vOrderForm;
389 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
390 return MakeWalletTx(*
m_wallet, mi->second);
394 std::optional<PSBTError> fillPSBT(
int sighash_type,
399 bool& complete)
override 401 return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs, n_signed);
407 result.
balance = bal.m_mine_trusted;
421 if (!locked_wallet) {
424 block_hash =
m_wallet->GetLastBlockHash();
425 balances = getBalances();
429 CAmount getAvailableBalance(
const CCoinControl& coin_control)
override 434 if (coin_control.HasSelected()) {
436 CoinSelectionParams params(rng);
439 total_amount += res->total_amount;
444 if (coin_control.m_allow_other_inputs) {
463 return m_wallet->GetDebit(txin, filter);
470 CoinsList listCoins()
override 475 auto&
group = result[entry.first];
476 for (
const auto& coin : entry.second) {
477 group.emplace_back(coin.outpoint,
483 std::vector<WalletTxOut> getCoins(
const std::vector<COutPoint>& outputs)
override 486 std::vector<WalletTxOut> result;
487 result.reserve(outputs.size());
488 for (
const auto& output : outputs) {
489 result.emplace_back();
491 if (it !=
m_wallet->mapWallet.end()) {
492 int depth =
m_wallet->GetTxDepthInMainChain(it->second);
494 result.back() = MakeWalletTxOut(*
m_wallet, it->second, output.
n, depth);
501 CAmount getMinimumFee(
unsigned int tx_bytes,
502 const CCoinControl& coin_control,
503 int* returned_target,
510 if (reason) *reason = fee_calc.
reason;
513 unsigned int getConfirmTarget()
override {
return m_wallet->m_confirm_target; }
514 bool hdEnabled()
override {
return m_wallet->IsHDEnabled(); }
515 bool canGetAddresses()
override {
return m_wallet->CanGetAddresses(); }
518 bool taprootEnabled()
override {
519 if (
m_wallet->IsLegacy())
return false;
521 return spk_man !=
nullptr;
523 OutputType getDefaultAddressType()
override {
return m_wallet->m_default_address_type; }
524 CAmount getDefaultMaxTxFee()
override {
return m_wallet->m_default_max_tx_fee; }
525 void remove()
override 529 bool isLegacy()
override {
return m_wallet->IsLegacy(); }
530 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override 534 std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn)
override 538 std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn)
override 542 std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn)
override 545 [fn](
const CTxDestination& address,
const std::string& label,
bool is_mine,
548 std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn)
override 553 std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn)
override 557 std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
override 578 void registerRpcs()
override 582 JSONRPCRequest wallet_request = request;
583 wallet_request.context = &m_context;
584 return command.actor(wallet_request, result, last_handler);
598 void setMockTime(int64_t time)
override {
return SetMockTime(time); }
599 void schedulerMockForward(std::chrono::seconds delta)
override {
Assert(
m_context.scheduler)->MockForward(delta); }
604 DatabaseOptions options;
607 options.require_create =
true;
608 options.create_flags = wallet_creation_flags;
609 options.create_passphrase = passphrase;
620 DatabaseOptions options;
623 options.require_existing =
true;
649 .watchonly_wallet_name = res->watchonly_wallet ? std::make_optional(res->watchonly_wallet->GetName()) : std::nullopt,
650 .solvables_wallet_name = res->solvables_wallet ? std::make_optional(res->solvables_wallet->GetName()) : std::nullopt,
651 .backup_path = res->backup_path,
655 bool isEncrypted(
const std::string& wallet_name)
override 658 auto it = std::find_if(wallets.begin(), wallets.end(), [&](std::shared_ptr<CWallet> w){
return w->GetName() == wallet_name; });
659 if (it != wallets.end())
return (*it)->IsCrypted();
662 DatabaseOptions options;
663 options.require_existing =
true;
667 if (!db)
return false;
668 return WalletBatch(*db).IsEncrypted();
670 std::string getWalletDir()
override 674 std::vector<std::pair<std::string, std::string>> listWalletDir()
override 676 std::vector<std::pair<std::string, std::string>> paths;
682 std::vector<std::unique_ptr<Wallet>> getWallets()
override 684 std::vector<std::unique_ptr<Wallet>> wallets;
690 std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
override 694 WalletContext* context()
override {
return &
m_context; }
709 return std::make_unique<wallet::WalletLoaderImpl>(chain,
args);
std::shared_ptr< const CTransaction > CTransactionRef
Helper for findBlock to selectively return pieces of block data.
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
std::vector< CTxDestination > txout_address
const std::vector< std::string > m_wallet_filenames
void FlushWallets(WalletContext &context)
Flush all wallets in preparation for shutdown.
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
#define TRY_LOCK(cs, name)
std::vector< wallet::isminetype > txin_is_mine
std::vector< std::pair< fs::path, std::string > > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
unsigned int time_received
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)
std::shared_ptr< CWallet > m_wallet
#define CHECK_NONFATAL(condition)
Identity function.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
std::unique_ptr< Wallet > MakeWallet(wallet::WalletContext &context, const std::shared_ptr< wallet::CWallet > &wallet)
Return implementation of Wallet interface.
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
A version of CTransaction with the PSBT format.
Result CreateRateBumpTransaction(CWallet &wallet, const uint256 &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.
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
CTxDestination getNewDestination(CWallet &w, OutputType output_type)
Returns a new destination, of an specific type, from the wallet.
std::map< std::string, std::string > WalletValueMap
fs::path GetWalletDir()
Get the path of the wallet directory.
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
bool LoadWallets(WalletContext &context)
Load wallet databases.
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
void StopWallets(WalletContext &context)
Stop all wallets. Wallets will be flushed first.
int64_t CAmount
Amount in satoshis (Can be negative)
std::vector< bool > txout_is_change
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
void StartWallets(WalletContext &context)
Complete startup of wallets.
std::vector< wallet::isminetype > txout_is_mine
bool VerifyWallets(WalletContext &context)
Responsible for reading and validating the -wallet arguments and verifying the wallet database...
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
Indicates that the wallet needs an external signer.
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
CAmount watch_only_balance
std::underlying_type< isminetype >::type isminefilter
used for bitflags of isminetype
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
static std::string PathToString(const path &path)
Convert path object to a byte string.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
Collection of wallet balances.
An input of a transaction.
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...
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< uint256 > &trusted_parents)
An encapsulated public key.
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
Interface for accessing a wallet.
static bool verify(const CScriptNum10 &bignum, const CScriptNum &scriptnum)
An output of a transaction.
std::vector< wallet::isminetype > txout_address_is_mine
CAmount immature_watch_only_balance
An outpoint - a combination of a transaction hash and an index n into its vout.
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.
is a home for public enum and struct type definitions that are used by internally by wallet code...
util::Result< MigrationResult > MigrateLegacyToDescriptor(const std::string &wallet_name, const SecureString &passphrase, WalletContext &context)
Do all steps to migrate a legacy wallet to a descriptor wallet.
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Generic interface for managing an event handler or callback function registered with another interfac...
util::Result< PreSelectedInputs > FetchSelectedInputs(const CWallet &wallet, const CCoinControl &coin_control, const CoinSelectionParams &coin_selection_params)
Fetch and validate coin control selected inputs.
CAmount unconfirmed_balance
#define EXCLUSIVE_LOCKS_REQUIRED(...)
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
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.
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
A reference to a CKey: the Hash160 of its serialized public key.
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.
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
WalletContext struct containing references to state shared between CWallet instances, like the reference to the chain interface, and the list of opened wallets.
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
std::vector< std::pair< std::string, std::string > > WalletOrderForm
bilingual_str ErrorString(const Result< T > &result)
Information about one wallet address.
A mutable version of CTransaction.
std::unique_ptr< Handler > MakeSignalHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
void UnloadWallets(WalletContext &context)
Close all wallets.
std::map< std::string, std::string > value_map
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
Span< const CRPCCommand > GetWalletRPCCommands()
std::shared_ptr< CWallet > wallet
Simple class for background tasks that should be run periodically or once "after a while"...
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)
ChangeType
General change type (added, updated, removed).
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.
is a home for public enum and struct type definitions that are used by internally by node code...
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)
std::list< CRPCCommand > m_rpc_commands
Wallet transaction output.
CAmount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Updated transaction status.
FoundBlock & time(int64_t &time)
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
#define Assert(val)
Identity function.
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, const isminefilter &filter)
filter decides which addresses will count towards the debit