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