Bitcoin Core  0.19.99
P2P Digital Currency
wallet.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 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 <script/standard.h>
14 #include <sync.h>
15 #include <ui_interface.h>
16 #include <uint256.h>
17 #include <util/system.h>
18 #include <wallet/feebumper.h>
19 #include <wallet/fees.h>
20 #include <wallet/ismine.h>
21 #include <wallet/load.h>
22 #include <wallet/rpcwallet.h>
23 #include <wallet/wallet.h>
24 
25 #include <memory>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 namespace interfaces {
31 namespace {
32 
34 WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
35 {
36  WalletTx result;
37  result.tx = wtx.tx;
38  result.txin_is_mine.reserve(wtx.tx->vin.size());
39  for (const auto& txin : wtx.tx->vin) {
40  result.txin_is_mine.emplace_back(wallet.IsMine(txin));
41  }
42  result.txout_is_mine.reserve(wtx.tx->vout.size());
43  result.txout_address.reserve(wtx.tx->vout.size());
44  result.txout_address_is_mine.reserve(wtx.tx->vout.size());
45  for (const auto& txout : wtx.tx->vout) {
46  result.txout_is_mine.emplace_back(wallet.IsMine(txout));
47  result.txout_address.emplace_back();
48  result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
49  wallet.IsMine(result.txout_address.back()) :
50  ISMINE_NO);
51  }
52  result.credit = wtx.GetCredit(ISMINE_ALL);
53  result.debit = wtx.GetDebit(ISMINE_ALL);
54  result.change = wtx.GetChange();
55  result.time = wtx.GetTxTime();
56  result.value_map = wtx.mapValue;
57  result.is_coinbase = wtx.IsCoinBase();
58  return result;
59 }
60 
62 WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
63 {
64  WalletTxStatus result;
65  result.block_height = locked_chain.getBlockHeight(wtx.m_confirm.hashBlock).get_value_or(std::numeric_limits<int>::max());
66  result.blocks_to_maturity = wtx.GetBlocksToMaturity();
67  result.depth_in_main_chain = wtx.GetDepthInMainChain();
68  result.time_received = wtx.nTimeReceived;
69  result.lock_time = wtx.tx->nLockTime;
70  result.is_final = locked_chain.checkFinalTx(*wtx.tx);
71  result.is_trusted = wtx.IsTrusted(locked_chain);
72  result.is_abandoned = wtx.isAbandoned();
73  result.is_coinbase = wtx.IsCoinBase();
74  result.is_in_main_chain = wtx.IsInMainChain();
75  return result;
76 }
77 
79 WalletTxOut MakeWalletTxOut(CWallet& wallet,
80  const CWalletTx& wtx,
81  int n,
82  int depth) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
83 {
84  WalletTxOut result;
85  result.txout = wtx.tx->vout[n];
86  result.time = wtx.GetTxTime();
87  result.depth_in_main_chain = depth;
88  result.is_spent = wallet.IsSpent(wtx.GetHash(), n);
89  return result;
90 }
91 
92 class WalletImpl : public Wallet
93 {
94 public:
95  explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet) {}
96 
97  bool encryptWallet(const SecureString& wallet_passphrase) override
98  {
99  return m_wallet->EncryptWallet(wallet_passphrase);
100  }
101  bool isCrypted() override { return m_wallet->IsCrypted(); }
102  bool lock() override { return m_wallet->Lock(); }
103  bool unlock(const SecureString& wallet_passphrase) override { return m_wallet->Unlock(wallet_passphrase); }
104  bool isLocked() override { return m_wallet->IsLocked(); }
105  bool changeWalletPassphrase(const SecureString& old_wallet_passphrase,
106  const SecureString& new_wallet_passphrase) override
107  {
108  return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
109  }
110  void abortRescan() override { m_wallet->AbortRescan(); }
111  bool backupWallet(const std::string& filename) override { return m_wallet->BackupWallet(filename); }
112  std::string getWalletName() override { return m_wallet->GetName(); }
113  bool getNewDestination(const OutputType type, const std::string label, CTxDestination& dest) override
114  {
115  LOCK(m_wallet->cs_wallet);
116  std::string error;
117  return m_wallet->GetNewDestination(type, label, dest, error);
118  }
119  bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
120  {
121  std::unique_ptr<SigningProvider> provider = m_wallet->GetSolvingProvider(script);
122  if (provider) {
123  return provider->GetPubKey(address, pub_key);
124  }
125  return false;
126  }
127  SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) override
128  {
129  return m_wallet->SignMessage(message, pkhash, str_sig);
130  }
131  bool isSpendable(const CTxDestination& dest) override { return m_wallet->IsMine(dest) & ISMINE_SPENDABLE; }
132  bool haveWatchOnly() override
133  {
134  auto spk_man = m_wallet->GetLegacyScriptPubKeyMan();
135  if (spk_man) {
136  return spk_man->HaveWatchOnly();
137  }
138  return false;
139  };
140  bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::string& purpose) override
141  {
142  return m_wallet->SetAddressBook(dest, name, purpose);
143  }
144  bool delAddressBook(const CTxDestination& dest) override
145  {
146  return m_wallet->DelAddressBook(dest);
147  }
148  bool getAddress(const CTxDestination& dest,
149  std::string* name,
150  isminetype* is_mine,
151  std::string* purpose) override
152  {
153  LOCK(m_wallet->cs_wallet);
154  auto it = m_wallet->m_address_book.find(dest);
155  if (it == m_wallet->m_address_book.end() || it->second.IsChange()) {
156  return false;
157  }
158  if (name) {
159  *name = it->second.GetLabel();
160  }
161  if (is_mine) {
162  *is_mine = m_wallet->IsMine(dest);
163  }
164  if (purpose) {
165  *purpose = it->second.purpose;
166  }
167  return true;
168  }
169  std::vector<WalletAddress> getAddresses() override
170  {
171  LOCK(m_wallet->cs_wallet);
172  std::vector<WalletAddress> result;
173  for (const auto& item : m_wallet->m_address_book) {
174  if (item.second.IsChange()) continue;
175  result.emplace_back(item.first, m_wallet->IsMine(item.first), item.second.GetLabel(), item.second.purpose);
176  }
177  return result;
178  }
179  bool addDestData(const CTxDestination& dest, const std::string& key, const std::string& value) override
180  {
181  LOCK(m_wallet->cs_wallet);
182  WalletBatch batch{m_wallet->GetDatabase()};
183  return m_wallet->AddDestData(batch, dest, key, value);
184  }
185  bool eraseDestData(const CTxDestination& dest, const std::string& key) override
186  {
187  LOCK(m_wallet->cs_wallet);
188  WalletBatch batch{m_wallet->GetDatabase()};
189  return m_wallet->EraseDestData(batch, dest, key);
190  }
191  std::vector<std::string> getDestValues(const std::string& prefix) override
192  {
193  LOCK(m_wallet->cs_wallet);
194  return m_wallet->GetDestValues(prefix);
195  }
196  void lockCoin(const COutPoint& output) override
197  {
198  auto locked_chain = m_wallet->chain().lock();
199  LOCK(m_wallet->cs_wallet);
200  return m_wallet->LockCoin(output);
201  }
202  void unlockCoin(const COutPoint& output) override
203  {
204  auto locked_chain = m_wallet->chain().lock();
205  LOCK(m_wallet->cs_wallet);
206  return m_wallet->UnlockCoin(output);
207  }
208  bool isLockedCoin(const COutPoint& output) override
209  {
210  auto locked_chain = m_wallet->chain().lock();
211  LOCK(m_wallet->cs_wallet);
212  return m_wallet->IsLockedCoin(output.hash, output.n);
213  }
214  void listLockedCoins(std::vector<COutPoint>& outputs) override
215  {
216  auto locked_chain = m_wallet->chain().lock();
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  std::string& fail_reason) override
226  {
227  auto locked_chain = m_wallet->chain().lock();
228  LOCK(m_wallet->cs_wallet);
229  CTransactionRef tx;
230  if (!m_wallet->CreateTransaction(*locked_chain, recipients, tx, fee, change_pos,
231  fail_reason, coin_control, sign)) {
232  return {};
233  }
234  return tx;
235  }
236  void commitTransaction(CTransactionRef tx,
237  WalletValueMap value_map,
238  WalletOrderForm order_form) override
239  {
240  auto locked_chain = m_wallet->chain().lock();
241  LOCK(m_wallet->cs_wallet);
242  m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
243  }
244  bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
245  bool abandonTransaction(const uint256& txid) override
246  {
247  auto locked_chain = m_wallet->chain().lock();
248  LOCK(m_wallet->cs_wallet);
249  return m_wallet->AbandonTransaction(txid);
250  }
251  bool transactionCanBeBumped(const uint256& txid) override
252  {
253  return feebumper::TransactionCanBeBumped(*m_wallet.get(), txid);
254  }
255  bool createBumpTransaction(const uint256& txid,
256  const CCoinControl& coin_control,
257  std::vector<std::string>& errors,
258  CAmount& old_fee,
259  CAmount& new_fee,
260  CMutableTransaction& mtx) override
261  {
262  return feebumper::CreateRateBumpTransaction(*m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx) == feebumper::Result::OK;
263  }
264  bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(*m_wallet.get(), mtx); }
265  bool commitBumpTransaction(const uint256& txid,
266  CMutableTransaction&& mtx,
267  std::vector<std::string>& errors,
268  uint256& bumped_txid) override
269  {
270  return feebumper::CommitTransaction(*m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) ==
272  }
273  CTransactionRef getTx(const uint256& txid) override
274  {
275  auto locked_chain = m_wallet->chain().lock();
276  LOCK(m_wallet->cs_wallet);
277  auto mi = m_wallet->mapWallet.find(txid);
278  if (mi != m_wallet->mapWallet.end()) {
279  return mi->second.tx;
280  }
281  return {};
282  }
283  WalletTx getWalletTx(const uint256& txid) override
284  {
285  auto locked_chain = m_wallet->chain().lock();
286  LOCK(m_wallet->cs_wallet);
287  auto mi = m_wallet->mapWallet.find(txid);
288  if (mi != m_wallet->mapWallet.end()) {
289  return MakeWalletTx(*m_wallet, mi->second);
290  }
291  return {};
292  }
293  std::vector<WalletTx> getWalletTxs() override
294  {
295  auto locked_chain = m_wallet->chain().lock();
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  auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
310  if (!locked_chain) {
311  return false;
312  }
313  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
314  if (!locked_wallet) {
315  return false;
316  }
317  auto mi = m_wallet->mapWallet.find(txid);
318  if (mi == m_wallet->mapWallet.end()) {
319  return false;
320  }
321  if (Optional<int> height = locked_chain->getHeight()) {
322  num_blocks = *height;
323  block_time = locked_chain->getBlockTime(*height);
324  } else {
325  num_blocks = -1;
326  block_time = -1;
327  }
328  tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
329  return true;
330  }
331  WalletTx getWalletTxDetails(const uint256& txid,
332  WalletTxStatus& tx_status,
333  WalletOrderForm& order_form,
334  bool& in_mempool,
335  int& num_blocks) override
336  {
337  auto locked_chain = m_wallet->chain().lock();
338  LOCK(m_wallet->cs_wallet);
339  auto mi = m_wallet->mapWallet.find(txid);
340  if (mi != m_wallet->mapWallet.end()) {
341  num_blocks = locked_chain->getHeight().get_value_or(-1);
342  in_mempool = mi->second.InMempool();
343  order_form = mi->second.vOrderForm;
344  tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
345  return MakeWalletTx(*m_wallet, mi->second);
346  }
347  return {};
348  }
349  TransactionError fillPSBT(int sighash_type,
350  bool sign,
351  bool bip32derivs,
353  bool& complete) override
354  {
355  return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs);
356  }
357  WalletBalances getBalances() override
358  {
359  const auto bal = m_wallet->GetBalance();
360  WalletBalances result;
361  result.balance = bal.m_mine_trusted;
362  result.unconfirmed_balance = bal.m_mine_untrusted_pending;
363  result.immature_balance = bal.m_mine_immature;
364  result.have_watch_only = haveWatchOnly();
365  if (result.have_watch_only) {
366  result.watch_only_balance = bal.m_watchonly_trusted;
367  result.unconfirmed_watch_only_balance = bal.m_watchonly_untrusted_pending;
368  result.immature_watch_only_balance = bal.m_watchonly_immature;
369  }
370  return result;
371  }
372  bool tryGetBalances(WalletBalances& balances, int& num_blocks, bool force, int cached_num_blocks) override
373  {
374  auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
375  if (!locked_chain) return false;
376  num_blocks = locked_chain->getHeight().get_value_or(-1);
377  if (!force && num_blocks == cached_num_blocks) return false;
378  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
379  if (!locked_wallet) {
380  return false;
381  }
382  balances = getBalances();
383  return true;
384  }
385  CAmount getBalance() override { return m_wallet->GetBalance().m_mine_trusted; }
386  CAmount getAvailableBalance(const CCoinControl& coin_control) override
387  {
388  return m_wallet->GetAvailableBalance(&coin_control);
389  }
390  isminetype txinIsMine(const CTxIn& txin) override
391  {
392  auto locked_chain = m_wallet->chain().lock();
393  LOCK(m_wallet->cs_wallet);
394  return m_wallet->IsMine(txin);
395  }
396  isminetype txoutIsMine(const CTxOut& txout) override
397  {
398  auto locked_chain = m_wallet->chain().lock();
399  LOCK(m_wallet->cs_wallet);
400  return m_wallet->IsMine(txout);
401  }
402  CAmount getDebit(const CTxIn& txin, isminefilter filter) override
403  {
404  auto locked_chain = m_wallet->chain().lock();
405  LOCK(m_wallet->cs_wallet);
406  return m_wallet->GetDebit(txin, filter);
407  }
408  CAmount getCredit(const CTxOut& txout, isminefilter filter) override
409  {
410  auto locked_chain = m_wallet->chain().lock();
411  LOCK(m_wallet->cs_wallet);
412  return m_wallet->GetCredit(txout, filter);
413  }
414  CoinsList listCoins() override
415  {
416  auto locked_chain = m_wallet->chain().lock();
417  LOCK(m_wallet->cs_wallet);
418  CoinsList result;
419  for (const auto& entry : m_wallet->ListCoins(*locked_chain)) {
420  auto& group = result[entry.first];
421  for (const auto& coin : entry.second) {
422  group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i),
423  MakeWalletTxOut(*m_wallet, *coin.tx, coin.i, coin.nDepth));
424  }
425  }
426  return result;
427  }
428  std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) override
429  {
430  auto locked_chain = m_wallet->chain().lock();
431  LOCK(m_wallet->cs_wallet);
432  std::vector<WalletTxOut> result;
433  result.reserve(outputs.size());
434  for (const auto& output : outputs) {
435  result.emplace_back();
436  auto it = m_wallet->mapWallet.find(output.hash);
437  if (it != m_wallet->mapWallet.end()) {
438  int depth = it->second.GetDepthInMainChain();
439  if (depth >= 0) {
440  result.back() = MakeWalletTxOut(*m_wallet, it->second, output.n, depth);
441  }
442  }
443  }
444  return result;
445  }
446  CAmount getRequiredFee(unsigned int tx_bytes) override { return GetRequiredFee(*m_wallet, tx_bytes); }
447  CAmount getMinimumFee(unsigned int tx_bytes,
448  const CCoinControl& coin_control,
449  int* returned_target,
450  FeeReason* reason) override
451  {
452  FeeCalculation fee_calc;
453  CAmount result;
454  result = GetMinimumFee(*m_wallet, tx_bytes, coin_control, &fee_calc);
455  if (returned_target) *returned_target = fee_calc.returnedTarget;
456  if (reason) *reason = fee_calc.reason;
457  return result;
458  }
459  unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
460  bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
461  bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
462  bool privateKeysDisabled() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); }
463  OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
464  OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; }
465  CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }
466  void remove() override
467  {
469  }
470  std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
471  {
472  return MakeHandler(m_wallet->NotifyUnload.connect(fn));
473  }
474  std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
475  {
476  return MakeHandler(m_wallet->ShowProgress.connect(fn));
477  }
478  std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) override
479  {
480  return MakeHandler(m_wallet->NotifyStatusChanged.connect([fn](CWallet*) { fn(); }));
481  }
482  std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) override
483  {
484  return MakeHandler(m_wallet->NotifyAddressBookChanged.connect(
485  [fn](CWallet*, const CTxDestination& address, const std::string& label, bool is_mine,
486  const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); }));
487  }
488  std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override
489  {
490  return MakeHandler(m_wallet->NotifyTransactionChanged.connect(
491  [fn](CWallet*, const uint256& txid, ChangeType status) { fn(txid, status); }));
492  }
493  std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override
494  {
495  return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
496  }
497  std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override
498  {
499  return MakeHandler(m_wallet->NotifyCanGetAddressesChanged.connect(fn));
500  }
501 
502  std::shared_ptr<CWallet> m_wallet;
503 };
504 
505 class WalletClientImpl : public ChainClient
506 {
507 public:
508  WalletClientImpl(Chain& chain, std::vector<std::string> wallet_filenames)
509  : m_chain(chain), m_wallet_filenames(std::move(wallet_filenames))
510  {
511  }
512  void registerRpcs() override
513  {
514  g_rpc_chain = &m_chain;
516  }
517  bool verify() override { return VerifyWallets(m_chain, m_wallet_filenames); }
518  bool load() override { return LoadWallets(m_chain, m_wallet_filenames); }
519  void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
520  void flush() override { return FlushWallets(); }
521  void stop() override { return StopWallets(); }
522  ~WalletClientImpl() override { UnloadWallets(); }
523 
524  Chain& m_chain;
525  std::vector<std::string> m_wallet_filenames;
526  std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
527 };
528 
529 } // namespace
530 
531 std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? MakeUnique<WalletImpl>(wallet) : nullptr; }
532 
533 std::unique_ptr<ChainClient> MakeWalletClient(Chain& chain, std::vector<std::string> wallet_filenames)
534 {
535  return MakeUnique<WalletClientImpl>(chain, std::move(wallet_filenames));
536 }
537 
538 } // namespace interfaces
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
std::shared_ptr< CWallet > m_wallet
Definition: wallet.cpp:502
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:156
int returnedTarget
Definition: fees.h:80
#define TRY_LOCK(cs, name)
Definition: sync.h:222
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< std::string > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:248
virtual int64_t getBlockTime(int height)=0
Get block time. Height must be valid or this function will abort.
SigningResult
Definition: message.h:42
const char * prefix
Definition: rest.cpp:650
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
Definition: wallet.cpp:1820
FeeReason reason
Definition: fees.h:78
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
Interface for querying locked chain state, used by legacy code that assumes state won&#39;t change betwee...
Definition: chain.h:64
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:533
bool IsInMainChain() const
Definition: wallet.h:529
virtual Optional< int > getBlockHeight(const uint256 &hash)=0
Get block height above genesis block.
A version of CTransaction with the PSBT format.
Definition: psbt.h:388
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:552
std::map< std::string, std::string > WalletValueMap
Definition: wallet.h:46
bool LoadWallets(interfaces::Chain &chain, const std::vector< std::string > &wallet_files)
Load wallet databases.
Definition: load.cpp:67
isminetype IsMine(const CTxDestination &dest) const
Definition: wallet.cpp:1203
void RegisterWalletRPCCommands(interfaces::Chain &chain, std::vector< std::unique_ptr< interfaces::Handler >> &handlers)
Definition: rpcwallet.cpp:4259
OutputType
Definition: outputtype.h:17
Coin Control Features.
Definition: coincontrol.h:22
void StartWallets(CScheduler &scheduler)
Complete startup of wallets.
Definition: load.cpp:88
bool IsTrusted(interfaces::Chain::Lock &locked_chain) const
Definition: wallet.cpp:1921
Access to the wallet database.
Definition: walletdb.h:175
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: wallet.h:301
void StopWallets()
Stop all wallets. Wallets will be flushed first.
Definition: load.cpp:106
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
Confirmation m_confirm
Definition: wallet.h:391
ChangeType
General change type (added, updated, removed).
Definition: ui_interface.h:21
An input of a transaction.
Definition: transaction.h:63
#define LOCK(cs)
Definition: sync.h:218
const char * name
Definition: rest.cpp:40
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
Definition: feebumper.cpp:141
virtual Optional< int > getHeight()=0
Get current chain height, not including genesis block (returns 0 if chain only contains genesis block...
Chain & m_chain
Definition: wallet.cpp:524
An encapsulated public key.
Definition: pubkey.h:30
int GetBlocksToMaturity() const
Definition: wallet.cpp:4174
uint32_t n
Definition: transaction.h:22
uint8_t isminefilter
Definition: wallet.h:30
isminetype
IsMine() return codes.
Definition: ismine.h:18
An output of a transaction.
Definition: transaction.h:133
FeeReason
Definition: fees.h:36
const uint256 & GetHash() const
Definition: wallet.h:551
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:525
std::unique_ptr< Wallet > MakeWallet(const std::shared_ptr< CWallet > &wallet)
Return implementation of Wallet interface.
Definition: dummywallet.cpp:93
void FlushWallets()
Flush all wallets in preparation for shutdown.
Definition: load.cpp:99
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
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
CAmount GetCredit(const isminefilter &filter) const
Definition: wallet.cpp:1835
int64_t GetTxTime() const
Definition: wallet.cpp:1398
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:54
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
Result CreateRateBumpTransaction(CWallet &wallet, const uint256 &txid, const CCoinControl &coin_control, std::vector< std::string > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction based on feerate estimates.
Definition: feebumper.cpp:153
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:4165
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:63
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:45
RecursiveMutex cs_wallet
Definition: wallet.h:729
A mutable version of CTransaction.
Definition: transaction.h:366
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:471
unsigned int nTimeReceived
time received by this node
Definition: wallet.h:304
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:14
bool isAbandoned() const
Definition: wallet.h:537
void UnloadWallets()
Close all wallets.
Definition: load.cpp:113
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:143
virtual bool checkFinalTx(const CTransaction &tx)=0
Check if transaction will be final given chain height current time.
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:361
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
Updated transaction status.
Definition: wallet.h:353
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
Definition: wallet.cpp:526
CTransactionRef tx
Definition: wallet.h:361
interfaces::Chain * g_rpc_chain
Pointer to chain interface that needs to be declared as a global to be accessible loadwallet and crea...
Definition: rpcwallet.cpp:4328
CAmount GetChange() const
Definition: wallet.cpp:1907
UniValue stop(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:154
uint256 hash
Definition: transaction.h:21