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/psbtwallet.h>
23 #include <wallet/rpcwallet.h>
24 #include <wallet/wallet.h>
25 
26 #include <memory>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 namespace interfaces {
32 namespace {
33 
35 WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
36 {
37  WalletTx result;
38  result.tx = wtx.tx;
39  result.txin_is_mine.reserve(wtx.tx->vin.size());
40  for (const auto& txin : wtx.tx->vin) {
41  result.txin_is_mine.emplace_back(wallet.IsMine(txin));
42  }
43  result.txout_is_mine.reserve(wtx.tx->vout.size());
44  result.txout_address.reserve(wtx.tx->vout.size());
45  result.txout_address_is_mine.reserve(wtx.tx->vout.size());
46  for (const auto& txout : wtx.tx->vout) {
47  result.txout_is_mine.emplace_back(wallet.IsMine(txout));
48  result.txout_address.emplace_back();
49  result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
50  wallet.IsMine(result.txout_address.back()) :
51  ISMINE_NO);
52  }
53  result.credit = wtx.GetCredit(ISMINE_ALL);
54  result.debit = wtx.GetDebit(ISMINE_ALL);
55  result.change = wtx.GetChange();
56  result.time = wtx.GetTxTime();
57  result.value_map = wtx.mapValue;
58  result.is_coinbase = wtx.IsCoinBase();
59  return result;
60 }
61 
63 WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
64 {
65  WalletTxStatus result;
66  result.block_height = locked_chain.getBlockHeight(wtx.m_confirm.hashBlock).get_value_or(std::numeric_limits<int>::max());
67  result.blocks_to_maturity = wtx.GetBlocksToMaturity();
68  result.depth_in_main_chain = wtx.GetDepthInMainChain();
69  result.time_received = wtx.nTimeReceived;
70  result.lock_time = wtx.tx->nLockTime;
71  result.is_final = locked_chain.checkFinalTx(*wtx.tx);
72  result.is_trusted = wtx.IsTrusted(locked_chain);
73  result.is_abandoned = wtx.isAbandoned();
74  result.is_coinbase = wtx.IsCoinBase();
75  result.is_in_main_chain = wtx.IsInMainChain();
76  return result;
77 }
78 
80 WalletTxOut MakeWalletTxOut(CWallet& wallet,
81  const CWalletTx& wtx,
82  int n,
83  int depth) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
84 {
85  WalletTxOut result;
86  result.txout = wtx.tx->vout[n];
87  result.time = wtx.GetTxTime();
88  result.depth_in_main_chain = depth;
89  result.is_spent = wallet.IsSpent(wtx.GetHash(), n);
90  return result;
91 }
92 
93 class WalletImpl : public Wallet
94 {
95 public:
96  explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet) {}
97 
98  bool encryptWallet(const SecureString& wallet_passphrase) override
99  {
100  return m_wallet->EncryptWallet(wallet_passphrase);
101  }
102  bool isCrypted() override { return m_wallet->IsCrypted(); }
103  bool lock() override { return m_wallet->Lock(); }
104  bool unlock(const SecureString& wallet_passphrase) override { return m_wallet->Unlock(wallet_passphrase); }
105  bool isLocked() override { return m_wallet->IsLocked(); }
106  bool changeWalletPassphrase(const SecureString& old_wallet_passphrase,
107  const SecureString& new_wallet_passphrase) override
108  {
109  return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
110  }
111  void abortRescan() override { m_wallet->AbortRescan(); }
112  bool backupWallet(const std::string& filename) override { return m_wallet->BackupWallet(filename); }
113  std::string getWalletName() override { return m_wallet->GetName(); }
114  bool getNewDestination(const OutputType type, const std::string label, CTxDestination& dest) override
115  {
116  LOCK(m_wallet->cs_wallet);
117  std::string error;
118  return m_wallet->GetNewDestination(type, label, dest, error);
119  }
120  bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
121  {
122  std::unique_ptr<SigningProvider> provider = m_wallet->GetSigningProvider(script);
123  if (provider) {
124  return provider->GetPubKey(address, pub_key);
125  }
126  return false;
127  }
128  bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) override
129  {
130  std::unique_ptr<SigningProvider> provider = m_wallet->GetSigningProvider(script);
131  if (provider) {
132  return provider->GetKey(address, key);
133  }
134  return false;
135  }
136  bool isSpendable(const CTxDestination& dest) override { return m_wallet->IsMine(dest) & ISMINE_SPENDABLE; }
137  bool haveWatchOnly() override
138  {
139  auto spk_man = m_wallet->GetLegacyScriptPubKeyMan();
140  if (spk_man) {
141  return spk_man->HaveWatchOnly();
142  }
143  return false;
144  };
145  bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::string& purpose) override
146  {
147  return m_wallet->SetAddressBook(dest, name, purpose);
148  }
149  bool delAddressBook(const CTxDestination& dest) override
150  {
151  return m_wallet->DelAddressBook(dest);
152  }
153  bool getAddress(const CTxDestination& dest,
154  std::string* name,
155  isminetype* is_mine,
156  std::string* purpose) override
157  {
158  LOCK(m_wallet->cs_wallet);
159  auto it = m_wallet->mapAddressBook.find(dest);
160  if (it == m_wallet->mapAddressBook.end()) {
161  return false;
162  }
163  if (name) {
164  *name = it->second.name;
165  }
166  if (is_mine) {
167  *is_mine = m_wallet->IsMine(dest);
168  }
169  if (purpose) {
170  *purpose = it->second.purpose;
171  }
172  return true;
173  }
174  std::vector<WalletAddress> getAddresses() override
175  {
176  LOCK(m_wallet->cs_wallet);
177  std::vector<WalletAddress> result;
178  for (const auto& item : m_wallet->mapAddressBook) {
179  result.emplace_back(item.first, m_wallet->IsMine(item.first), item.second.name, 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  auto locked_chain = m_wallet->chain().lock();
203  LOCK(m_wallet->cs_wallet);
204  return m_wallet->LockCoin(output);
205  }
206  void unlockCoin(const COutPoint& output) override
207  {
208  auto locked_chain = m_wallet->chain().lock();
209  LOCK(m_wallet->cs_wallet);
210  return m_wallet->UnlockCoin(output);
211  }
212  bool isLockedCoin(const COutPoint& output) override
213  {
214  auto locked_chain = m_wallet->chain().lock();
215  LOCK(m_wallet->cs_wallet);
216  return m_wallet->IsLockedCoin(output.hash, output.n);
217  }
218  void listLockedCoins(std::vector<COutPoint>& outputs) override
219  {
220  auto locked_chain = m_wallet->chain().lock();
221  LOCK(m_wallet->cs_wallet);
222  return m_wallet->ListLockedCoins(outputs);
223  }
224  CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
225  const CCoinControl& coin_control,
226  bool sign,
227  int& change_pos,
228  CAmount& fee,
229  std::string& fail_reason) override
230  {
231  auto locked_chain = m_wallet->chain().lock();
232  LOCK(m_wallet->cs_wallet);
233  CTransactionRef tx;
234  if (!m_wallet->CreateTransaction(*locked_chain, recipients, tx, fee, change_pos,
235  fail_reason, coin_control, sign)) {
236  return {};
237  }
238  return tx;
239  }
240  void commitTransaction(CTransactionRef tx,
241  WalletValueMap value_map,
242  WalletOrderForm order_form) override
243  {
244  auto locked_chain = m_wallet->chain().lock();
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  auto locked_chain = m_wallet->chain().lock();
252  LOCK(m_wallet->cs_wallet);
253  return m_wallet->AbandonTransaction(txid);
254  }
255  bool transactionCanBeBumped(const uint256& txid) override
256  {
257  return feebumper::TransactionCanBeBumped(*m_wallet.get(), txid);
258  }
259  bool createBumpTransaction(const uint256& txid,
260  const CCoinControl& coin_control,
261  CAmount total_fee,
262  std::vector<std::string>& errors,
263  CAmount& old_fee,
264  CAmount& new_fee,
265  CMutableTransaction& mtx) override
266  {
267  if (total_fee > 0) {
268  return feebumper::CreateTotalBumpTransaction(m_wallet.get(), txid, coin_control, total_fee, errors, old_fee, new_fee, mtx) ==
270  } else {
271  return feebumper::CreateRateBumpTransaction(*m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx) ==
273  }
274  }
275  bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(*m_wallet.get(), mtx); }
276  bool commitBumpTransaction(const uint256& txid,
277  CMutableTransaction&& mtx,
278  std::vector<std::string>& errors,
279  uint256& bumped_txid) override
280  {
281  return feebumper::CommitTransaction(*m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) ==
283  }
284  CTransactionRef getTx(const uint256& txid) override
285  {
286  auto locked_chain = m_wallet->chain().lock();
287  LOCK(m_wallet->cs_wallet);
288  auto mi = m_wallet->mapWallet.find(txid);
289  if (mi != m_wallet->mapWallet.end()) {
290  return mi->second.tx;
291  }
292  return {};
293  }
294  WalletTx getWalletTx(const uint256& txid) override
295  {
296  auto locked_chain = m_wallet->chain().lock();
297  LOCK(m_wallet->cs_wallet);
298  auto mi = m_wallet->mapWallet.find(txid);
299  if (mi != m_wallet->mapWallet.end()) {
300  return MakeWalletTx(*m_wallet, mi->second);
301  }
302  return {};
303  }
304  std::vector<WalletTx> getWalletTxs() override
305  {
306  auto locked_chain = m_wallet->chain().lock();
307  LOCK(m_wallet->cs_wallet);
308  std::vector<WalletTx> result;
309  result.reserve(m_wallet->mapWallet.size());
310  for (const auto& entry : m_wallet->mapWallet) {
311  result.emplace_back(MakeWalletTx(*m_wallet, entry.second));
312  }
313  return result;
314  }
315  bool tryGetTxStatus(const uint256& txid,
316  interfaces::WalletTxStatus& tx_status,
317  int& num_blocks,
318  int64_t& block_time) override
319  {
320  auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
321  if (!locked_chain) {
322  return false;
323  }
324  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
325  if (!locked_wallet) {
326  return false;
327  }
328  auto mi = m_wallet->mapWallet.find(txid);
329  if (mi == m_wallet->mapWallet.end()) {
330  return false;
331  }
332  if (Optional<int> height = locked_chain->getHeight()) {
333  num_blocks = *height;
334  block_time = locked_chain->getBlockTime(*height);
335  } else {
336  num_blocks = -1;
337  block_time = -1;
338  }
339  tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
340  return true;
341  }
342  WalletTx getWalletTxDetails(const uint256& txid,
343  WalletTxStatus& tx_status,
344  WalletOrderForm& order_form,
345  bool& in_mempool,
346  int& num_blocks) override
347  {
348  auto locked_chain = m_wallet->chain().lock();
349  LOCK(m_wallet->cs_wallet);
350  auto mi = m_wallet->mapWallet.find(txid);
351  if (mi != m_wallet->mapWallet.end()) {
352  num_blocks = locked_chain->getHeight().get_value_or(-1);
353  in_mempool = mi->second.InMempool();
354  order_form = mi->second.vOrderForm;
355  tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
356  return MakeWalletTx(*m_wallet, mi->second);
357  }
358  return {};
359  }
361  bool& complete,
362  int sighash_type = 1 /* SIGHASH_ALL */,
363  bool sign = true,
364  bool bip32derivs = false) override
365  {
366  return FillPSBT(m_wallet.get(), psbtx, complete, sighash_type, sign, bip32derivs);
367  }
368  WalletBalances getBalances() override
369  {
370  const auto bal = m_wallet->GetBalance();
371  WalletBalances result;
372  result.balance = bal.m_mine_trusted;
373  result.unconfirmed_balance = bal.m_mine_untrusted_pending;
374  result.immature_balance = bal.m_mine_immature;
375  result.have_watch_only = haveWatchOnly();
376  if (result.have_watch_only) {
377  result.watch_only_balance = bal.m_watchonly_trusted;
378  result.unconfirmed_watch_only_balance = bal.m_watchonly_untrusted_pending;
379  result.immature_watch_only_balance = bal.m_watchonly_immature;
380  }
381  return result;
382  }
383  bool tryGetBalances(WalletBalances& balances, int& num_blocks) override
384  {
385  auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
386  if (!locked_chain) return false;
387  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
388  if (!locked_wallet) {
389  return false;
390  }
391  balances = getBalances();
392  num_blocks = locked_chain->getHeight().get_value_or(-1);
393  return true;
394  }
395  CAmount getBalance() override { return m_wallet->GetBalance().m_mine_trusted; }
396  CAmount getAvailableBalance(const CCoinControl& coin_control) override
397  {
398  return m_wallet->GetAvailableBalance(&coin_control);
399  }
400  isminetype txinIsMine(const CTxIn& txin) override
401  {
402  auto locked_chain = m_wallet->chain().lock();
403  LOCK(m_wallet->cs_wallet);
404  return m_wallet->IsMine(txin);
405  }
406  isminetype txoutIsMine(const CTxOut& txout) override
407  {
408  auto locked_chain = m_wallet->chain().lock();
409  LOCK(m_wallet->cs_wallet);
410  return m_wallet->IsMine(txout);
411  }
412  CAmount getDebit(const CTxIn& txin, isminefilter filter) override
413  {
414  auto locked_chain = m_wallet->chain().lock();
415  LOCK(m_wallet->cs_wallet);
416  return m_wallet->GetDebit(txin, filter);
417  }
418  CAmount getCredit(const CTxOut& txout, isminefilter filter) override
419  {
420  auto locked_chain = m_wallet->chain().lock();
421  LOCK(m_wallet->cs_wallet);
422  return m_wallet->GetCredit(txout, filter);
423  }
424  CoinsList listCoins() override
425  {
426  auto locked_chain = m_wallet->chain().lock();
427  LOCK(m_wallet->cs_wallet);
428  CoinsList result;
429  for (const auto& entry : m_wallet->ListCoins(*locked_chain)) {
430  auto& group = result[entry.first];
431  for (const auto& coin : entry.second) {
432  group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i),
433  MakeWalletTxOut(*m_wallet, *coin.tx, coin.i, coin.nDepth));
434  }
435  }
436  return result;
437  }
438  std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) override
439  {
440  auto locked_chain = m_wallet->chain().lock();
441  LOCK(m_wallet->cs_wallet);
442  std::vector<WalletTxOut> result;
443  result.reserve(outputs.size());
444  for (const auto& output : outputs) {
445  result.emplace_back();
446  auto it = m_wallet->mapWallet.find(output.hash);
447  if (it != m_wallet->mapWallet.end()) {
448  int depth = it->second.GetDepthInMainChain();
449  if (depth >= 0) {
450  result.back() = MakeWalletTxOut(*m_wallet, it->second, output.n, depth);
451  }
452  }
453  }
454  return result;
455  }
456  CAmount getRequiredFee(unsigned int tx_bytes) override { return GetRequiredFee(*m_wallet, tx_bytes); }
457  CAmount getMinimumFee(unsigned int tx_bytes,
458  const CCoinControl& coin_control,
459  int* returned_target,
460  FeeReason* reason) override
461  {
462  FeeCalculation fee_calc;
463  CAmount result;
464  result = GetMinimumFee(*m_wallet, tx_bytes, coin_control, &fee_calc);
465  if (returned_target) *returned_target = fee_calc.returnedTarget;
466  if (reason) *reason = fee_calc.reason;
467  return result;
468  }
469  unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
470  bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
471  bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
472  bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); }
473  OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
474  OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; }
475  CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }
476  void remove() override
477  {
479  }
480  std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
481  {
482  return MakeHandler(m_wallet->NotifyUnload.connect(fn));
483  }
484  std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
485  {
486  return MakeHandler(m_wallet->ShowProgress.connect(fn));
487  }
488  std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) override
489  {
490  return MakeHandler(m_wallet->NotifyStatusChanged.connect([fn](CWallet*) { fn(); }));
491  }
492  std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) override
493  {
494  return MakeHandler(m_wallet->NotifyAddressBookChanged.connect(
495  [fn](CWallet*, const CTxDestination& address, const std::string& label, bool is_mine,
496  const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); }));
497  }
498  std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override
499  {
500  return MakeHandler(m_wallet->NotifyTransactionChanged.connect(
501  [fn](CWallet*, const uint256& txid, ChangeType status) { fn(txid, status); }));
502  }
503  std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override
504  {
505  return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
506  }
507  std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override
508  {
509  return MakeHandler(m_wallet->NotifyCanGetAddressesChanged.connect(fn));
510  }
511 
512  std::shared_ptr<CWallet> m_wallet;
513 };
514 
515 class WalletClientImpl : public ChainClient
516 {
517 public:
518  WalletClientImpl(Chain& chain, std::vector<std::string> wallet_filenames)
519  : m_chain(chain), m_wallet_filenames(std::move(wallet_filenames))
520  {
521  }
522  void registerRpcs() override
523  {
524  g_rpc_chain = &m_chain;
526  }
527  bool verify() override { return VerifyWallets(m_chain, m_wallet_filenames); }
528  bool load() override { return LoadWallets(m_chain, m_wallet_filenames); }
529  void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
530  void flush() override { return FlushWallets(); }
531  void stop() override { return StopWallets(); }
532  ~WalletClientImpl() override { UnloadWallets(); }
533 
534  Chain& m_chain;
535  std::vector<std::string> m_wallet_filenames;
536  std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
537 };
538 
539 } // namespace
540 
541 std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? MakeUnique<WalletImpl>(wallet) : nullptr; }
542 
543 std::unique_ptr<ChainClient> MakeWalletClient(Chain& chain, std::vector<std::string> wallet_filenames)
544 {
545  return MakeUnique<WalletClientImpl>(chain, std::move(wallet_filenames));
546 }
547 
548 } // namespace interfaces
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
std::shared_ptr< CWallet > m_wallet
Definition: wallet.cpp:512
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Definition: feebumper.cpp:369
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:183
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< std::string > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:375
virtual int64_t getBlockTime(int height)=0
Get block time. Height must be valid or this function will abort.
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:1819
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:543
bool IsInMainChain() const
Definition: wallet.h:517
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:540
std::map< std::string, std::string > WalletValueMap
Definition: wallet.h:45
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:4314
OutputType
Definition: outputtype.h:17
Coin Control Features.
Definition: coincontrol.h:22
void StartWallets(CScheduler &scheduler)
Complete startup of wallets.
Definition: load.cpp:84
bool IsTrusted(interfaces::Chain::Lock &locked_chain) const
Definition: wallet.cpp:1920
Access to the wallet database.
Definition: walletdb.h:175
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: wallet.h:289
TransactionError FillPSBT(const CWallet *pwallet, PartiallySignedTransaction &psbtx, bool &complete, int sighash_type, bool sign, bool bip32derivs)
Fills out a PSBT with information from the wallet.
Definition: psbtwallet.cpp:7
void StopWallets()
Stop all wallets. Wallets will be flushed first.
Definition: load.cpp:102
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
Result CreateTotalBumpTransaction(const CWallet *wallet, const uint256 &txid, const CCoinControl &coin_control, CAmount total_fee, std::vector< std::string > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction based on total amount.
Definition: feebumper.cpp:154
Confirmation m_confirm
Definition: wallet.h:379
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:179
const char * name
Definition: rest.cpp:40
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
Definition: feebumper.cpp:142
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:534
An encapsulated public key.
Definition: pubkey.h:30
int GetBlocksToMaturity() const
Definition: wallet.cpp:4037
uint32_t n
Definition: transaction.h:22
uint8_t isminefilter
Definition: wallet.h:29
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:539
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:535
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:95
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:253
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:1834
int64_t GetTxTime() const
Definition: wallet.cpp:1397
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:280
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:4028
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:64
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:606
TransactionError
Definition: error.h:22
std::vector< std::pair< std::string, std::string > > WalletOrderForm
Definition: wallet.h:44
RecursiveMutex cs_wallet
Definition: wallet.h:717
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:468
unsigned int nTimeReceived
time received by this node
Definition: wallet.h:292
An encapsulated private key.
Definition: key.h:27
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:14
bool isAbandoned() const
Definition: wallet.h:525
void UnloadWallets()
Close all wallets.
Definition: load.cpp:109
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:362
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
Updated transaction status.
Definition: wallet.h:350
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
Definition: wallet.cpp:536
CTransactionRef tx
Definition: wallet.h:349
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:4320
CAmount GetChange() const
Definition: wallet.cpp:1906
UniValue stop(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:154
uint256 hash
Definition: transaction.h:21