61 for (
const auto& txin : wtx.tx->vin) {
67 for (
const auto& txout : wtx.tx->vout) {
77 result.
time = wtx.GetTxTime();
91 wtx.state<TxStateConfirmed>() ? wtx.state<TxStateConfirmed>()->confirmed_block_height :
92 wtx.state<TxStateConflicted>() ? wtx.state<TxStateConflicted>()->conflicting_block_height :
93 std::numeric_limits<int>::max();
107 const CWalletTx& wtx,
112 result.
txout = wtx.tx->vout[n];
113 result.
time = wtx.GetTxTime();
123 result.
txout = output.txout;
124 result.
time = output.time;
130 class WalletImpl :
public Wallet 135 bool encryptWallet(
const SecureString& wallet_passphrase)
override 137 return m_wallet->EncryptWallet(wallet_passphrase);
139 bool isCrypted()
override {
return m_wallet->IsCrypted(); }
140 bool lock()
override {
return m_wallet->Lock(); }
141 bool unlock(
const SecureString& wallet_passphrase)
override {
return m_wallet->Unlock(wallet_passphrase); }
142 bool isLocked()
override {
return m_wallet->IsLocked(); }
143 bool changeWalletPassphrase(
const SecureString& old_wallet_passphrase,
146 return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
148 void abortRescan()
override {
m_wallet->AbortRescan(); }
149 bool backupWallet(
const std::string& filename)
override {
return m_wallet->BackupWallet(filename); }
150 std::string getWalletName()
override {
return m_wallet->GetName(); }
154 return m_wallet->GetNewDestination(type, label);
158 std::unique_ptr<SigningProvider> provider =
m_wallet->GetSolvingProvider(script);
160 return provider->GetPubKey(address, pub_key);
164 SigningResult signMessage(
const std::string& message,
const PKHash& pkhash, std::string& str_sig)
override 166 return m_wallet->SignMessage(message, pkhash, str_sig);
173 bool haveWatchOnly()
override 175 auto spk_man =
m_wallet->GetLegacyScriptPubKeyMan();
177 return spk_man->HaveWatchOnly();
181 bool setAddressBook(
const CTxDestination& dest,
const std::string&
name,
const std::string& purpose)
override 187 return m_wallet->DelAddressBook(dest);
192 std::string* purpose)
override 195 const auto& entry =
m_wallet->FindAddressBookEntry(dest,
false);
196 if (!entry)
return false;
198 *
name = entry->GetLabel();
204 *purpose = entry->purpose;
208 std::vector<WalletAddress> getAddresses()
const override 211 std::vector<WalletAddress> result;
213 if (is_change) return;
214 result.emplace_back(dest, m_wallet->IsMine(dest), label, purpose);
218 std::vector<std::string> getAddressReceiveRequests()
override {
220 return m_wallet->GetAddressReceiveRequests();
222 bool setAddressReceiveRequest(
const CTxDestination& dest,
const std::string&
id,
const std::string& value)
override {
224 WalletBatch batch{
m_wallet->GetDatabase()};
225 return m_wallet->SetAddressReceiveRequest(batch, dest,
id, value);
230 return m_wallet->DisplayAddress(dest);
232 bool lockCoin(
const COutPoint& output,
const bool write_to_db)
override 235 std::unique_ptr<WalletBatch> batch = write_to_db ? std::make_unique<WalletBatch>(
m_wallet->GetDatabase()) :
nullptr;
236 return m_wallet->LockCoin(output, batch.get());
238 bool unlockCoin(
const COutPoint& output)
override 241 std::unique_ptr<WalletBatch> batch = std::make_unique<WalletBatch>(
m_wallet->GetDatabase());
242 return m_wallet->UnlockCoin(output, batch.get());
244 bool isLockedCoin(
const COutPoint& output)
override 247 return m_wallet->IsLockedCoin(output);
249 void listLockedCoins(std::vector<COutPoint>& outputs)
override 252 return m_wallet->ListLockedCoins(outputs);
255 const CCoinControl& coin_control,
264 const auto& txr = *res;
266 change_pos = txr.change_pos;
275 m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
277 bool transactionCanBeAbandoned(
const uint256& txid)
override {
return m_wallet->TransactionCanBeAbandoned(txid); }
278 bool abandonTransaction(
const uint256& txid)
override 281 return m_wallet->AbandonTransaction(txid);
283 bool transactionCanBeBumped(
const uint256& txid)
override 287 bool createBumpTransaction(
const uint256& txid,
288 const CCoinControl& coin_control,
289 std::vector<bilingual_str>& errors,
297 bool commitBumpTransaction(
const uint256& txid,
299 std::vector<bilingual_str>& errors,
308 auto mi =
m_wallet->mapWallet.find(txid);
309 if (mi !=
m_wallet->mapWallet.end()) {
310 return mi->second.tx;
317 auto mi =
m_wallet->mapWallet.find(txid);
318 if (mi !=
m_wallet->mapWallet.end()) {
319 return MakeWalletTx(*
m_wallet, mi->second);
323 std::set<WalletTx> getWalletTxs()
override 326 std::set<WalletTx> result;
327 for (
const auto& entry :
m_wallet->mapWallet) {
328 result.emplace(MakeWalletTx(*
m_wallet, entry.second));
332 bool tryGetTxStatus(
const uint256& txid,
335 int64_t& block_time)
override 338 if (!locked_wallet) {
341 auto mi =
m_wallet->mapWallet.find(txid);
342 if (mi ==
m_wallet->mapWallet.end()) {
345 num_blocks =
m_wallet->GetLastBlockHeight();
348 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
355 int& num_blocks)
override 358 auto mi =
m_wallet->mapWallet.find(txid);
359 if (mi !=
m_wallet->mapWallet.end()) {
360 num_blocks =
m_wallet->GetLastBlockHeight();
361 in_mempool = mi->second.InMempool();
362 order_form = mi->second.vOrderForm;
363 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
364 return MakeWalletTx(*
m_wallet, mi->second);
373 bool& complete)
override 375 return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs, n_signed);
381 result.
balance = bal.m_mine_trusted;
395 if (!locked_wallet) {
398 block_hash =
m_wallet->GetLastBlockHash();
399 balances = getBalances();
403 CAmount getAvailableBalance(
const CCoinControl& coin_control)
override 420 return m_wallet->GetDebit(txin, filter);
427 CoinsList listCoins()
override 432 auto& group = result[entry.first];
433 for (
const auto& coin : entry.second) {
434 group.emplace_back(coin.outpoint,
440 std::vector<WalletTxOut> getCoins(
const std::vector<COutPoint>& outputs)
override 443 std::vector<WalletTxOut> result;
444 result.reserve(outputs.size());
445 for (
const auto& output : outputs) {
446 result.emplace_back();
448 if (it !=
m_wallet->mapWallet.end()) {
449 int depth =
m_wallet->GetTxDepthInMainChain(it->second);
451 result.back() = MakeWalletTxOut(*
m_wallet, it->second, output.
n, depth);
458 CAmount getMinimumFee(
unsigned int tx_bytes,
459 const CCoinControl& coin_control,
460 int* returned_target,
467 if (reason) *reason = fee_calc.
reason;
470 unsigned int getConfirmTarget()
override {
return m_wallet->m_confirm_target; }
471 bool hdEnabled()
override {
return m_wallet->IsHDEnabled(); }
472 bool canGetAddresses()
override {
return m_wallet->CanGetAddresses(); }
475 bool taprootEnabled()
override {
476 if (
m_wallet->IsLegacy())
return false;
478 return spk_man !=
nullptr;
480 OutputType getDefaultAddressType()
override {
return m_wallet->m_default_address_type; }
481 CAmount getDefaultMaxTxFee()
override {
return m_wallet->m_default_max_tx_fee; }
482 void remove()
override 486 bool isLegacy()
override {
return m_wallet->IsLegacy(); }
487 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override 491 std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn)
override 495 std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn)
override 499 std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn)
override 502 [fn](
const CTxDestination& address,
const std::string& label,
bool is_mine,
503 const std::string& purpose,
ChangeType status) { fn(address, label, is_mine, purpose, status); }));
505 std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn)
override 510 std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn)
override 514 std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
override 535 void registerRpcs()
override 539 JSONRPCRequest wallet_request = request;
540 wallet_request.context = &m_context;
541 return command.actor(wallet_request, result, last_handler);
551 void setMockTime(int64_t time)
override {
return SetMockTime(time); }
556 DatabaseOptions options;
559 options.require_create =
true;
560 options.create_flags = wallet_creation_flags;
561 options.create_passphrase = passphrase;
565 return {std::move(
wallet)};
572 DatabaseOptions options;
575 options.require_existing =
true;
579 return {std::move(
wallet)};
590 return {std::move(
wallet)};
595 std::string getWalletDir()
override 599 std::vector<std::string> listWalletDir()
override 601 std::vector<std::string> paths;
607 std::vector<std::unique_ptr<Wallet>> getWallets()
override 609 std::vector<std::unique_ptr<Wallet>> wallets;
615 std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
override 634 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
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination 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
#define TRY_LOCK(cs, name)
std::vector< wallet::isminetype > txin_is_mine
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.
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
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)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::vector< wallet::isminetype > txout_is_mine
bool VerifyWallets(WalletContext &context)
Responsible for reading and validating the -wallet arguments and verifying the wallet database...
CAmount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
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.
void StartWallets(WalletContext &context, CScheduler &scheduler)
Complete startup of wallets.
Collection of wallet balances.
An input of a transaction.
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)
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
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.
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...
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
A reference to a CKey: the Hash160 of its serialized public key.
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.
util::Result< CreatedTransactionResult > CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, 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::pair< std::string, std::string > > WalletOrderForm
bilingual_str ErrorString(const Result< T > &result)
Information about one wallet address.
A mutable version of CTransaction.
std::vector< fs::path > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
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)
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)
Create bumpfee transaction based on feerate estimates.
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.
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:...
bool error(const char *fmt, const Args &... args)
Updated transaction status.
FoundBlock & time(int64_t &time)
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