Bitcoin Core  22.99.0
P2P Digital Currency
interfaces.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <interfaces/wallet.h>
6 
7 #include <consensus/amount.h>
8 #include <interfaces/chain.h>
9 #include <interfaces/handler.h>
10 #include <policy/fees.h>
11 #include <primitives/transaction.h>
12 #include <rpc/server.h>
13 #include <script/standard.h>
15 #include <sync.h>
16 #include <uint256.h>
17 #include <util/check.h>
18 #include <util/system.h>
19 #include <util/translation.h>
20 #include <util/ui_change_type.h>
21 #include <wallet/context.h>
22 #include <wallet/feebumper.h>
23 #include <wallet/fees.h>
24 #include <wallet/ismine.h>
25 #include <wallet/load.h>
26 #include <wallet/receive.h>
27 #include <wallet/rpc/wallet.h>
28 #include <wallet/spend.h>
29 #include <wallet/wallet.h>
30 
31 #include <memory>
32 #include <string>
33 #include <utility>
34 #include <vector>
35 
36 using interfaces::Chain;
40 using interfaces::Wallet;
49 
50 namespace wallet {
51 namespace {
53 WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
54 {
55  LOCK(wallet.cs_wallet);
56  WalletTx result;
57  result.tx = wtx.tx;
58  result.txin_is_mine.reserve(wtx.tx->vin.size());
59  for (const auto& txin : wtx.tx->vin) {
60  result.txin_is_mine.emplace_back(InputIsMine(wallet, txin));
61  }
62  result.txout_is_mine.reserve(wtx.tx->vout.size());
63  result.txout_address.reserve(wtx.tx->vout.size());
64  result.txout_address_is_mine.reserve(wtx.tx->vout.size());
65  for (const auto& txout : wtx.tx->vout) {
66  result.txout_is_mine.emplace_back(wallet.IsMine(txout));
67  result.txout_address.emplace_back();
68  result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
69  wallet.IsMine(result.txout_address.back()) :
70  ISMINE_NO);
71  }
72  result.credit = CachedTxGetCredit(wallet, wtx, ISMINE_ALL);
73  result.debit = CachedTxGetDebit(wallet, wtx, ISMINE_ALL);
74  result.change = CachedTxGetChange(wallet, wtx);
75  result.time = wtx.GetTxTime();
76  result.value_map = wtx.mapValue;
77  result.is_coinbase = wtx.IsCoinBase();
78  return result;
79 }
80 
82 WalletTxStatus MakeWalletTxStatus(const CWallet& wallet, const CWalletTx& wtx)
83 {
84  WalletTxStatus result;
85  result.block_height =
86  wtx.state<TxStateConfirmed>() ? wtx.state<TxStateConfirmed>()->confirmed_block_height :
87  wtx.state<TxStateConflicted>() ? wtx.state<TxStateConflicted>()->conflicting_block_height :
88  std::numeric_limits<int>::max();
89  result.blocks_to_maturity = wallet.GetTxBlocksToMaturity(wtx);
90  result.depth_in_main_chain = wallet.GetTxDepthInMainChain(wtx);
91  result.time_received = wtx.nTimeReceived;
92  result.lock_time = wtx.tx->nLockTime;
93  result.is_trusted = CachedTxIsTrusted(wallet, wtx);
94  result.is_abandoned = wtx.isAbandoned();
95  result.is_coinbase = wtx.IsCoinBase();
96  result.is_in_main_chain = wallet.IsTxInMainChain(wtx);
97  return result;
98 }
99 
101 WalletTxOut MakeWalletTxOut(const CWallet& wallet,
102  const CWalletTx& wtx,
103  int n,
104  int depth) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
105 {
106  WalletTxOut result;
107  result.txout = wtx.tx->vout[n];
108  result.time = wtx.GetTxTime();
109  result.depth_in_main_chain = depth;
110  result.is_spent = wallet.IsSpent(wtx.GetHash(), n);
111  return result;
112 }
113 
114 class WalletImpl : public Wallet
115 {
116 public:
117  explicit WalletImpl(WalletContext& context, const std::shared_ptr<CWallet>& wallet) : m_context(context), m_wallet(wallet) {}
118 
119  bool encryptWallet(const SecureString& wallet_passphrase) override
120  {
121  return m_wallet->EncryptWallet(wallet_passphrase);
122  }
123  bool isCrypted() override { return m_wallet->IsCrypted(); }
124  bool lock() override { return m_wallet->Lock(); }
125  bool unlock(const SecureString& wallet_passphrase) override { return m_wallet->Unlock(wallet_passphrase); }
126  bool isLocked() override { return m_wallet->IsLocked(); }
127  bool changeWalletPassphrase(const SecureString& old_wallet_passphrase,
128  const SecureString& new_wallet_passphrase) override
129  {
130  return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
131  }
132  void abortRescan() override { m_wallet->AbortRescan(); }
133  bool backupWallet(const std::string& filename) override { return m_wallet->BackupWallet(filename); }
134  std::string getWalletName() override { return m_wallet->GetName(); }
135  bool getNewDestination(const OutputType type, const std::string label, CTxDestination& dest) override
136  {
137  LOCK(m_wallet->cs_wallet);
139  return m_wallet->GetNewDestination(type, label, dest, error);
140  }
141  bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
142  {
143  std::unique_ptr<SigningProvider> provider = m_wallet->GetSolvingProvider(script);
144  if (provider) {
145  return provider->GetPubKey(address, pub_key);
146  }
147  return false;
148  }
149  SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) override
150  {
151  return m_wallet->SignMessage(message, pkhash, str_sig);
152  }
153  bool isSpendable(const CTxDestination& dest) override
154  {
155  LOCK(m_wallet->cs_wallet);
156  return m_wallet->IsMine(dest) & ISMINE_SPENDABLE;
157  }
158  bool haveWatchOnly() override
159  {
160  auto spk_man = m_wallet->GetLegacyScriptPubKeyMan();
161  if (spk_man) {
162  return spk_man->HaveWatchOnly();
163  }
164  return false;
165  };
166  bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::string& purpose) override
167  {
168  return m_wallet->SetAddressBook(dest, name, purpose);
169  }
170  bool delAddressBook(const CTxDestination& dest) override
171  {
172  return m_wallet->DelAddressBook(dest);
173  }
174  bool getAddress(const CTxDestination& dest,
175  std::string* name,
176  isminetype* is_mine,
177  std::string* purpose) override
178  {
179  LOCK(m_wallet->cs_wallet);
180  auto it = m_wallet->m_address_book.find(dest);
181  if (it == m_wallet->m_address_book.end() || it->second.IsChange()) {
182  return false;
183  }
184  if (name) {
185  *name = it->second.GetLabel();
186  }
187  if (is_mine) {
188  *is_mine = m_wallet->IsMine(dest);
189  }
190  if (purpose) {
191  *purpose = it->second.purpose;
192  }
193  return true;
194  }
195  std::vector<WalletAddress> getAddresses() override
196  {
197  LOCK(m_wallet->cs_wallet);
198  std::vector<WalletAddress> result;
199  for (const auto& item : m_wallet->m_address_book) {
200  if (item.second.IsChange()) continue;
201  result.emplace_back(item.first, m_wallet->IsMine(item.first), item.second.GetLabel(), item.second.purpose);
202  }
203  return result;
204  }
205  std::vector<std::string> getAddressReceiveRequests() override {
206  LOCK(m_wallet->cs_wallet);
207  return m_wallet->GetAddressReceiveRequests();
208  }
209  bool setAddressReceiveRequest(const CTxDestination& dest, const std::string& id, const std::string& value) override {
210  LOCK(m_wallet->cs_wallet);
211  WalletBatch batch{m_wallet->GetDatabase()};
212  return m_wallet->SetAddressReceiveRequest(batch, dest, id, value);
213  }
214  bool displayAddress(const CTxDestination& dest) override
215  {
216  LOCK(m_wallet->cs_wallet);
217  return m_wallet->DisplayAddress(dest);
218  }
219  bool lockCoin(const COutPoint& output, const bool write_to_db) override
220  {
221  LOCK(m_wallet->cs_wallet);
222  std::unique_ptr<WalletBatch> batch = write_to_db ? std::make_unique<WalletBatch>(m_wallet->GetDatabase()) : nullptr;
223  return m_wallet->LockCoin(output, batch.get());
224  }
225  bool unlockCoin(const COutPoint& output) override
226  {
227  LOCK(m_wallet->cs_wallet);
228  std::unique_ptr<WalletBatch> batch = std::make_unique<WalletBatch>(m_wallet->GetDatabase());
229  return m_wallet->UnlockCoin(output, batch.get());
230  }
231  bool isLockedCoin(const COutPoint& output) override
232  {
233  LOCK(m_wallet->cs_wallet);
234  return m_wallet->IsLockedCoin(output.hash, output.n);
235  }
236  void listLockedCoins(std::vector<COutPoint>& outputs) override
237  {
238  LOCK(m_wallet->cs_wallet);
239  return m_wallet->ListLockedCoins(outputs);
240  }
241  CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
242  const CCoinControl& coin_control,
243  bool sign,
244  int& change_pos,
245  CAmount& fee,
246  bilingual_str& fail_reason) override
247  {
248  LOCK(m_wallet->cs_wallet);
249  CTransactionRef tx;
250  FeeCalculation fee_calc_out;
251  if (!CreateTransaction(*m_wallet, recipients, tx, fee, change_pos,
252  fail_reason, coin_control, fee_calc_out, sign)) {
253  return {};
254  }
255  return tx;
256  }
257  void commitTransaction(CTransactionRef tx,
258  WalletValueMap value_map,
259  WalletOrderForm order_form) override
260  {
261  LOCK(m_wallet->cs_wallet);
262  m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
263  }
264  bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
265  bool abandonTransaction(const uint256& txid) override
266  {
267  LOCK(m_wallet->cs_wallet);
268  return m_wallet->AbandonTransaction(txid);
269  }
270  bool transactionCanBeBumped(const uint256& txid) override
271  {
272  return feebumper::TransactionCanBeBumped(*m_wallet.get(), txid);
273  }
274  bool createBumpTransaction(const uint256& txid,
275  const CCoinControl& coin_control,
276  std::vector<bilingual_str>& errors,
277  CAmount& old_fee,
278  CAmount& new_fee,
279  CMutableTransaction& mtx) override
280  {
281  return feebumper::CreateRateBumpTransaction(*m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx) == feebumper::Result::OK;
282  }
283  bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(*m_wallet.get(), mtx); }
284  bool commitBumpTransaction(const uint256& txid,
285  CMutableTransaction&& mtx,
286  std::vector<bilingual_str>& errors,
287  uint256& bumped_txid) override
288  {
289  return feebumper::CommitTransaction(*m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) ==
291  }
292  CTransactionRef getTx(const uint256& txid) override
293  {
294  LOCK(m_wallet->cs_wallet);
295  auto mi = m_wallet->mapWallet.find(txid);
296  if (mi != m_wallet->mapWallet.end()) {
297  return mi->second.tx;
298  }
299  return {};
300  }
301  WalletTx getWalletTx(const uint256& txid) override
302  {
303  LOCK(m_wallet->cs_wallet);
304  auto mi = m_wallet->mapWallet.find(txid);
305  if (mi != m_wallet->mapWallet.end()) {
306  return MakeWalletTx(*m_wallet, mi->second);
307  }
308  return {};
309  }
310  std::vector<WalletTx> getWalletTxs() override
311  {
312  LOCK(m_wallet->cs_wallet);
313  std::vector<WalletTx> result;
314  result.reserve(m_wallet->mapWallet.size());
315  for (const auto& entry : m_wallet->mapWallet) {
316  result.emplace_back(MakeWalletTx(*m_wallet, entry.second));
317  }
318  return result;
319  }
320  bool tryGetTxStatus(const uint256& txid,
321  interfaces::WalletTxStatus& tx_status,
322  int& num_blocks,
323  int64_t& block_time) override
324  {
325  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
326  if (!locked_wallet) {
327  return false;
328  }
329  auto mi = m_wallet->mapWallet.find(txid);
330  if (mi == m_wallet->mapWallet.end()) {
331  return false;
332  }
333  num_blocks = m_wallet->GetLastBlockHeight();
334  block_time = -1;
335  CHECK_NONFATAL(m_wallet->chain().findBlock(m_wallet->GetLastBlockHash(), FoundBlock().time(block_time)));
336  tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
337  return true;
338  }
339  WalletTx getWalletTxDetails(const uint256& txid,
340  WalletTxStatus& tx_status,
341  WalletOrderForm& order_form,
342  bool& in_mempool,
343  int& num_blocks) override
344  {
345  LOCK(m_wallet->cs_wallet);
346  auto mi = m_wallet->mapWallet.find(txid);
347  if (mi != m_wallet->mapWallet.end()) {
348  num_blocks = m_wallet->GetLastBlockHeight();
349  in_mempool = mi->second.InMempool();
350  order_form = mi->second.vOrderForm;
351  tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
352  return MakeWalletTx(*m_wallet, mi->second);
353  }
354  return {};
355  }
356  TransactionError fillPSBT(int sighash_type,
357  bool sign,
358  bool bip32derivs,
359  size_t* n_signed,
361  bool& complete) override
362  {
363  return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs, n_signed);
364  }
365  WalletBalances getBalances() override
366  {
367  const auto bal = GetBalance(*m_wallet);
368  WalletBalances result;
369  result.balance = bal.m_mine_trusted;
370  result.unconfirmed_balance = bal.m_mine_untrusted_pending;
371  result.immature_balance = bal.m_mine_immature;
372  result.have_watch_only = haveWatchOnly();
373  if (result.have_watch_only) {
374  result.watch_only_balance = bal.m_watchonly_trusted;
375  result.unconfirmed_watch_only_balance = bal.m_watchonly_untrusted_pending;
376  result.immature_watch_only_balance = bal.m_watchonly_immature;
377  }
378  return result;
379  }
380  bool tryGetBalances(WalletBalances& balances, uint256& block_hash) override
381  {
382  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
383  if (!locked_wallet) {
384  return false;
385  }
386  block_hash = m_wallet->GetLastBlockHash();
387  balances = getBalances();
388  return true;
389  }
390  CAmount getBalance() override { return GetBalance(*m_wallet).m_mine_trusted; }
391  CAmount getAvailableBalance(const CCoinControl& coin_control) override
392  {
393  return GetAvailableBalance(*m_wallet, &coin_control);
394  }
395  isminetype txinIsMine(const CTxIn& txin) override
396  {
397  LOCK(m_wallet->cs_wallet);
398  return InputIsMine(*m_wallet, txin);
399  }
400  isminetype txoutIsMine(const CTxOut& txout) override
401  {
402  LOCK(m_wallet->cs_wallet);
403  return m_wallet->IsMine(txout);
404  }
405  CAmount getDebit(const CTxIn& txin, isminefilter filter) override
406  {
407  LOCK(m_wallet->cs_wallet);
408  return m_wallet->GetDebit(txin, filter);
409  }
410  CAmount getCredit(const CTxOut& txout, isminefilter filter) override
411  {
412  LOCK(m_wallet->cs_wallet);
413  return OutputGetCredit(*m_wallet, txout, filter);
414  }
415  CoinsList listCoins() override
416  {
417  LOCK(m_wallet->cs_wallet);
418  CoinsList result;
419  for (const auto& entry : ListCoins(*m_wallet)) {
420  auto& group = result[entry.first];
421  for (const auto& coin : entry.second) {
422  group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i),
423  MakeWalletTxOut(*m_wallet, *coin.tx, coin.i, coin.nDepth));
424  }
425  }
426  return result;
427  }
428  std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) override
429  {
430  LOCK(m_wallet->cs_wallet);
431  std::vector<WalletTxOut> result;
432  result.reserve(outputs.size());
433  for (const auto& output : outputs) {
434  result.emplace_back();
435  auto it = m_wallet->mapWallet.find(output.hash);
436  if (it != m_wallet->mapWallet.end()) {
437  int depth = m_wallet->GetTxDepthInMainChain(it->second);
438  if (depth >= 0) {
439  result.back() = MakeWalletTxOut(*m_wallet, it->second, output.n, depth);
440  }
441  }
442  }
443  return result;
444  }
445  CAmount getRequiredFee(unsigned int tx_bytes) override { return GetRequiredFee(*m_wallet, tx_bytes); }
446  CAmount getMinimumFee(unsigned int tx_bytes,
447  const CCoinControl& coin_control,
448  int* returned_target,
449  FeeReason* reason) override
450  {
451  FeeCalculation fee_calc;
452  CAmount result;
453  result = GetMinimumFee(*m_wallet, tx_bytes, coin_control, &fee_calc);
454  if (returned_target) *returned_target = fee_calc.returnedTarget;
455  if (reason) *reason = fee_calc.reason;
456  return result;
457  }
458  unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
459  bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
460  bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
461  bool hasExternalSigner() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER); }
462  bool privateKeysDisabled() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); }
463  bool taprootEnabled() override {
464  if (m_wallet->IsLegacy()) return false;
465  auto spk_man = m_wallet->GetScriptPubKeyMan(OutputType::BECH32M, /*internal=*/false);
466  return spk_man != nullptr;
467  }
468  OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
469  CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }
470  void remove() override
471  {
472  RemoveWallet(m_context, m_wallet, false /* load_on_start */);
473  }
474  bool isLegacy() override { return m_wallet->IsLegacy(); }
475  std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
476  {
477  return MakeHandler(m_wallet->NotifyUnload.connect(fn));
478  }
479  std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
480  {
481  return MakeHandler(m_wallet->ShowProgress.connect(fn));
482  }
483  std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) override
484  {
485  return MakeHandler(m_wallet->NotifyStatusChanged.connect([fn](CWallet*) { fn(); }));
486  }
487  std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) override
488  {
489  return MakeHandler(m_wallet->NotifyAddressBookChanged.connect(
490  [fn](const CTxDestination& address, const std::string& label, bool is_mine,
491  const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); }));
492  }
493  std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override
494  {
495  return MakeHandler(m_wallet->NotifyTransactionChanged.connect(
496  [fn](const uint256& txid, ChangeType status) { fn(txid, status); }));
497  }
498  std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override
499  {
500  return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
501  }
502  std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override
503  {
504  return MakeHandler(m_wallet->NotifyCanGetAddressesChanged.connect(fn));
505  }
506  CWallet* wallet() override { return m_wallet.get(); }
507 
508  WalletContext& m_context;
509  std::shared_ptr<CWallet> m_wallet;
510 };
511 
512 class WalletLoaderImpl : public WalletLoader
513 {
514 public:
515  WalletLoaderImpl(Chain& chain, ArgsManager& args)
516  {
517  m_context.chain = &chain;
518  m_context.args = &args;
519  }
520  ~WalletLoaderImpl() override { UnloadWallets(m_context); }
521 
523  void registerRpcs() override
524  {
525  for (const CRPCCommand& command : GetWalletRPCCommands()) {
526  m_rpc_commands.emplace_back(command.category, command.name, [this, &command](const JSONRPCRequest& request, UniValue& result, bool last_handler) {
527  JSONRPCRequest wallet_request = request;
528  wallet_request.context = &m_context;
529  return command.actor(wallet_request, result, last_handler);
530  }, command.argNames, command.unique_id);
531  m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back()));
532  }
533  }
534  bool verify() override { return VerifyWallets(m_context); }
535  bool load() override { return LoadWallets(m_context); }
536  void start(CScheduler& scheduler) override { return StartWallets(m_context, scheduler); }
537  void flush() override { return FlushWallets(m_context); }
538  void stop() override { return StopWallets(m_context); }
539  void setMockTime(int64_t time) override { return SetMockTime(time); }
540 
542  std::unique_ptr<Wallet> createWallet(const std::string& name, const SecureString& passphrase, uint64_t wallet_creation_flags, bilingual_str& error, std::vector<bilingual_str>& warnings) override
543  {
544  std::shared_ptr<CWallet> wallet;
545  DatabaseOptions options;
546  DatabaseStatus status;
547  options.require_create = true;
548  options.create_flags = wallet_creation_flags;
549  options.create_passphrase = passphrase;
550  return MakeWallet(m_context, CreateWallet(m_context, name, true /* load_on_start */, options, status, error, warnings));
551  }
552  std::unique_ptr<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
553  {
554  DatabaseOptions options;
555  DatabaseStatus status;
556  options.require_existing = true;
557  return MakeWallet(m_context, LoadWallet(m_context, name, true /* load_on_start */, options, status, error, warnings));
558  }
559  std::unique_ptr<Wallet> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
560  {
561  DatabaseStatus status;
562 
563  return MakeWallet(m_context, RestoreWallet(m_context, backup_file, wallet_name, /*load_on_start=*/true, status, error, warnings));
564  }
565  std::string getWalletDir() override
566  {
567  return fs::PathToString(GetWalletDir());
568  }
569  std::vector<std::string> listWalletDir() override
570  {
571  std::vector<std::string> paths;
572  for (auto& path : ListDatabases(GetWalletDir())) {
573  paths.push_back(fs::PathToString(path));
574  }
575  return paths;
576  }
577  std::vector<std::unique_ptr<Wallet>> getWallets() override
578  {
579  std::vector<std::unique_ptr<Wallet>> wallets;
580  for (const auto& wallet : GetWallets(m_context)) {
581  wallets.emplace_back(MakeWallet(m_context, wallet));
582  }
583  return wallets;
584  }
585  std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
586  {
587  return HandleLoadWallet(m_context, std::move(fn));
588  }
589  WalletContext* context() override { return &m_context; }
590 
591  WalletContext m_context;
592  const std::vector<std::string> m_wallet_filenames;
593  std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
594  std::list<CRPCCommand> m_rpc_commands;
595 };
596 } // namespace
597 } // namespace wallet
598 
599 namespace interfaces {
600 std::unique_ptr<Wallet> MakeWallet(wallet::WalletContext& context, const std::shared_ptr<wallet::CWallet>& wallet) { return wallet ? std::make_unique<wallet::WalletImpl>(context, wallet) : nullptr; }
601 
602 std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args)
603 {
604  return std::make_unique<wallet::WalletLoaderImpl>(chain, args);
605 }
606 } // namespace interfaces
wallet::StartWallets
void StartWallets(WalletContext &context, CScheduler &scheduler)
Complete startup of wallets.
Definition: load.cpp:139
CTxIn
An input of a transaction.
Definition: transaction.h:65
interfaces
Definition: dummywallet.cpp:10
FeeReason
FeeReason
Definition: fees.h:43
CScheduler
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:33
OutputType
OutputType
Definition: outputtype.h:18
wallet::isminetype
isminetype
IsMine() return codes, which depend on ScriptPubKeyMan implementation.
Definition: ismine.h:41
ui_change_type.h
wallet::isminefilter
std::underlying_type< isminetype >::type isminefilter
used for bitflags of isminetype
Definition: wallet.h:40
check.h
wallet.h
CHECK_NONFATAL
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
Definition: check.h:32
wallet::ListDatabases
std::vector< fs::path > ListDatabases(const fs::path &wallet_dir)
Recursively list database paths in directory.
Definition: db.cpp:18
interfaces::WalletTxStatus::depth_in_main_chain
int depth_in_main_chain
Definition: wallet.h:405
m_context
NodeContext * m_context
Definition: interfaces.cpp:343
wallet::UnloadWallets
void UnloadWallets(WalletContext &context)
Close all wallets.
Definition: load.cpp:166
interfaces::WalletTxOut::depth_in_main_chain
int depth_in_main_chain
Definition: wallet.h:419
wallet::DatabaseStatus
DatabaseStatus
Definition: db.h:213
sync.h
wallet::HandleLoadWallet
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
Definition: wallet.cpp:163
transaction.h
FeeCalculation::returnedTarget
int returnedTarget
Definition: fees.h:80
COutPoint::hash
uint256 hash
Definition: transaction.h:29
bilingual_str
Bilingual messages:
Definition: translation.h:16
uint256.h
interfaces::WalletTx::is_coinbase
bool is_coinbase
Definition: wallet.h:397
interfaces::WalletTxStatus::block_height
int block_height
Definition: wallet.h:403
interfaces::WalletBalances::unconfirmed_balance
CAmount unconfirmed_balance
Definition: wallet.h:368
handler.h
wallet::GetAvailableBalance
CAmount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
Definition: spend.cpp:213
wallet
Definition: node.h:38
interfaces::WalletBalances::have_watch_only
bool have_watch_only
Definition: wallet.h:370
interfaces::WalletTxOut
Wallet transaction output.
Definition: wallet.h:415
wallet::GetMinimumFee
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.
Definition: fees.cpp:19
TRY_LOCK
#define TRY_LOCK(cs, name)
Definition: sync.h:230
CKeyID
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:23
wallet::feebumper::TransactionCanBeBumped
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
Definition: feebumper.cpp:146
interfaces::WalletBalances::immature_watch_only_balance
CAmount immature_watch_only_balance
Definition: wallet.h:373
fs::PathToString
static std::string PathToString(const path &path)
Convert path object to a byte string.
Definition: fs.h:112
chain.h
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:406
interfaces::WalletTx::time
int64_t time
Definition: wallet.h:395
interfaces::WalletBalances::balance
CAmount balance
Definition: wallet.h:367
wallet
std::shared_ptr< CWallet > wallet
Definition: notifications.cpp:38
wallet::InputIsMine
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
Definition: receive.cpp:12
SigningResult
SigningResult
Definition: message.h:42
UniValue
Definition: univalue.h:17
interfaces::WalletTx::txout_is_mine
std::vector< wallet::isminetype > txout_is_mine
Definition: wallet.h:389
interfaces::WalletTxStatus::is_coinbase
bool is_coinbase
Definition: wallet.h:410
wallet::CachedTxIsTrusted
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< uint256 > &trusted_parents)
Definition: receive.cpp:279
wallet::FlushWallets
void FlushWallets(WalletContext &context)
Flush all wallets in preparation for shutdown.
Definition: load.cpp:152
m_rpc_commands
std::list< CRPCCommand > m_rpc_commands
Definition: interfaces.cpp:594
wallet::GetWallets
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition: wallet.cpp:148
OutputType::BECH32M
@ BECH32M
LoadWalletFn
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition: wallet.h:45
FeeCalculation::reason
FeeReason reason
Definition: fees.h:78
wallet::WALLET_FLAG_EXTERNAL_SIGNER
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
Definition: walletutil.h:69
interfaces::WalletBalances::watch_only_balance
CAmount watch_only_balance
Definition: wallet.h:371
ismine.h
load.h
fees.h
TransactionError
TransactionError
Definition: error.h:22
interfaces::WalletTx::value_map
std::map< std::string, std::string > value_map
Definition: wallet.h:396
interfaces::Chain
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:94
SecureString
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:59
FeeCalculation
Definition: fees.h:75
ChangeType
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
interfaces::WalletBalances
Collection of wallet balances.
Definition: wallet.h:365
CTxDestination
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:157
wallet::feebumper::CommitTransaction
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:251
CTxOut
An output of a transaction.
Definition: transaction.h:148
CRPCCommand
Definition: server.h:89
interfaces::WalletTx::change
CAmount change
Definition: wallet.h:394
fs::path
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:29
SetMockTime
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:101
m_wallet_filenames
const std::vector< std::string > m_wallet_filenames
Definition: interfaces.cpp:592
interfaces::WalletTx::debit
CAmount debit
Definition: wallet.h:393
wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:51
feebumper.h
interfaces::WalletTx
Definition: wallet.h:385
wallet::LoadWallets
bool LoadWallets(WalletContext &context)
Load wallet databases.
Definition: load.cpp:103
interfaces::WalletLoader
Wallet chain client that in addition to having chain client methods for starting up,...
Definition: wallet.h:319
verify
static bool verify(const CScriptNum10 &bignum, const CScriptNum &scriptnum)
Definition: scriptnum_tests.cpp:21
wallet::GetWalletRPCCommands
Span< const CRPCCommand > GetWalletRPCCommands()
Definition: wallet.cpp:659
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
standard.h
context
WalletContext context
Definition: notifications.cpp:37
wallet::CreateWallet
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)
Definition: wallet.cpp:263
interfaces::WalletTx::txin_is_mine
std::vector< wallet::isminetype > txin_is_mine
Definition: wallet.h:388
interfaces::FoundBlock
Helper for findBlock to selectively return pieces of block data.
Definition: chain.h:43
uint256
256-bit opaque blob.
Definition: uint256.h:126
interfaces::WalletTxStatus
Updated transaction status.
Definition: wallet.h:401
wallet::OutputGetCredit
CAmount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
Definition: receive.cpp:46
interfaces::Wallet
Interface for accessing a wallet.
Definition: wallet.h:56
interfaces::WalletTxStatus::is_in_main_chain
bool is_in_main_chain
Definition: wallet.h:411
interfaces::WalletTxOut::txout
CTxOut txout
Definition: wallet.h:417
wallet::CachedTxGetCredit
CAmount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Definition: receive.cpp:124
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
interfaces::WalletTxStatus::blocks_to_maturity
int blocks_to_maturity
Definition: wallet.h:404
wallet::feebumper::CreateRateBumpTransaction
Result CreateRateBumpTransaction(CWallet &wallet, const uint256 &txid, const CCoinControl &coin_control, std::vector< bilingual_str > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction based on feerate estimates.
Definition: feebumper.cpp:157
ExtractDestination
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:213
interfaces::WalletOrderForm
std::vector< std::pair< std::string, std::string > > WalletOrderForm
Definition: wallet.h:52
wallet::GetRequiredFee
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
Definition: fees.cpp:13
m_rpc_handlers
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
Definition: interfaces.cpp:593
wallet::ISMINE_ALL
@ ISMINE_ALL
Definition: ismine.h:46
secure.h
wallet::CreateTransaction
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CAmount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, FeeCalculation &fee_calc_out, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: spend.cpp:931
wallet::ISMINE_SPENDABLE
@ ISMINE_SPENDABLE
Definition: ismine.h:44
name
const char * name
Definition: rest.cpp:52
interfaces::WalletBalances::immature_balance
CAmount immature_balance
Definition: wallet.h:369
wallet::VerifyWallets
bool VerifyWallets(WalletContext &context)
Responsible for reading and validating the -wallet arguments and verifying the wallet database.
Definition: load.cpp:25
system.h
PKHash
Definition: standard.h:79
stop
static RPCHelpMan stop()
Definition: server.cpp:161
interfaces::WalletTxStatus::is_trusted
bool is_trusted
Definition: wallet.h:408
CPubKey
An encapsulated public key.
Definition: pubkey.h:33
wallet::feebumper::SignTransaction
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Definition: feebumper.cpp:246
fees.h
wallet::ListCoins
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
Definition: spend.cpp:246
ArgsManager
Definition: system.h:164
translation.h
interfaces::WalletTxOut::is_spent
bool is_spent
Definition: wallet.h:420
wallet::LoadWallet
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)
Definition: wallet.cpp:250
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
COutPoint::n
uint32_t n
Definition: transaction.h:30
PartiallySignedTransaction
A version of CTransaction with the PSBT format.
Definition: psbt.h:668
interfaces::WalletTxStatus::lock_time
uint32_t lock_time
Definition: wallet.h:407
LOCK
#define LOCK(cs)
Definition: sync.h:226
wallet::RestoreWallet
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)
Definition: wallet.cpp:361
interfaces::WalletValueMap
std::map< std::string, std::string > WalletValueMap
Definition: wallet.h:53
interfaces::WalletTx::credit
CAmount credit
Definition: wallet.h:392
wallet::GetWalletDir
fs::path GetWalletDir()
Get the path of the wallet directory.
Definition: walletutil.cpp:11
m_wallet
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:509
wallet::ISMINE_NO
@ ISMINE_NO
Definition: ismine.h:42
interfaces::WalletTxStatus::is_abandoned
bool is_abandoned
Definition: wallet.h:409
interfaces::WalletTx::txout_address
std::vector< CTxDestination > txout_address
Definition: wallet.h:390
wallet::GetBalance
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
Definition: receive.cpp:316
wallet::CachedTxGetChange
CAmount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
Definition: receive.cpp:156
context.h
wallet.h
receive.h
wallet::CachedTxGetDebit
CAmount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
Definition: receive.cpp:141
interfaces::WalletBalances::unconfirmed_watch_only_balance
CAmount unconfirmed_watch_only_balance
Definition: wallet.h:372
JSONRPCRequest
Definition: request.h:28
interfaces::WalletTx::txout_address_is_mine
std::vector< wallet::isminetype > txout_address_is_mine
Definition: wallet.h:391
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
wallet::feebumper::Result::OK
@ OK
interfaces::MakeWallet
std::unique_ptr< Wallet > MakeWallet(wallet::WalletContext &context, const std::shared_ptr< wallet::CWallet > &wallet)
Return implementation of Wallet interface.
Definition: interfaces.cpp:600
interfaces::WalletTxStatus::time_received
unsigned int time_received
Definition: wallet.h:406
interfaces::Handler
Generic interface for managing an event handler or callback function registered with another interfac...
Definition: handler.h:22
wallet::WalletContext
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:35
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:364
interfaces::MakeWalletLoader
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
Definition: dummywallet.cpp:61
server.h
wallet::RemoveWallet
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:122
amount.h
interfaces::WalletTx::tx
CTransactionRef tx
Definition: wallet.h:387
wallet::StopWallets
void StopWallets(WalletContext &context)
Stop all wallets. Wallets will be flushed first.
Definition: load.cpp:159
interfaces::WalletTxOut::time
int64_t time
Definition: wallet.h:418
spend.h
wallet.h
wallet::Balance::m_mine_trusted
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
Definition: receive.h:53
interfaces::MakeHandler
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
Definition: handler.cpp:35
interfaces::WalletAddress
Information about one wallet address.
Definition: wallet.h:351
args
ArgsManager args
Definition: notifications.cpp:36