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