7#include <chainparams.h>
54 for (
const auto &txin : wtx.
tx->vin) {
60 for (
const auto &txout : wtx.
tx->vout) {
87 : std::numeric_limits<int>::max();
106 result.
txout = wtx.
tx->vout[n];
113 class WalletImpl :
public Wallet {
116 const std::shared_ptr<CWallet> &
wallet)
119 bool encryptWallet(
const SecureString &wallet_passphrase)
override {
120 return m_wallet->EncryptWallet(wallet_passphrase);
122 bool isCrypted()
override {
return m_wallet->IsCrypted(); }
123 bool lock()
override {
return m_wallet->Lock(); }
124 bool unlock(
const SecureString &wallet_passphrase)
override {
125 return m_wallet->Unlock(wallet_passphrase);
127 bool isLocked()
override {
return m_wallet->IsLocked(); }
128 bool changeWalletPassphrase(
131 return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase,
132 new_wallet_passphrase);
134 void abortRescan()
override {
m_wallet->AbortRescan(); }
135 bool backupWallet(
const std::string &filename)
override {
136 return m_wallet->BackupWallet(filename);
138 std::string getWalletName()
override {
return m_wallet->GetName(); }
141 const std::string &label)
override {
143 return m_wallet->GetNewDestination(type, label);
148 bool getPubKey(
const CScript &script,
const CKeyID &address,
150 std::unique_ptr<SigningProvider> provider =
151 m_wallet->GetSolvingProvider(script);
153 return provider->GetPubKey(address, pub_key);
159 std::string &str_sig)
override {
160 return m_wallet->SignMessage(message, pkhash, str_sig);
166 bool haveWatchOnly()
override {
167 auto spk_man =
m_wallet->GetLegacyScriptPubKeyMan();
169 return spk_man->HaveWatchOnly();
174 const std::string &purpose)
override {
178 return m_wallet->DelAddressBook(dest);
181 isminetype *is_mine, std::string *purpose)
override {
183 auto it =
m_wallet->m_address_book.find(dest);
184 if (it ==
m_wallet->m_address_book.end() || it->second.IsChange()) {
188 *
name = it->second.GetLabel();
194 *purpose = it->second.purpose;
198 std::vector<WalletAddress> getAddresses()
override {
200 std::vector<WalletAddress> result;
201 for (
const auto &item :
m_wallet->m_address_book) {
202 if (item.second.IsChange()) {
205 result.emplace_back(item.first,
m_wallet->IsMine(item.first),
206 item.second.GetLabel(),
207 item.second.purpose);
211 bool addDestData(
const CTxDestination &dest,
const std::string &key,
212 const std::string &value)
override {
215 return m_wallet->AddDestData(batch, dest, key, value);
218 const std::string &key)
override {
221 return m_wallet->EraseDestData(batch, dest, key);
223 std::vector<std::string>
224 getDestValues(
const std::string &
prefix)
override {
228 void lockCoin(
const COutPoint &output)
override {
232 void unlockCoin(
const COutPoint &output)
override {
234 return m_wallet->UnlockCoin(output);
236 bool isLockedCoin(
const COutPoint &output)
override {
238 return m_wallet->IsLockedCoin(output);
240 void listLockedCoins(std::vector<COutPoint> &outputs)
override {
242 return m_wallet->ListLockedCoins(outputs);
245 createTransaction(
const std::vector<CRecipient> &recipients,
247 int &change_pos,
Amount &fee)
override {
254 const auto &txr = *res;
256 change_pos = txr.change_pos;
263 m_wallet->CommitTransaction(std::move(tx), std::move(value_map),
264 std::move(order_form));
266 bool transactionCanBeAbandoned(
const TxId &txid)
override {
267 return m_wallet->TransactionCanBeAbandoned(txid);
269 bool abandonTransaction(
const TxId &txid)
override {
271 return m_wallet->AbandonTransaction(txid);
275 auto mi =
m_wallet->mapWallet.find(txid);
276 if (mi !=
m_wallet->mapWallet.end()) {
277 return mi->second.tx;
283 auto mi =
m_wallet->mapWallet.find(txid);
284 if (mi !=
m_wallet->mapWallet.end()) {
285 return MakeWalletTx(*
m_wallet, mi->second);
289 std::vector<WalletTx> getWalletTxs()
override {
291 std::vector<WalletTx> result;
292 result.reserve(
m_wallet->mapWallet.size());
293 for (
const auto &entry :
m_wallet->mapWallet) {
294 result.emplace_back(MakeWalletTx(*
m_wallet, entry.second));
298 bool tryGetTxStatus(
const TxId &txid,
300 int &num_blocks, int64_t &block_time)
override {
302 if (!locked_wallet) {
305 auto mi =
m_wallet->mapWallet.find(txid);
306 if (mi ==
m_wallet->mapWallet.end()) {
309 num_blocks =
m_wallet->GetLastBlockHeight();
313 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
319 int &num_blocks)
override {
321 auto mi =
m_wallet->mapWallet.find(txid);
322 if (mi !=
m_wallet->mapWallet.end()) {
323 num_blocks =
m_wallet->GetLastBlockHeight();
324 in_mempool = mi->second.InMempool();
325 order_form = mi->second.vOrderForm;
326 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
327 return MakeWalletTx(*
m_wallet, mi->second);
334 bool &complete)
const override {
335 return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign,
341 result.
balance = bal.m_mine_trusted;
348 bal.m_watchonly_untrusted_pending;
356 if (!locked_wallet) {
359 block_hash =
m_wallet->GetLastBlockHash();
360 balances = getBalances();
363 Amount getBalance()
override {
369 isminetype txinIsMine(
const CTxIn &txin)
override {
379 return m_wallet->GetDebit(txin, filter);
385 CoinsList listCoins()
override {
389 auto &group = result[entry.first];
390 for (
const auto &coin : entry.second) {
391 group.emplace_back(COutPoint(coin.tx->GetId(), coin.i),
392 MakeWalletTxOut(*
m_wallet, *coin.tx,
393 coin.i, coin.nDepth));
398 std::vector<WalletTxOut>
399 getCoins(
const std::vector<COutPoint> &outputs)
override {
401 std::vector<WalletTxOut> result;
402 result.reserve(outputs.size());
403 for (
const auto &output : outputs) {
404 result.emplace_back();
405 auto it =
m_wallet->mapWallet.find(output.GetTxId());
406 if (it !=
m_wallet->mapWallet.end()) {
407 int depth =
m_wallet->GetTxDepthInMainChain(it->second);
409 result.back() = MakeWalletTxOut(*
m_wallet, it->second,
410 output.GetN(), depth);
416 bool hdEnabled()
override {
return m_wallet->IsHDEnabled(); }
418 return m_wallet->m_default_address_type;
420 bool canGetAddresses()
const override {
423 bool privateKeysDisabled()
override {
426 Amount getDefaultMaxTxFee()
override {
427 return m_wallet->m_default_max_tx_fee;
429 void remove()
override {
432 bool isLegacy()
override {
return m_wallet->IsLegacy(); }
433 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override {
436 std::unique_ptr<Handler>
437 handleShowProgress(ShowProgressFn fn)
override {
440 std::unique_ptr<Handler>
441 handleStatusChanged(StatusChangedFn fn)
override {
445 std::unique_ptr<Handler>
446 handleAddressBookChanged(AddressBookChangedFn fn)
override {
449 const std::string &label,
bool is_mine,
450 const std::string &purpose,
ChangeType status) {
451 fn(address, label, is_mine, purpose, status);
454 std::unique_ptr<Handler>
455 handleTransactionChanged(TransactionChangedFn fn)
override {
461 std::unique_ptr<Handler>
462 handleWatchOnlyChanged(WatchOnlyChangedFn fn)
override {
465 std::unique_ptr<Handler>
466 handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
override {
468 m_wallet->NotifyCanGetAddressesChanged.connect(fn));
470 Amount getRequiredFee(
unsigned int tx_bytes)
override {
473 Amount getMinimumFee(
unsigned int tx_bytes,
495 command.category, command.name,
496 [
this, &command](
const Config &config,
498 UniValue &result,
bool last_handler) {
499 JSONRPCRequest wallet_request = request;
500 wallet_request.context = &m_context;
501 return command.actor(config, wallet_request, result,
504 command.argNames, command.unique_id);
510 void registerRpcs()
override {
522 void setMockTime(int64_t time)
override {
return SetMockTime(time); }
527 uint64_t wallet_creation_flags,
528 std::vector<bilingual_str> &warnings)
override {
537 options, status,
error, warnings))};
542 return {std::move(
wallet)};
547 loadWallet(
const std::string &
name,
548 std::vector<bilingual_str> &warnings)
override {
555 options, status,
error, warnings))};
560 return {std::move(
wallet)};
565 restoreWallet(
const fs::path &backup_file,
566 const std::string &wallet_name,
567 std::vector<bilingual_str> &warnings)
override {
578 return {std::move(
wallet)};
582 std::string getWalletDir()
override {
585 std::vector<std::string> listWalletDir()
override {
586 std::vector<std::string> paths;
593 std::vector<std::unique_ptr<Wallet>> getWallets()
override {
594 std::vector<std::unique_ptr<Wallet>> wallets;
601 std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
override {
616 const std::shared_ptr<CWallet> &
wallet) {
617 return wallet ? std::make_unique<wallet::WalletImpl>(context,
wallet)
623 return std::make_unique<wallet::WalletClientImpl>(chain, args);
Span< const CRPCCommand > GetWalletDumpRPCCommands()
#define CHECK_NONFATAL(condition)
Identity function.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
A reference to a CKey: the Hash160 of its serialized public key.
An encapsulated public key.
Simple class for background tasks that should be run periodically or once "after a while".
An output of a transaction.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
mapValue_t mapValue
Key/value map with information about the transaction.
int64_t GetTxTime() const
unsigned int nTimeReceived
time received by this node
Signature hash type wrapper class.
A Span is an object that can refer to a contiguous sequence of objects.
Access to the wallet database.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
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...
Wallet chain client that in addition to having chain client methods for starting up,...
Interface for accessing a wallet.
Span< const CRPCCommand > GetWalletEncryptRPCCommands()
isminetype
IsMine() return codes.
void FlushWallets(WalletContext &context)
Flush all wallets in preparation for shutdown.
void StopWallets(WalletContext &context)
Stop all wallets. Wallets will be flushed first.
void StartWallets(WalletContext &context, CScheduler &scheduler)
Complete startup of wallets.
bool LoadWallets(WalletContext &context)
Load wallet databases.
bool VerifyWallets(WalletContext &context)
Responsible for reading and validating the -wallet arguments and verifying.
void UnloadWallets(WalletContext &context)
Close all wallets.
bool error(const char *fmt, const Args &...args)
static std::string PathToString(const path &path)
Convert path object to byte string.
std::unique_ptr< Wallet > MakeWallet(const std::shared_ptr< CWallet > &wallet)
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
std::vector< std::pair< std::string, std::string > > WalletOrderForm
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
std::map< std::string, std::string > WalletValueMap
bilingual_str ErrorString(const Result< T > &result)
std::shared_ptr< const CTransaction > CTransactionRef
Amount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
Amount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
Amount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
Amount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< TxId > &trusted_parents)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
Span< const CRPCCommand > GetWalletRPCCommands()
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
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...
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Amount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
A BlockHash is a unqiue identifier for a block.
SecureString create_passphrase
A version of CTransaction with the PSBT format.
A TxId is the identifier of a transaction.
WalletContext struct containing references to state shared between CWallet instances,...
Information about one wallet address.
Collection of wallet balances.
Amount immature_watch_only_balance
Amount unconfirmed_watch_only_balance
Amount unconfirmed_balance
Amount watch_only_balance
std::vector< CTxDestination > txout_address
std::vector< isminetype > txout_is_mine
std::map< std::string, std::string > value_map
std::vector< isminetype > txout_address_is_mine
std::vector< isminetype > txin_is_mine
Wallet transaction output.
Updated transaction status.
unsigned int time_received
#define TRY_LOCK(cs, name)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
ChangeType
General change type (added, updated, removed).
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Amount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control)
Estimate the minimum fee considering user set parameters and the required fee.
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::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
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::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)
fs::path GetWalletDir()
Get the path of the wallet directory.
std::vector< fs::path > ListWalletDir()
Get wallets in wallet directory.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS