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