7#include <chainparams.h>
55 for (
const auto &txin : wtx.
tx->vin) {
61 for (
const auto &txout : wtx.
tx->vout) {
88 : std::numeric_limits<int>::max();
107 result.
txout = wtx.
tx->vout[n];
114 class WalletImpl :
public Wallet {
117 const std::shared_ptr<CWallet> &
wallet)
120 bool encryptWallet(
const SecureString &wallet_passphrase)
override {
121 return m_wallet->EncryptWallet(wallet_passphrase);
123 bool isCrypted()
override {
return m_wallet->IsCrypted(); }
124 bool lock()
override {
return m_wallet->Lock(); }
125 bool unlock(
const SecureString &wallet_passphrase)
override {
126 return m_wallet->Unlock(wallet_passphrase);
128 bool isLocked()
override {
return m_wallet->IsLocked(); }
129 bool changeWalletPassphrase(
132 return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase,
133 new_wallet_passphrase);
135 void abortRescan()
override {
m_wallet->AbortRescan(); }
136 bool backupWallet(
const std::string &filename)
override {
137 return m_wallet->BackupWallet(filename);
139 std::string getWalletName()
override {
return m_wallet->GetName(); }
142 const std::string &label)
override {
144 return m_wallet->GetNewDestination(type, label);
149 bool getPubKey(
const CScript &
script,
const CKeyID &address,
151 std::unique_ptr<SigningProvider> provider =
154 return provider->GetPubKey(address, pub_key);
160 std::string &str_sig)
override {
161 return m_wallet->SignMessage(message, pkhash, str_sig);
167 bool haveWatchOnly()
override {
168 auto spk_man =
m_wallet->GetLegacyScriptPubKeyMan();
170 return spk_man->HaveWatchOnly();
175 const std::string &purpose)
override {
179 return m_wallet->DelAddressBook(dest);
182 isminetype *is_mine, std::string *purpose)
override {
184 auto it =
m_wallet->m_address_book.find(dest);
185 if (it ==
m_wallet->m_address_book.end() || it->second.IsChange()) {
189 *
name = it->second.GetLabel();
195 *purpose = it->second.purpose;
199 std::vector<WalletAddress> getAddresses()
override {
201 std::vector<WalletAddress> result;
202 for (
const auto &item :
m_wallet->m_address_book) {
203 if (item.second.IsChange()) {
206 result.emplace_back(item.first,
m_wallet->IsMine(item.first),
207 item.second.GetLabel(),
208 item.second.purpose);
212 bool addDestData(
const CTxDestination &dest,
const std::string &key,
213 const std::string &value)
override {
216 return m_wallet->AddDestData(batch, dest, key, value);
219 const std::string &key)
override {
222 return m_wallet->EraseDestData(batch, dest, key);
224 std::vector<std::string>
225 getDestValues(
const std::string &
prefix)
override {
229 void lockCoin(
const COutPoint &output)
override {
233 void unlockCoin(
const COutPoint &output)
override {
235 return m_wallet->UnlockCoin(output);
237 bool isLockedCoin(
const COutPoint &output)
override {
239 return m_wallet->IsLockedCoin(output);
241 void listLockedCoins(std::vector<COutPoint> &outputs)
override {
243 return m_wallet->ListLockedCoins(outputs);
246 createTransaction(
const std::vector<CRecipient> &recipients,
248 int &change_pos,
Amount &fee)
override {
255 const auto &txr = *res;
257 change_pos = txr.change_pos;
264 m_wallet->CommitTransaction(std::move(tx), std::move(value_map),
265 std::move(order_form));
267 bool transactionCanBeAbandoned(
const TxId &txid)
override {
268 return m_wallet->TransactionCanBeAbandoned(txid);
270 bool abandonTransaction(
const TxId &txid)
override {
272 return m_wallet->AbandonTransaction(txid);
276 auto mi =
m_wallet->mapWallet.find(txid);
277 if (mi !=
m_wallet->mapWallet.end()) {
278 return mi->second.tx;
284 auto mi =
m_wallet->mapWallet.find(txid);
285 if (mi !=
m_wallet->mapWallet.end()) {
286 return MakeWalletTx(*
m_wallet, mi->second);
290 std::vector<WalletTx> getWalletTxs()
override {
292 std::vector<WalletTx> result;
293 result.reserve(
m_wallet->mapWallet.size());
294 for (
const auto &entry :
m_wallet->mapWallet) {
295 result.emplace_back(MakeWalletTx(*
m_wallet, entry.second));
299 bool tryGetTxStatus(
const TxId &txid,
301 int &num_blocks, int64_t &block_time)
override {
303 if (!locked_wallet) {
306 auto mi =
m_wallet->mapWallet.find(txid);
307 if (mi ==
m_wallet->mapWallet.end()) {
310 num_blocks =
m_wallet->GetLastBlockHeight();
314 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
320 int &num_blocks)
override {
322 auto mi =
m_wallet->mapWallet.find(txid);
323 if (mi !=
m_wallet->mapWallet.end()) {
324 num_blocks =
m_wallet->GetLastBlockHeight();
325 in_mempool = mi->second.InMempool();
326 order_form = mi->second.vOrderForm;
327 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
328 return MakeWalletTx(*
m_wallet, mi->second);
332 std::optional<PSBTError> fillPSBT(
SigHashType sighash_type,
bool sign,
335 bool &complete)
const override {
336 return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign,
342 result.
balance = bal.m_mine_trusted;
349 bal.m_watchonly_untrusted_pending;
357 if (!locked_wallet) {
360 block_hash =
m_wallet->GetLastBlockHash();
361 balances = getBalances();
364 Amount getBalance()
override {
370 isminetype txinIsMine(
const CTxIn &txin)
override {
380 return m_wallet->GetDebit(txin, filter);
386 CoinsList listCoins()
override {
390 auto &group = result[entry.first];
391 for (
const auto &coin : entry.second) {
392 group.emplace_back(COutPoint(coin.tx->GetId(), coin.i),
393 MakeWalletTxOut(*
m_wallet, *coin.tx,
394 coin.i, coin.nDepth));
399 std::vector<WalletTxOut>
400 getCoins(
const std::vector<COutPoint> &outputs)
override {
402 std::vector<WalletTxOut> result;
403 result.reserve(outputs.size());
404 for (
const auto &output : outputs) {
405 result.emplace_back();
406 auto it =
m_wallet->mapWallet.find(output.GetTxId());
407 if (it !=
m_wallet->mapWallet.end()) {
408 int depth =
m_wallet->GetTxDepthInMainChain(it->second);
410 result.back() = MakeWalletTxOut(*
m_wallet, it->second,
411 output.GetN(), depth);
417 bool hdEnabled()
override {
return m_wallet->IsHDEnabled(); }
419 return m_wallet->m_default_address_type;
421 bool canGetAddresses()
const override {
424 bool privateKeysDisabled()
override {
427 Amount getDefaultMaxTxFee()
override {
428 return m_wallet->m_default_max_tx_fee;
430 void remove()
override {
433 bool isLegacy()
override {
return m_wallet->IsLegacy(); }
434 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override {
437 std::unique_ptr<Handler>
438 handleShowProgress(ShowProgressFn fn)
override {
441 std::unique_ptr<Handler>
442 handleStatusChanged(StatusChangedFn fn)
override {
446 std::unique_ptr<Handler>
447 handleAddressBookChanged(AddressBookChangedFn fn)
override {
450 const std::string &label,
bool is_mine,
451 const std::string &purpose,
ChangeType status) {
452 fn(address, label, is_mine, purpose, status);
455 std::unique_ptr<Handler>
456 handleTransactionChanged(TransactionChangedFn fn)
override {
462 std::unique_ptr<Handler>
463 handleWatchOnlyChanged(WatchOnlyChangedFn fn)
override {
466 std::unique_ptr<Handler>
467 handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
override {
469 m_wallet->NotifyCanGetAddressesChanged.connect(fn));
471 Amount getRequiredFee(
unsigned int tx_bytes)
override {
474 Amount getMinimumFee(
unsigned int tx_bytes,
496 command.category, command.name,
497 [
this, &command](
const Config &config,
499 UniValue &result,
bool last_handler) {
500 JSONRPCRequest wallet_request = request;
501 wallet_request.context = &m_context;
502 return command.actor(config, wallet_request, result,
505 command.argNames, command.unique_id);
511 void registerRpcs()
override {
523 void setMockTime(int64_t time)
override {
return SetMockTime(time); }
528 uint64_t wallet_creation_flags,
529 std::vector<bilingual_str> &warnings)
override {
538 options, status, error, warnings))};
543 return {std::move(
wallet)};
548 loadWallet(
const std::string &
name,
549 std::vector<bilingual_str> &warnings)
override {
556 options, status, error, warnings))};
561 return {std::move(
wallet)};
566 restoreWallet(
const fs::path &backup_file,
567 const std::string &wallet_name,
568 std::vector<bilingual_str> &warnings)
override {
579 return {std::move(
wallet)};
583 std::string getWalletDir()
override {
586 std::vector<std::string> listWalletDir()
override {
587 std::vector<std::string> paths;
594 std::vector<std::unique_ptr<Wallet>> getWallets()
override {
595 std::vector<std::unique_ptr<Wallet>> wallets;
602 std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
override {
617 const std::shared_ptr<CWallet> &
wallet) {
618 return wallet ? std::make_unique<wallet::WalletImpl>(context,
wallet)
624 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.
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