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