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 <chain.h>
9 #include <consensus/validation.h>
10 #include <init.h>
11 #include <interfaces/chain.h>
12 #include <interfaces/handler.h>
13 #include <net.h>
14 #include <policy/feerate.h>
15 #include <policy/fees.h>
16 #include <policy/policy.h>
17 #include <primitives/transaction.h>
18 #include <rpc/server.h>
19 #include <scheduler.h>
20 #include <script/ismine.h>
21 #include <script/standard.h>
23 #include <sync.h>
24 #include <timedata.h>
25 #include <ui_interface.h>
26 #include <uint256.h>
27 #include <util/system.h>
28 #include <validation.h>
29 #include <wallet/feebumper.h>
30 #include <wallet/fees.h>
31 #include <wallet/rpcwallet.h>
32 #include <wallet/load.h>
33 #include <wallet/wallet.h>
34 #include <wallet/walletutil.h>
35 
36 #include <memory>
37 #include <string>
38 #include <utility>
39 #include <vector>
40 
41 namespace interfaces {
42 namespace {
43 
44 class PendingWalletTxImpl : public PendingWalletTx
45 {
46 public:
47  explicit PendingWalletTxImpl(CWallet& wallet) : m_wallet(wallet), m_key(&wallet) {}
48 
49  const CTransaction& get() override { return *m_tx; }
50 
51  bool commit(WalletValueMap value_map,
52  WalletOrderForm order_form,
53  std::string& reject_reason) override
54  {
55  auto locked_chain = m_wallet.chain().lock();
57  CValidationState state;
58  if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), m_key, state)) {
59  reject_reason = state.GetRejectReason();
60  return false;
61  }
62  return true;
63  }
64 
68 };
69 
71 WalletTx MakeWalletTx(interfaces::Chain::Lock& locked_chain, CWallet& wallet, const CWalletTx& wtx)
72 {
73  WalletTx result;
74  result.tx = wtx.tx;
75  result.txin_is_mine.reserve(wtx.tx->vin.size());
76  for (const auto& txin : wtx.tx->vin) {
77  result.txin_is_mine.emplace_back(wallet.IsMine(txin));
78  }
79  result.txout_is_mine.reserve(wtx.tx->vout.size());
80  result.txout_address.reserve(wtx.tx->vout.size());
81  result.txout_address_is_mine.reserve(wtx.tx->vout.size());
82  for (const auto& txout : wtx.tx->vout) {
83  result.txout_is_mine.emplace_back(wallet.IsMine(txout));
84  result.txout_address.emplace_back();
85  result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
86  IsMine(wallet, result.txout_address.back()) :
87  ISMINE_NO);
88  }
89  result.credit = wtx.GetCredit(locked_chain, ISMINE_ALL);
90  result.debit = wtx.GetDebit(ISMINE_ALL);
91  result.change = wtx.GetChange();
92  result.time = wtx.GetTxTime();
93  result.value_map = wtx.mapValue;
94  result.is_coinbase = wtx.IsCoinBase();
95  return result;
96 }
97 
99 WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
100 {
101  WalletTxStatus result;
102  result.block_height = locked_chain.getBlockHeight(wtx.hashBlock).get_value_or(std::numeric_limits<int>::max());
103  result.blocks_to_maturity = wtx.GetBlocksToMaturity(locked_chain);
104  result.depth_in_main_chain = wtx.GetDepthInMainChain(locked_chain);
105  result.time_received = wtx.nTimeReceived;
106  result.lock_time = wtx.tx->nLockTime;
107  result.is_final = locked_chain.checkFinalTx(*wtx.tx);
108  result.is_trusted = wtx.IsTrusted(locked_chain);
109  result.is_abandoned = wtx.isAbandoned();
110  result.is_coinbase = wtx.IsCoinBase();
111  result.is_in_main_chain = wtx.IsInMainChain(locked_chain);
112  return result;
113 }
114 
116 WalletTxOut MakeWalletTxOut(interfaces::Chain::Lock& locked_chain,
117  CWallet& wallet,
118  const CWalletTx& wtx,
119  int n,
120  int depth) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
121 {
122  WalletTxOut result;
123  result.txout = wtx.tx->vout[n];
124  result.time = wtx.GetTxTime();
125  result.depth_in_main_chain = depth;
126  result.is_spent = wallet.IsSpent(locked_chain, wtx.GetHash(), n);
127  return result;
128 }
129 
130 class WalletImpl : public Wallet
131 {
132 public:
133  explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet) {}
134 
135  bool encryptWallet(const SecureString& wallet_passphrase) override
136  {
137  return m_wallet->EncryptWallet(wallet_passphrase);
138  }
139  bool isCrypted() override { return m_wallet->IsCrypted(); }
140  bool lock() override { return m_wallet->Lock(); }
141  bool unlock(const SecureString& wallet_passphrase) override { return m_wallet->Unlock(wallet_passphrase); }
142  bool isLocked() override { return m_wallet->IsLocked(); }
143  bool changeWalletPassphrase(const SecureString& old_wallet_passphrase,
144  const SecureString& new_wallet_passphrase) override
145  {
146  return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
147  }
148  void abortRescan() override { m_wallet->AbortRescan(); }
149  bool backupWallet(const std::string& filename) override { return m_wallet->BackupWallet(filename); }
150  std::string getWalletName() override { return m_wallet->GetName(); }
151  bool getKeyFromPool(bool internal, CPubKey& pub_key) override
152  {
153  return m_wallet->GetKeyFromPool(pub_key, internal);
154  }
155  bool getPubKey(const CKeyID& address, CPubKey& pub_key) override { return m_wallet->GetPubKey(address, pub_key); }
156  bool getPrivKey(const CKeyID& address, CKey& key) override { return m_wallet->GetKey(address, key); }
157  bool isSpendable(const CTxDestination& dest) override { return IsMine(*m_wallet, dest) & ISMINE_SPENDABLE; }
158  bool haveWatchOnly() override { return m_wallet->HaveWatchOnly(); };
159  bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::string& purpose) override
160  {
161  return m_wallet->SetAddressBook(dest, name, purpose);
162  }
163  bool delAddressBook(const CTxDestination& dest) override
164  {
165  return m_wallet->DelAddressBook(dest);
166  }
167  bool getAddress(const CTxDestination& dest,
168  std::string* name,
169  isminetype* is_mine,
170  std::string* purpose) override
171  {
173  auto it = m_wallet->mapAddressBook.find(dest);
174  if (it == m_wallet->mapAddressBook.end()) {
175  return false;
176  }
177  if (name) {
178  *name = it->second.name;
179  }
180  if (is_mine) {
181  *is_mine = IsMine(*m_wallet, dest);
182  }
183  if (purpose) {
184  *purpose = it->second.purpose;
185  }
186  return true;
187  }
188  std::vector<WalletAddress> getAddresses() override
189  {
191  std::vector<WalletAddress> result;
192  for (const auto& item : m_wallet->mapAddressBook) {
193  result.emplace_back(item.first, IsMine(*m_wallet, item.first), item.second.name, item.second.purpose);
194  }
195  return result;
196  }
197  void learnRelatedScripts(const CPubKey& key, OutputType type) override { m_wallet->LearnRelatedScripts(key, type); }
198  bool addDestData(const CTxDestination& dest, const std::string& key, const std::string& value) override
199  {
201  return m_wallet->AddDestData(dest, key, value);
202  }
203  bool eraseDestData(const CTxDestination& dest, const std::string& key) override
204  {
206  return m_wallet->EraseDestData(dest, key);
207  }
208  std::vector<std::string> getDestValues(const std::string& prefix) override
209  {
211  return m_wallet->GetDestValues(prefix);
212  }
213  void lockCoin(const COutPoint& output) override
214  {
215  auto locked_chain = m_wallet->chain().lock();
217  return m_wallet->LockCoin(output);
218  }
219  void unlockCoin(const COutPoint& output) override
220  {
221  auto locked_chain = m_wallet->chain().lock();
223  return m_wallet->UnlockCoin(output);
224  }
225  bool isLockedCoin(const COutPoint& output) override
226  {
227  auto locked_chain = m_wallet->chain().lock();
229  return m_wallet->IsLockedCoin(output.hash, output.n);
230  }
231  void listLockedCoins(std::vector<COutPoint>& outputs) override
232  {
233  auto locked_chain = m_wallet->chain().lock();
235  return m_wallet->ListLockedCoins(outputs);
236  }
237  std::unique_ptr<PendingWalletTx> createTransaction(const std::vector<CRecipient>& recipients,
238  const CCoinControl& coin_control,
239  bool sign,
240  int& change_pos,
241  CAmount& fee,
242  std::string& fail_reason) override
243  {
244  auto locked_chain = m_wallet->chain().lock();
246  auto pending = MakeUnique<PendingWalletTxImpl>(*m_wallet);
247  if (!m_wallet->CreateTransaction(*locked_chain, recipients, pending->m_tx, pending->m_key, fee, change_pos,
248  fail_reason, coin_control, sign)) {
249  return {};
250  }
251  return std::move(pending);
252  }
253  bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
254  bool abandonTransaction(const uint256& txid) override
255  {
256  auto locked_chain = m_wallet->chain().lock();
258  return m_wallet->AbandonTransaction(*locked_chain, txid);
259  }
260  bool transactionCanBeBumped(const uint256& txid) override
261  {
262  return feebumper::TransactionCanBeBumped(m_wallet.get(), txid);
263  }
264  bool createBumpTransaction(const uint256& txid,
265  const CCoinControl& coin_control,
266  CAmount total_fee,
267  std::vector<std::string>& errors,
268  CAmount& old_fee,
269  CAmount& new_fee,
270  CMutableTransaction& mtx) override
271  {
272  if (total_fee > 0) {
273  return feebumper::CreateTotalBumpTransaction(m_wallet.get(), txid, coin_control, total_fee, errors, old_fee, new_fee, mtx) ==
275  } else {
276  return feebumper::CreateRateBumpTransaction(m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx) ==
278  }
279  }
280  bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(m_wallet.get(), mtx); }
281  bool commitBumpTransaction(const uint256& txid,
282  CMutableTransaction&& mtx,
283  std::vector<std::string>& errors,
284  uint256& bumped_txid) override
285  {
286  return feebumper::CommitTransaction(m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) ==
288  }
289  CTransactionRef getTx(const uint256& txid) override
290  {
291  auto locked_chain = m_wallet->chain().lock();
293  auto mi = m_wallet->mapWallet.find(txid);
294  if (mi != m_wallet->mapWallet.end()) {
295  return mi->second.tx;
296  }
297  return {};
298  }
299  WalletTx getWalletTx(const uint256& txid) override
300  {
301  auto locked_chain = m_wallet->chain().lock();
303  auto mi = m_wallet->mapWallet.find(txid);
304  if (mi != m_wallet->mapWallet.end()) {
305  return MakeWalletTx(*locked_chain, *m_wallet, mi->second);
306  }
307  return {};
308  }
309  std::vector<WalletTx> getWalletTxs() override
310  {
311  auto locked_chain = m_wallet->chain().lock();
313  std::vector<WalletTx> result;
314  result.reserve(m_wallet->mapWallet.size());
315  for (const auto& entry : m_wallet->mapWallet) {
316  result.emplace_back(MakeWalletTx(*locked_chain, *m_wallet, entry.second));
317  }
318  return result;
319  }
320  bool tryGetTxStatus(const uint256& txid,
321  interfaces::WalletTxStatus& tx_status,
322  int& num_blocks,
323  int64_t& block_time) override
324  {
325  auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
326  if (!locked_chain) {
327  return false;
328  }
329  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
330  if (!locked_wallet) {
331  return false;
332  }
333  auto mi = m_wallet->mapWallet.find(txid);
334  if (mi == m_wallet->mapWallet.end()) {
335  return false;
336  }
337  if (Optional<int> height = locked_chain->getHeight()) {
338  num_blocks = *height;
339  block_time = locked_chain->getBlockTime(*height);
340  } else {
341  num_blocks = -1;
342  block_time = -1;
343  }
344  tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
345  return true;
346  }
347  WalletTx getWalletTxDetails(const uint256& txid,
348  WalletTxStatus& tx_status,
349  WalletOrderForm& order_form,
350  bool& in_mempool,
351  int& num_blocks) override
352  {
353  auto locked_chain = m_wallet->chain().lock();
355  auto mi = m_wallet->mapWallet.find(txid);
356  if (mi != m_wallet->mapWallet.end()) {
357  num_blocks = locked_chain->getHeight().get_value_or(-1);
358  in_mempool = mi->second.InMempool();
359  order_form = mi->second.vOrderForm;
360  tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
361  return MakeWalletTx(*locked_chain, *m_wallet, mi->second);
362  }
363  return {};
364  }
365  WalletBalances getBalances() override
366  {
367  const auto bal = m_wallet->GetBalance();
368  WalletBalances result;
369  result.balance = bal.m_mine_trusted;
370  result.unconfirmed_balance = bal.m_mine_untrusted_pending;
371  result.immature_balance = bal.m_mine_immature;
372  result.have_watch_only = m_wallet->HaveWatchOnly();
373  if (result.have_watch_only) {
374  result.watch_only_balance = bal.m_watchonly_trusted;
375  result.unconfirmed_watch_only_balance = bal.m_watchonly_untrusted_pending;
376  result.immature_watch_only_balance = bal.m_watchonly_immature;
377  }
378  return result;
379  }
380  bool tryGetBalances(WalletBalances& balances, int& num_blocks) override
381  {
382  auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
383  if (!locked_chain) return false;
384  TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
385  if (!locked_wallet) {
386  return false;
387  }
388  balances = getBalances();
389  num_blocks = locked_chain->getHeight().get_value_or(-1);
390  return true;
391  }
392  CAmount getBalance() override { return m_wallet->GetBalance().m_mine_trusted; }
393  CAmount getAvailableBalance(const CCoinControl& coin_control) override
394  {
395  return m_wallet->GetAvailableBalance(&coin_control);
396  }
397  isminetype txinIsMine(const CTxIn& txin) override
398  {
399  auto locked_chain = m_wallet->chain().lock();
401  return m_wallet->IsMine(txin);
402  }
403  isminetype txoutIsMine(const CTxOut& txout) override
404  {
405  auto locked_chain = m_wallet->chain().lock();
407  return m_wallet->IsMine(txout);
408  }
409  CAmount getDebit(const CTxIn& txin, isminefilter filter) override
410  {
411  auto locked_chain = m_wallet->chain().lock();
413  return m_wallet->GetDebit(txin, filter);
414  }
415  CAmount getCredit(const CTxOut& txout, isminefilter filter) override
416  {
417  auto locked_chain = m_wallet->chain().lock();
419  return m_wallet->GetCredit(txout, filter);
420  }
421  CoinsList listCoins() override
422  {
423  auto locked_chain = m_wallet->chain().lock();
425  CoinsList result;
426  for (const auto& entry : m_wallet->ListCoins(*locked_chain)) {
427  auto& group = result[entry.first];
428  for (const auto& coin : entry.second) {
429  group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i),
430  MakeWalletTxOut(*locked_chain, *m_wallet, *coin.tx, coin.i, coin.nDepth));
431  }
432  }
433  return result;
434  }
435  std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) override
436  {
437  auto locked_chain = m_wallet->chain().lock();
439  std::vector<WalletTxOut> result;
440  result.reserve(outputs.size());
441  for (const auto& output : outputs) {
442  result.emplace_back();
443  auto it = m_wallet->mapWallet.find(output.hash);
444  if (it != m_wallet->mapWallet.end()) {
445  int depth = it->second.GetDepthInMainChain(*locked_chain);
446  if (depth >= 0) {
447  result.back() = MakeWalletTxOut(*locked_chain, *m_wallet, it->second, output.n, depth);
448  }
449  }
450  }
451  return result;
452  }
453  CAmount getRequiredFee(unsigned int tx_bytes) override { return GetRequiredFee(*m_wallet, tx_bytes); }
454  CAmount getMinimumFee(unsigned int tx_bytes,
455  const CCoinControl& coin_control,
456  int* returned_target,
457  FeeReason* reason) override
458  {
459  FeeCalculation fee_calc;
460  CAmount result;
461  result = GetMinimumFee(*m_wallet, tx_bytes, coin_control, &fee_calc);
462  if (returned_target) *returned_target = fee_calc.returnedTarget;
463  if (reason) *reason = fee_calc.reason;
464  return result;
465  }
466  unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
467  bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
468  bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
469  bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); }
470  OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
471  OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; }
472  CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }
473  void remove() override
474  {
476  }
477  std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
478  {
479  return MakeHandler(m_wallet->NotifyUnload.connect(fn));
480  }
481  std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
482  {
483  return MakeHandler(m_wallet->ShowProgress.connect(fn));
484  }
485  std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) override
486  {
487  return MakeHandler(m_wallet->NotifyStatusChanged.connect([fn](CCryptoKeyStore*) { fn(); }));
488  }
489  std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) override
490  {
492  [fn](CWallet*, const CTxDestination& address, const std::string& label, bool is_mine,
493  const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); }));
494  }
495  std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override
496  {
498  [fn](CWallet*, const uint256& txid, ChangeType status) { fn(txid, status); }));
499  }
500  std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override
501  {
502  return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
503  }
504  std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override
505  {
507  }
508 
509  std::shared_ptr<CWallet> m_wallet;
510 };
511 
512 class WalletClientImpl : public ChainClient
513 {
514 public:
515  WalletClientImpl(Chain& chain, std::vector<std::string> wallet_filenames)
516  : m_chain(chain), m_wallet_filenames(std::move(wallet_filenames))
517  {
518  }
519  void registerRpcs() override { return RegisterWalletRPCCommands(m_chain, m_rpc_handlers); }
520  bool verify() override { return VerifyWallets(m_chain, m_wallet_filenames); }
521  bool load() override { return LoadWallets(m_chain, m_wallet_filenames); }
522  void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
523  void flush() override { return FlushWallets(); }
524  void stop() override { return StopWallets(); }
525  ~WalletClientImpl() override { UnloadWallets(); }
526 
527  Chain& m_chain;
528  std::vector<std::string> m_wallet_filenames;
529  std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
530 };
531 
532 } // namespace
533 
534 std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? MakeUnique<WalletImpl>(wallet) : nullptr; }
535 
536 std::unique_ptr<ChainClient> MakeWalletClient(Chain& chain, std::vector<std::string> wallet_filenames)
537 {
538  return MakeUnique<WalletClientImpl>(chain, std::move(wallet_filenames));
539 }
540 
541 } // namespace interfaces
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
CReserveKey m_key
Definition: wallet.cpp:67
OutputType m_default_change_type
Definition: wallet.h:1066
CWallet & m_wallet
Definition: wallet.cpp:66
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:159
bool CanGetAddresses(bool internal=false)
Definition: wallet.cpp:1519
int returnedTarget
Definition: fees.h:81
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition: wallet.h:1187
void UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3682
#define TRY_LOCK(cs, name)
Definition: sync.h:186
CAmount GetAvailableBalance(const CCoinControl *coinControl=nullptr) const
Definition: wallet.cpp:2165
CCriticalSection cs_wallet
Definition: wallet.h:803
const uint256 & GetHash() const
Definition: wallet.h:409
virtual int64_t getBlockTime(int height)=0
Get block time. Height must be valid or this function will abort.
bool EraseDestData(const CTxDestination &dest, const std::string &key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Erases a destination data tuple in the store and on disk.
Definition: wallet.cpp:3830
bool IsCrypted() const
Definition: crypter.h:144
CTransactionRef m_tx
Definition: wallet.cpp:65
const char * prefix
Definition: rest.cpp:625
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
Definition: wallet.cpp:1933
Balance GetBalance(int min_depth=0) const
Definition: wallet.cpp:2137
uint256 hashBlock
Definition: wallet.h:345
FeeReason reason
Definition: fees.h:79
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:21
Interface for querying locked chain state, used by legacy code that assumes state won&#39;t change betwee...
Definition: chain.h:68
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:536
virtual Optional< int > getBlockHeight(const uint256 &hash)=0
Get block height above genesis block.
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
Definition: wallet.h:1015
uint8_t isminefilter
used for bitflags of isminetype
Definition: ismine.h:27
bool IsWalletFlagSet(uint64_t flag)
check if a certain wallet flag is set
Definition: wallet.cpp:1552
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
Definition: handler.cpp:27
CAmount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
Definition: wallet.h:1068
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:687
std::map< std::string, std::string > WalletValueMap
Definition: wallet.h:43
bool LoadWallets(interfaces::Chain &chain, const std::vector< std::string > &wallet_files)
Load wallet databases.
Definition: load.cpp:65
Keystore which keeps the private keys encrypted.
Definition: crypter.h:115
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:730
void RegisterWalletRPCCommands(interfaces::Chain &chain, std::vector< std::unique_ptr< interfaces::Handler >> &handlers)
Definition: rpcwallet.cpp:4235
OutputType
Definition: outputtype.h:16
Coin Control Features.
Definition: coincontrol.h:16
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
Definition: crypter.cpp:278
void StartWallets(CScheduler &scheduler)
Complete startup of wallets.
Definition: load.cpp:78
bool IsTrusted(interfaces::Chain::Lock &locked_chain) const
Definition: wallet.cpp:2033
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: wallet.h:452
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition: wallet.h:877
void StopWallets()
Stop all wallets. Wallets will be flushed first.
Definition: load.cpp:96
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:1162
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:1178
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:3153
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: crypter.h:159
bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3694
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:3171
bool SignTransaction(CWallet *wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Definition: feebumper.cpp:306
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:78
CAmount GetCredit(interfaces::Chain::Lock &locked_chain, const isminefilter &filter) const
Definition: wallet.cpp:1948
ChangeType
General change type (added, updated, removed).
Definition: ui_interface.h:26
CTransactionRef tx
Definition: wallet.h:344
isminetype
IsMine() return codes.
Definition: ismine.h:18
An input of a transaction.
Definition: transaction.h:63
OutputType m_default_address_type
Definition: wallet.h:1065
bool IsHDEnabled() const
Definition: wallet.cpp:1507
#define LOCK(cs)
Definition: sync.h:182
const char * name
Definition: rest.cpp:38
bool IsLocked() const
Definition: crypter.cpp:155
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:527
An encapsulated public key.
Definition: pubkey.h:30
bool TransactionCanBeAbandoned(const uint256 &hashTx) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1095
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Adds a destination data tuple to the store, and saves it to disk.
Definition: wallet.cpp:3821
std::string GetRejectReason() const
Definition: validation.h:140
uint32_t n
Definition: transaction.h:22
bool IsCoinBase() const
Definition: wallet.h:410
bool GetKey(const CKeyID &address, CKey &keyOut) const override
Definition: crypter.cpp:261
An output of a transaction.
Definition: transaction.h:133
FeeReason
Definition: fees.h:36
virtual std::unique_ptr< Lock > lock(bool try_lock=false)=0
Return Lock interface.
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:528
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:203
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:89
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:421
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3702
void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3676
bool TransactionCanBeBumped(const CWallet *wallet, const uint256 &txid)
Return whether transaction can be bumped.
Definition: feebumper.cpp:66
Capture information about block/transaction validation.
Definition: validation.h:98
256-bit opaque blob.
Definition: uint256.h:121
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
unsigned int m_confirm_target
Definition: wallet.h:1053
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition: wallet.h:1171
CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Returns amount of debit if the input matches the filter, otherwise returns 0.
Definition: wallet.cpp:1316
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:521
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:825
int64_t GetTxTime() const
Definition: wallet.cpp:1572
A wrapper to reserve a key from a wallet keypool.
Definition: wallet.h:252
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:58
Result CommitTransaction(CWallet *wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< std::string > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:312
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey)
Definition: ismine.cpp:175
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
void LearnRelatedScripts(const CPubKey &key, OutputType)
Explicitly make the wallet learn the related scripts for outputs to the given key.
Definition: wallet.cpp:4380
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:59
bool CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector< std::pair< std::string, std::string >> orderForm, CReserveKey &reservekey, CValidationState &state)
Call after CreateTransaction unless you want to abort.
Definition: wallet.cpp:3018
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:692
bool IsInMainChain(interfaces::Chain::Lock &locked_chain) const
Definition: wallet.h:397
void AbortRescan()
Definition: wallet.h:920
std::vector< std::pair< std::string, std::string > > WalletOrderForm
Definition: wallet.h:42
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:1181
bool GetKeyFromPool(CPubKey &key, bool internal=false)
Definition: wallet.cpp:3414
A mutable version of CTransaction.
Definition: transaction.h:366
bool Unlock(const SecureString &strWalletPassphrase, bool accept_no_keys=false)
Definition: wallet.cpp:498
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:15
unsigned int nTimeReceived
time received by this node
Definition: wallet.h:455
An encapsulated private key.
Definition: key.h:27
bool HaveWatchOnly(const CScript &dest) const override
Definition: keystore.cpp:165
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:270
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:14
void UnloadWallets()
Close all wallets.
Definition: load.cpp:103
std::vector< std::string > GetDestValues(const std::string &prefix) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get all destination values matching a prefix.
Definition: wallet.cpp:3858
CAmount GetCredit(const CTxOut &txout, const isminefilter &filter) const
Definition: wallet.cpp:1337
bool AbandonTransaction(interfaces::Chain::Lock &locked_chain, const uint256 &hashTx)
Definition: wallet.cpp:1113
isminetype IsMine(const CTxIn &txin) const
Definition: wallet.cpp:1299
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:13
bool BackupWallet(const std::string &strDest)
Definition: wallet.cpp:4310
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:1184
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:4345
Updated transaction status.
Definition: wallet.h:355
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
Definition: wallet.cpp:529
std::map< CTxDestination, std::vector< COutput > > ListCoins(interfaces::Chain::Lock &locked_chain) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Return list of available coins and locked coins grouped by non-change output address.
Definition: wallet.cpp:2290
CAmount GetChange() const
Definition: wallet.cpp:2019
UniValue stop(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:158
int GetBlocksToMaturity(interfaces::Chain::Lock &locked_chain) const
Definition: wallet.cpp:4353
bool isAbandoned() const
Definition: wallet.h:406
uint256 hash
Definition: transaction.h:21