Bitcoin Core  0.18.99
P2P Digital Currency
wallet.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018 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 <consensus/validation.h>
9 #include <interfaces/chain.h>
10 #include <interfaces/handler.h>
11 #include <policy/feerate.h>
12 #include <policy/fees.h>
13 #include <primitives/transaction.h>
14 #include <script/standard.h>
16 #include <sync.h>
17 #include <ui_interface.h>
18 #include <uint256.h>
19 #include <util/system.h>
20 #include <wallet/feebumper.h>
21 #include <wallet/fees.h>
22 #include <wallet/ismine.h>
23 #include <wallet/rpcwallet.h>
24 #include <wallet/load.h>
25 #include <wallet/wallet.h>
26 #include <wallet/walletutil.h>
27 
28 #include <memory>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 namespace interfaces {
34 namespace {
35 
37 WalletTx MakeWalletTx(interfaces::Chain::Lock& locked_chain, CWallet& wallet, const CWalletTx& wtx)
38 {
39  WalletTx result;
40  result.tx = wtx.tx;
41  result.txin_is_mine.reserve(wtx.tx->vin.size());
42  for (const auto& txin : wtx.tx->vin) {
43  result.txin_is_mine.emplace_back(wallet.IsMine(txin));
44  }
45  result.txout_is_mine.reserve(wtx.tx->vout.size());
46  result.txout_address.reserve(wtx.tx->vout.size());
47  result.txout_address_is_mine.reserve(wtx.tx->vout.size());
48  for (const auto& txout : wtx.tx->vout) {
49  result.txout_is_mine.emplace_back(wallet.IsMine(txout));
50  result.txout_address.emplace_back();
51  result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
52  IsMine(wallet, result.txout_address.back()) :
53  ISMINE_NO);
54  }
55  result.credit = wtx.GetCredit(locked_chain, ISMINE_ALL);
56  result.debit = wtx.GetDebit(ISMINE_ALL);
57  result.change = wtx.GetChange();
58  result.time = wtx.GetTxTime();
59  result.value_map = wtx.mapValue;
60  result.is_coinbase = wtx.IsCoinBase();
61  return result;
62 }
63 
65 WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
66 {
67  WalletTxStatus result;
68  result.block_height = locked_chain.getBlockHeight(wtx.hashBlock).get_value_or(std::numeric_limits<int>::max());
69  result.blocks_to_maturity = wtx.GetBlocksToMaturity(locked_chain);
70  result.depth_in_main_chain = wtx.GetDepthInMainChain(locked_chain);
71  result.time_received = wtx.nTimeReceived;
72  result.lock_time = wtx.tx->nLockTime;
73  result.is_final = locked_chain.checkFinalTx(*wtx.tx);
74  result.is_trusted = wtx.IsTrusted(locked_chain);
75  result.is_abandoned = wtx.isAbandoned();
76  result.is_coinbase = wtx.IsCoinBase();
77  result.is_in_main_chain = wtx.IsInMainChain(locked_chain);
78  return result;
79 }
80 
82 WalletTxOut MakeWalletTxOut(interfaces::Chain::Lock& locked_chain,
83  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(locked_chain, 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 CKeyID& address, CPubKey& pub_key) override { return m_wallet->GetPubKey(address, pub_key); }
124  bool getPrivKey(const CKeyID& address, CKey& key) override { return m_wallet->GetKey(address, key); }
125  bool isSpendable(const CTxDestination& dest) override { return IsMine(*m_wallet, dest) & ISMINE_SPENDABLE; }
126  bool haveWatchOnly() override { return m_wallet->HaveWatchOnly(); };
127  bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::string& purpose) override
128  {
129  return m_wallet->SetAddressBook(dest, name, purpose);
130  }
131  bool delAddressBook(const CTxDestination& dest) override
132  {
133  return m_wallet->DelAddressBook(dest);
134  }
135  bool getAddress(const CTxDestination& dest,
136  std::string* name,
137  isminetype* is_mine,
138  std::string* purpose) override
139  {
140  LOCK(m_wallet->cs_wallet);
141  auto it = m_wallet->mapAddressBook.find(dest);
142  if (it == m_wallet->mapAddressBook.end()) {
143  return false;
144  }
145  if (name) {
146  *name = it->second.name;
147  }
148  if (is_mine) {
149  *is_mine = IsMine(*m_wallet, dest);
150  }
151  if (purpose) {
152  *purpose = it->second.purpose;
153  }
154  return true;
155  }
156  std::vector<WalletAddress> getAddresses() override
157  {
158  LOCK(m_wallet->cs_wallet);
159  std::vector<WalletAddress> result;
160  for (const auto& item : m_wallet->mapAddressBook) {
161  result.emplace_back(item.first, IsMine(*m_wallet, item.first), item.second.name, item.second.purpose);
162  }
163  return result;
164  }
165  void learnRelatedScripts(const CPubKey& key, OutputType type) override { m_wallet->LearnRelatedScripts(key, type); }
166  bool addDestData(const CTxDestination& dest, const std::string& key, const std::string& value) override
167  {
168  LOCK(m_wallet->cs_wallet);
169  return m_wallet->AddDestData(dest, key, value);
170  }
171  bool eraseDestData(const CTxDestination& dest, const std::string& key) override
172  {
173  LOCK(m_wallet->cs_wallet);
174  return m_wallet->EraseDestData(dest, key);
175  }
176  std::vector<std::string> getDestValues(const std::string& prefix) override
177  {
178  LOCK(m_wallet->cs_wallet);
179  return m_wallet->GetDestValues(prefix);
180  }
181  void lockCoin(const COutPoint& output) override
182  {
183  auto locked_chain = m_wallet->chain().lock();
184  LOCK(m_wallet->cs_wallet);
185  return m_wallet->LockCoin(output);
186  }
187  void unlockCoin(const COutPoint& output) override
188  {
189  auto locked_chain = m_wallet->chain().lock();
190  LOCK(m_wallet->cs_wallet);
191  return m_wallet->UnlockCoin(output);
192  }
193  bool isLockedCoin(const COutPoint& output) override
194  {
195  auto locked_chain = m_wallet->chain().lock();
196  LOCK(m_wallet->cs_wallet);
197  return m_wallet->IsLockedCoin(output.hash, output.n);
198  }
199  void listLockedCoins(std::vector<COutPoint>& outputs) override
200  {
201  auto locked_chain = m_wallet->chain().lock();
202  LOCK(m_wallet->cs_wallet);
203  return m_wallet->ListLockedCoins(outputs);
204  }
205  CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
206  const CCoinControl& coin_control,
207  bool sign,
208  int& change_pos,
209  CAmount& fee,
210  std::string& fail_reason) override
211  {
212  auto locked_chain = m_wallet->chain().lock();
213  LOCK(m_wallet->cs_wallet);
214  CTransactionRef tx;
215  if (!m_wallet->CreateTransaction(*locked_chain, recipients, tx, fee, change_pos,
216  fail_reason, coin_control, sign)) {
217  return {};
218  }
219  return tx;
220  }
221  bool commitTransaction(CTransactionRef tx,
222  WalletValueMap value_map,
223  WalletOrderForm order_form,
224  std::string& reject_reason) override
225  {
226  auto locked_chain = m_wallet->chain().lock();
227  LOCK(m_wallet->cs_wallet);
228  CValidationState state;
229  if (!m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form), state)) {
230  reject_reason = state.GetRejectReason();
231  return false;
232  }
233  return true;
234  }
235  bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
236  bool abandonTransaction(const uint256& txid) override
237  {
238  auto locked_chain = m_wallet->chain().lock();
239  LOCK(m_wallet->cs_wallet);
240  return m_wallet->AbandonTransaction(*locked_chain, txid);
241  }
242  bool transactionCanBeBumped(const uint256& txid) override
243  {
244  return feebumper::TransactionCanBeBumped(m_wallet.get(), txid);
245  }
246  bool createBumpTransaction(const uint256& txid,
247  const CCoinControl& coin_control,
248  CAmount total_fee,
249  std::vector<std::string>& errors,
250  CAmount& old_fee,
251  CAmount& new_fee,
252  CMutableTransaction& mtx) override
253  {
254  if (total_fee > 0) {
255  return feebumper::CreateTotalBumpTransaction(m_wallet.get(), txid, coin_control, total_fee, errors, old_fee, new_fee, mtx) ==
257  } else {
258  return feebumper::CreateRateBumpTransaction(m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx) ==
260  }
261  }
262  bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(m_wallet.get(), mtx); }
263  bool commitBumpTransaction(const uint256& txid,
264  CMutableTransaction&& mtx,
265  std::vector<std::string>& errors,
266  uint256& bumped_txid) override
267  {
268  return feebumper::CommitTransaction(m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) ==
270  }
271  CTransactionRef getTx(const uint256& txid) override
272  {
273  auto locked_chain = m_wallet->chain().lock();
274  LOCK(m_wallet->cs_wallet);
275  auto mi = m_wallet->mapWallet.find(txid);
276  if (mi != m_wallet->mapWallet.end()) {
277  return mi->second.tx;
278  }
279  return {};
280  }
281  WalletTx getWalletTx(const uint256& txid) override
282  {
283  auto locked_chain = m_wallet->chain().lock();
284  LOCK(m_wallet->cs_wallet);
285  auto mi = m_wallet->mapWallet.find(txid);
286  if (mi != m_wallet->mapWallet.end()) {
287  return MakeWalletTx(*locked_chain, *m_wallet, mi->second);
288  }
289  return {};
290  }
291  std::vector<WalletTx> getWalletTxs() override
292  {
293  auto locked_chain = m_wallet->chain().lock();
294  LOCK(m_wallet->cs_wallet);
295  std::vector<WalletTx> result;
296  result.reserve(m_wallet->mapWallet.size());
297  for (const auto& entry : m_wallet->mapWallet) {
298  result.emplace_back(MakeWalletTx(*locked_chain, *m_wallet, entry.second));
299  }
300  return result;
301  }
302  bool tryGetTxStatus(const uint256& txid,
303  interfaces::WalletTxStatus& tx_status,
304  int& num_blocks,
305  int64_t& block_time) override
306  {
307  auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
308  if (!locked_chain) {
309  return false;
310  }
311  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
312  if (!locked_wallet) {
313  return false;
314  }
315  auto mi = m_wallet->mapWallet.find(txid);
316  if (mi == m_wallet->mapWallet.end()) {
317  return false;
318  }
319  if (Optional<int> height = locked_chain->getHeight()) {
320  num_blocks = *height;
321  block_time = locked_chain->getBlockTime(*height);
322  } else {
323  num_blocks = -1;
324  block_time = -1;
325  }
326  tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
327  return true;
328  }
329  WalletTx getWalletTxDetails(const uint256& txid,
330  WalletTxStatus& tx_status,
331  WalletOrderForm& order_form,
332  bool& in_mempool,
333  int& num_blocks) override
334  {
335  auto locked_chain = m_wallet->chain().lock();
336  LOCK(m_wallet->cs_wallet);
337  auto mi = m_wallet->mapWallet.find(txid);
338  if (mi != m_wallet->mapWallet.end()) {
339  num_blocks = locked_chain->getHeight().get_value_or(-1);
340  in_mempool = mi->second.InMempool();
341  order_form = mi->second.vOrderForm;
342  tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
343  return MakeWalletTx(*locked_chain, *m_wallet, mi->second);
344  }
345  return {};
346  }
347  WalletBalances getBalances() override
348  {
349  const auto bal = m_wallet->GetBalance();
350  WalletBalances result;
351  result.balance = bal.m_mine_trusted;
352  result.unconfirmed_balance = bal.m_mine_untrusted_pending;
353  result.immature_balance = bal.m_mine_immature;
354  result.have_watch_only = m_wallet->HaveWatchOnly();
355  if (result.have_watch_only) {
356  result.watch_only_balance = bal.m_watchonly_trusted;
357  result.unconfirmed_watch_only_balance = bal.m_watchonly_untrusted_pending;
358  result.immature_watch_only_balance = bal.m_watchonly_immature;
359  }
360  return result;
361  }
362  bool tryGetBalances(WalletBalances& balances, int& num_blocks) override
363  {
364  auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
365  if (!locked_chain) return false;
366  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
367  if (!locked_wallet) {
368  return false;
369  }
370  balances = getBalances();
371  num_blocks = locked_chain->getHeight().get_value_or(-1);
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  auto locked_chain = m_wallet->chain().lock();
382  LOCK(m_wallet->cs_wallet);
383  return m_wallet->IsMine(txin);
384  }
385  isminetype txoutIsMine(const CTxOut& txout) override
386  {
387  auto locked_chain = m_wallet->chain().lock();
388  LOCK(m_wallet->cs_wallet);
389  return m_wallet->IsMine(txout);
390  }
391  CAmount getDebit(const CTxIn& txin, isminefilter filter) override
392  {
393  auto locked_chain = m_wallet->chain().lock();
394  LOCK(m_wallet->cs_wallet);
395  return m_wallet->GetDebit(txin, filter);
396  }
397  CAmount getCredit(const CTxOut& txout, isminefilter filter) override
398  {
399  auto locked_chain = m_wallet->chain().lock();
400  LOCK(m_wallet->cs_wallet);
401  return m_wallet->GetCredit(txout, filter);
402  }
403  CoinsList listCoins() override
404  {
405  auto locked_chain = m_wallet->chain().lock();
406  LOCK(m_wallet->cs_wallet);
407  CoinsList result;
408  for (const auto& entry : m_wallet->ListCoins(*locked_chain)) {
409  auto& group = result[entry.first];
410  for (const auto& coin : entry.second) {
411  group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i),
412  MakeWalletTxOut(*locked_chain, *m_wallet, *coin.tx, coin.i, coin.nDepth));
413  }
414  }
415  return result;
416  }
417  std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) override
418  {
419  auto locked_chain = m_wallet->chain().lock();
420  LOCK(m_wallet->cs_wallet);
421  std::vector<WalletTxOut> result;
422  result.reserve(outputs.size());
423  for (const auto& output : outputs) {
424  result.emplace_back();
425  auto it = m_wallet->mapWallet.find(output.hash);
426  if (it != m_wallet->mapWallet.end()) {
427  int depth = it->second.GetDepthInMainChain(*locked_chain);
428  if (depth >= 0) {
429  result.back() = MakeWalletTxOut(*locked_chain, *m_wallet, it->second, output.n, depth);
430  }
431  }
432  }
433  return result;
434  }
435  CAmount getRequiredFee(unsigned int tx_bytes) override { return GetRequiredFee(*m_wallet, tx_bytes); }
436  CAmount getMinimumFee(unsigned int tx_bytes,
437  const CCoinControl& coin_control,
438  int* returned_target,
439  FeeReason* reason) override
440  {
441  FeeCalculation fee_calc;
442  CAmount result;
443  result = GetMinimumFee(*m_wallet, tx_bytes, coin_control, &fee_calc);
444  if (returned_target) *returned_target = fee_calc.returnedTarget;
445  if (reason) *reason = fee_calc.reason;
446  return result;
447  }
448  unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
449  bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
450  bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
451  bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); }
452  OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
453  OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; }
454  CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }
455  void remove() override
456  {
458  }
459  std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
460  {
461  return MakeHandler(m_wallet->NotifyUnload.connect(fn));
462  }
463  std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
464  {
465  return MakeHandler(m_wallet->ShowProgress.connect(fn));
466  }
467  std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) override
468  {
469  return MakeHandler(m_wallet->NotifyStatusChanged.connect([fn](CWallet*) { fn(); }));
470  }
471  std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) override
472  {
473  return MakeHandler(m_wallet->NotifyAddressBookChanged.connect(
474  [fn](CWallet*, const CTxDestination& address, const std::string& label, bool is_mine,
475  const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); }));
476  }
477  std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override
478  {
479  return MakeHandler(m_wallet->NotifyTransactionChanged.connect(
480  [fn](CWallet*, const uint256& txid, ChangeType status) { fn(txid, status); }));
481  }
482  std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override
483  {
484  return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
485  }
486  std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override
487  {
488  return MakeHandler(m_wallet->NotifyCanGetAddressesChanged.connect(fn));
489  }
490 
491  std::shared_ptr<CWallet> m_wallet;
492 };
493 
494 class WalletClientImpl : public ChainClient
495 {
496 public:
497  WalletClientImpl(Chain& chain, std::vector<std::string> wallet_filenames)
498  : m_chain(chain), m_wallet_filenames(std::move(wallet_filenames))
499  {
500  }
501  void registerRpcs() override { return RegisterWalletRPCCommands(m_chain, m_rpc_handlers); }
502  bool verify() override { return VerifyWallets(m_chain, m_wallet_filenames); }
503  bool load() override { return LoadWallets(m_chain, m_wallet_filenames); }
504  void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
505  void flush() override { return FlushWallets(); }
506  void stop() override { return StopWallets(); }
507  ~WalletClientImpl() override { UnloadWallets(); }
508 
509  Chain& m_chain;
510  std::vector<std::string> m_wallet_filenames;
511  std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
512 };
513 
514 } // namespace
515 
516 std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? MakeUnique<WalletImpl>(wallet) : nullptr; }
517 
518 std::unique_ptr<ChainClient> MakeWalletClient(Chain& chain, std::vector<std::string> wallet_filenames)
519 {
520  return MakeUnique<WalletClientImpl>(chain, std::move(wallet_filenames));
521 }
522 
523 } // namespace interfaces
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
std::shared_ptr< CWallet > m_wallet
Definition: wallet.cpp:491
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:186
CCriticalSection cs_wallet
Definition: wallet.h:841
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:626
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
Definition: wallet.cpp:2206
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:19
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:518
virtual Optional< int > getBlockHeight(const uint256 &hash)=0
Get block height above genesis block.
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
Definition: handler.cpp:27
bool IsSpent(interfaces::Chain::Lock &locked_chain, 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:812
bool IsCoinBase() const
Definition: wallet.h:615
std::map< std::string, std::string > WalletValueMap
Definition: wallet.h:44
bool LoadWallets(interfaces::Chain &chain, const std::vector< std::string > &wallet_files)
Load wallet databases.
Definition: load.cpp:66
static CScheduler scheduler
Definition: init.cpp:155
void RegisterWalletRPCCommands(interfaces::Chain &chain, std::vector< std::unique_ptr< interfaces::Handler >> &handlers)
Definition: rpcwallet.cpp:4220
OutputType
Definition: outputtype.h:16
Coin Control Features.
Definition: coincontrol.h:19
void StartWallets(CScheduler &scheduler)
Complete startup of wallets.
Definition: load.cpp:79
bool IsTrusted(interfaces::Chain::Lock &locked_chain) const
Definition: wallet.cpp:2306
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: wallet.h:428
void StopWallets()
Stop all wallets. Wallets will be flushed first.
Definition: load.cpp:97
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool SignTransaction(CWallet *wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Definition: feebumper.cpp:298
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:74
CAmount GetCredit(interfaces::Chain::Lock &locked_chain, const isminefilter &filter) const
Definition: wallet.cpp:2221
ChangeType
General change type (added, updated, removed).
Definition: ui_interface.h:26
An input of a transaction.
Definition: transaction.h:63
#define LOCK(cs)
Definition: sync.h:182
const char * name
Definition: rest.cpp:39
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:509
An encapsulated public key.
Definition: pubkey.h:30
std::string GetRejectReason() const
Definition: validation.h:140
uint32_t n
Definition: transaction.h:22
uint8_t isminefilter
Definition: wallet.h:28
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:614
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:510
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:199
std::unique_ptr< Wallet > MakeWallet(const std::shared_ptr< CWallet > &wallet)
Return implementation of Wallet interface.
Definition: dummywallet.cpp:81
void FlushWallets()
Flush all wallets in preparation for shutdown.
Definition: load.cpp:90
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:394
isminetype IsMine(const CWallet &keystore, const CScript &scriptPubKey)
Definition: ismine.cpp:175
bool TransactionCanBeBumped(const CWallet *wallet, const uint256 &txid)
Return whether transaction can be bumped.
Definition: feebumper.cpp:62
Capture information about block/transaction validation.
Definition: validation.h:98
256-bit opaque blob.
Definition: uint256.h:121
uint256 hashBlock
Definition: wallet.h:483
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
int64_t GetTxTime() const
Definition: wallet.cpp:1744
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:54
Result CommitTransaction(CWallet *wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< std::string > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:304
bool IsInMainChain(interfaces::Chain::Lock &locked_chain) const
Definition: wallet.h:602
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:63
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:680
int GetDepthInMainChain(interfaces::Chain::Lock &locked_chain) const
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
Definition: wallet.cpp:4646
std::vector< std::pair< std::string, std::string > > WalletOrderForm
Definition: wallet.h:43
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:13
unsigned int nTimeReceived
time received by this node
Definition: wallet.h:431
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:611
void UnloadWallets()
Close all wallets.
Definition: load.cpp:104
isminetype IsMine(const CTxIn &txin) const
Definition: wallet.cpp:1465
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:139
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:14
int GetBlocksToMaturity(interfaces::Chain::Lock &locked_chain) const
Definition: wallet.cpp:4654
auto it
Definition: validation.cpp:366
bool error(const char *fmt, const Args &... args)
Definition: system.h:47
Updated transaction status.
Definition: wallet.h:347
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
Definition: wallet.cpp:511
CTransactionRef tx
Definition: wallet.h:482
CAmount GetChange() const
Definition: wallet.cpp:2292
UniValue stop(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:156
uint256 hash
Definition: transaction.h:21