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