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