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