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;
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->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 setAddressBook(
const CTxDestination& dest,
const std::string&
name,
const std::optional<AddressPurpose>& purpose)
override
184 return m_wallet->DelAddressBook(dest);
192 const auto& entry =
m_wallet->FindAddressBookEntry(dest,
false);
193 if (!entry)
return false;
195 *
name = entry->GetLabel();
197 std::optional<isminetype> dest_is_mine;
198 if (is_mine || purpose) {
199 dest_is_mine =
m_wallet->IsMine(dest);
202 *is_mine = *dest_is_mine;
210 std::vector<WalletAddress> getAddresses()
override
213 std::vector<WalletAddress> result;
215 if (is_change) return;
216 isminetype is_mine = m_wallet->IsMine(dest);
218 result.emplace_back(dest, is_mine, purpose.value_or(is_mine ? AddressPurpose::RECEIVE : AddressPurpose::SEND), label);
222 std::vector<std::string> getAddressReceiveRequests()
override {
224 return m_wallet->GetAddressReceiveRequests();
226 bool setAddressReceiveRequest(
const CTxDestination& dest,
const std::string&
id,
const std::string& value)
override {
240 WalletBatch batch{
m_wallet->GetDatabase()};
241 return value.empty() ?
m_wallet->EraseAddressReceiveRequest(batch, dest,
id)
242 :
m_wallet->SetAddressReceiveRequest(batch, dest,
id, value);
247 return m_wallet->DisplayAddress(dest);
249 bool lockCoin(
const COutPoint& output,
const bool write_to_db)
override
252 std::unique_ptr<WalletBatch> batch = write_to_db ? std::make_unique<WalletBatch>(
m_wallet->GetDatabase()) : nullptr;
253 return m_wallet->LockCoin(output, batch.get());
255 bool unlockCoin(
const COutPoint& output)
override
258 std::unique_ptr<WalletBatch> batch = std::make_unique<WalletBatch>(
m_wallet->GetDatabase());
259 return m_wallet->UnlockCoin(output, batch.get());
261 bool isLockedCoin(
const COutPoint& output)
override
264 return m_wallet->IsLockedCoin(output);
266 void listLockedCoins(std::vector<COutPoint>& outputs)
override
269 return m_wallet->ListLockedCoins(outputs);
272 const CCoinControl& coin_control,
281 const auto& txr = *res;
283 change_pos = txr.change_pos ? int(*txr.change_pos) : -1;
292 m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
294 bool transactionCanBeAbandoned(
const uint256& txid)
override {
return m_wallet->TransactionCanBeAbandoned(txid); }
295 bool abandonTransaction(
const uint256& txid)
override
298 return m_wallet->AbandonTransaction(txid);
300 bool transactionCanBeBumped(
const uint256& txid)
override
304 bool createBumpTransaction(
const uint256& txid,
305 const CCoinControl& coin_control,
306 std::vector<bilingual_str>& errors,
311 std::vector<CTxOut> outputs;
315 bool commitBumpTransaction(
const uint256& txid,
317 std::vector<bilingual_str>& errors,
326 auto mi =
m_wallet->mapWallet.find(txid);
327 if (mi !=
m_wallet->mapWallet.end()) {
328 return mi->second.tx;
335 auto mi =
m_wallet->mapWallet.find(txid);
336 if (mi !=
m_wallet->mapWallet.end()) {
337 return MakeWalletTx(*
m_wallet, mi->second);
341 std::set<WalletTx> getWalletTxs()
override
344 std::set<WalletTx> result;
345 for (
const auto& entry :
m_wallet->mapWallet) {
346 result.emplace(MakeWalletTx(*
m_wallet, entry.second));
350 bool tryGetTxStatus(
const uint256& txid,
353 int64_t& block_time)
override
356 if (!locked_wallet) {
359 auto mi =
m_wallet->mapWallet.find(txid);
360 if (mi ==
m_wallet->mapWallet.end()) {
363 num_blocks =
m_wallet->GetLastBlockHeight();
366 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
373 int& num_blocks)
override
376 auto mi =
m_wallet->mapWallet.find(txid);
377 if (mi !=
m_wallet->mapWallet.end()) {
378 num_blocks =
m_wallet->GetLastBlockHeight();
379 in_mempool = mi->second.InMempool();
380 order_form = mi->second.vOrderForm;
381 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
382 return MakeWalletTx(*
m_wallet, mi->second);
386 std::optional<PSBTError> fillPSBT(
int sighash_type,
391 bool& complete)
override
393 return m_wallet->FillPSBT(psbtx, complete, sighash_type,
sign, bip32derivs, n_signed);
399 result.
balance = bal.m_mine_trusted;
408 if (!locked_wallet) {
411 block_hash =
m_wallet->GetLastBlockHash();
412 balances = getBalances();
416 CAmount getAvailableBalance(
const CCoinControl& coin_control)
override
421 if (coin_control.HasSelected()) {
423 CoinSelectionParams params(rng);
426 total_amount += res->total_amount;
431 if (coin_control.m_allow_other_inputs) {
450 return m_wallet->GetDebit(txin, filter);
457 CoinsList listCoins()
override
462 auto&
group = result[entry.first];
463 for (
const auto& coin : entry.second) {
464 group.emplace_back(coin.outpoint,
470 std::vector<WalletTxOut> getCoins(
const std::vector<COutPoint>& outputs)
override
473 std::vector<WalletTxOut> result;
474 result.reserve(outputs.size());
475 for (
const auto& output : outputs) {
476 result.emplace_back();
478 if (it !=
m_wallet->mapWallet.end()) {
479 int depth =
m_wallet->GetTxDepthInMainChain(it->second);
481 result.back() = MakeWalletTxOut(*
m_wallet, it->second, output.
n, depth);
488 CAmount getMinimumFee(
unsigned int tx_bytes,
489 const CCoinControl& coin_control,
490 int* returned_target,
497 if (reason) *reason = fee_calc.
reason;
500 unsigned int getConfirmTarget()
override {
return m_wallet->m_confirm_target; }
501 bool hdEnabled()
override {
return m_wallet->IsHDEnabled(); }
502 bool canGetAddresses()
override {
return m_wallet->CanGetAddresses(); }
505 bool taprootEnabled()
override {
507 return spk_man !=
nullptr;
509 OutputType getDefaultAddressType()
override {
return m_wallet->m_default_address_type; }
510 CAmount getDefaultMaxTxFee()
override {
return m_wallet->m_default_max_tx_fee; }
511 void remove()
override
515 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override
519 std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn)
override
523 std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn)
override
527 std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn)
override
530 [fn](
const CTxDestination& address,
const std::string& label,
bool is_mine,
533 std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn)
override
538 std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn)
override
542 std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
override
563 void registerRpcs()
override
567 JSONRPCRequest wallet_request = request;
568 wallet_request.context = &m_context;
569 return command.actor(wallet_request, result, last_handler);
581 void flush()
override {}
583 void setMockTime(int64_t time)
override {
return SetMockTime(time); }
584 void schedulerMockForward(std::chrono::seconds delta)
override {
Assert(
m_context.scheduler)->MockForward(delta); }
589 DatabaseOptions options;
592 options.require_create =
true;
593 options.create_flags = wallet_creation_flags;
594 options.create_passphrase = passphrase;
605 DatabaseOptions options;
608 options.require_existing =
true;
634 .watchonly_wallet_name = res->watchonly_wallet ? std::make_optional(res->watchonly_wallet->GetName()) :
std::nullopt,
635 .solvables_wallet_name = res->solvables_wallet ?
std::make_optional(res->solvables_wallet->GetName()) :
std::nullopt,
636 .backup_path = res->backup_path,
640 bool isEncrypted(
const std::string& wallet_name)
override
643 auto it = std::find_if(wallets.begin(), wallets.end(), [&](std::shared_ptr<CWallet> w){ return w->GetName() == wallet_name; });
644 if (it != wallets.end())
return (*it)->IsCrypted();
647 DatabaseOptions options;
648 options.require_existing =
true;
652 if (!db)
return false;
653 return WalletBatch(*db).IsEncrypted();
655 std::string getWalletDir()
override
659 std::vector<std::pair<std::string, std::string>> listWalletDir()
override
661 std::vector<std::pair<std::string, std::string>> paths;
663 paths.emplace_back(fs::PathToString(path),
format);
667 std::vector<std::unique_ptr<Wallet>> getWallets()
override
669 std::vector<std::unique_ptr<Wallet>> wallets;
675 std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
override
679 WalletContext* context()
override {
return &
m_context; }
694 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.
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< Handler > MakeSignalHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
std::vector< std::pair< std::string, std::string > > WalletOrderForm
std::unique_ptr< Wallet > MakeWallet(wallet::WalletContext &context, const std::shared_ptr< wallet::CWallet > &wallet)
Return implementation of Wallet interface.
std::map< std::string, std::string > WalletValueMap
bilingual_str ErrorString(const Result< T > &result)
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.
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
void StartWallets(WalletContext &context)
Complete startup of wallets.
bool OutputIsChange(const CWallet &wallet, const CTxOut &txout)
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
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)
CAmount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
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 OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
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)
util::Result< PreSelectedInputs > FetchSelectedInputs(const CWallet &wallet, const CCoinControl &coin_control, const CoinSelectionParams &coin_selection_params)
Fetch and validate coin control selected inputs.
std::underlying_type_t< isminetype > isminefilter
used for bitflags of isminetype
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)
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< uint256 > &trusted_parents)
fs::path GetWalletDir()
Get the path of the wallet directory.
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.
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.
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
void UnloadWallets(WalletContext &context)
Close all wallets.
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
void StopWallets(WalletContext &context)
Stop all wallets. Wallets will be flushed first.
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()
CTxDestination getNewDestination(CWallet &w, OutputType output_type)
Returns a new destination, of an specific type, from the wallet.
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.
A version of CTransaction with the PSBT format.
Information about one wallet address.
Collection of wallet balances.
CAmount unconfirmed_balance
std::vector< wallet::isminetype > txin_is_mine
std::vector< CTxDestination > txout_address
std::vector< wallet::isminetype > txout_address_is_mine
std::vector< bool > txout_is_change
std::map< std::string, std::string > value_map
std::vector< wallet::isminetype > txout_is_mine
Wallet transaction output.
Updated transaction status.
unsigned int time_received
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
WalletContext struct containing references to state shared between CWallet instances,...
#define TRY_LOCK(cs, name)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
ChangeType
General change type (added, updated, removed).
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
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
is a home for public enum and struct type definitions that are used by internally by wallet code,...
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn