Bitcoin ABC 0.31.2
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
interfaces.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 <chainparams.h>
8#include <common/args.h>
9#include <config.h>
10#include <consensus/amount.h>
12#include <interfaces/chain.h>
13#include <interfaces/handler.h>
15#include <rpc/server.h>
16#include <script/standard.h>
18#include <sync.h>
19#include <util/check.h>
20#include <util/ui_change_type.h>
21#include <wallet/context.h>
22#include <wallet/fees.h>
23#include <wallet/ismine.h>
24#include <wallet/load.h>
25#include <wallet/receive.h>
26#include <wallet/rpc/backup.h>
27#include <wallet/rpc/encrypt.h>
28#include <wallet/spend.h>
29#include <wallet/wallet.h>
30
44
45namespace wallet {
46namespace {
47
49 WalletTx MakeWalletTx(CWallet &wallet, const CWalletTx &wtx) {
50 LOCK(wallet.cs_wallet);
51 WalletTx result;
52 result.tx = wtx.tx;
53 result.txin_is_mine.reserve(wtx.tx->vin.size());
54 for (const auto &txin : wtx.tx->vin) {
55 result.txin_is_mine.emplace_back(InputIsMine(wallet, txin));
56 }
57 result.txout_is_mine.reserve(wtx.tx->vout.size());
58 result.txout_address.reserve(wtx.tx->vout.size());
59 result.txout_address_is_mine.reserve(wtx.tx->vout.size());
60 for (const auto &txout : wtx.tx->vout) {
61 result.txout_is_mine.emplace_back(wallet.IsMine(txout));
62 result.txout_address.emplace_back();
63 result.txout_address_is_mine.emplace_back(
64 ExtractDestination(txout.scriptPubKey,
65 result.txout_address.back())
66 ? wallet.IsMine(result.txout_address.back())
67 : ISMINE_NO);
68 }
71 result.change = CachedTxGetChange(wallet, wtx);
72 result.time = wtx.GetTxTime();
73 result.value_map = wtx.mapValue;
74 result.is_coinbase = wtx.IsCoinBase();
75 return result;
76 }
77
79 WalletTxStatus MakeWalletTxStatus(const CWallet &wallet,
80 const CWalletTx &wtx)
82 AssertLockHeld(wallet.cs_wallet);
83
84 WalletTxStatus result;
85 result.block_height = wtx.m_confirm.block_height > 0
87 : std::numeric_limits<int>::max();
88 result.blocks_to_maturity = wallet.GetTxBlocksToMaturity(wtx);
89 result.depth_in_main_chain = wallet.GetTxDepthInMainChain(wtx);
90 result.time_received = wtx.nTimeReceived;
91 result.lock_time = wtx.tx->nLockTime;
92 result.is_trusted = CachedTxIsTrusted(wallet, wtx);
93 result.is_abandoned = wtx.isAbandoned();
94 result.is_coinbase = wtx.IsCoinBase();
95 result.is_in_main_chain = wallet.IsTxInMainChain(wtx);
96 return result;
97 }
98
100 WalletTxOut MakeWalletTxOut(const CWallet &wallet, const CWalletTx &wtx,
101 int n, int depth)
103 AssertLockHeld(wallet.cs_wallet);
104
105 WalletTxOut result;
106 result.txout = wtx.tx->vout[n];
107 result.time = wtx.GetTxTime();
108 result.depth_in_main_chain = depth;
109 result.is_spent = wallet.IsSpent(COutPoint(wtx.GetId(), n));
110 return result;
111 }
112
113 class WalletImpl : public Wallet {
114 public:
115 explicit WalletImpl(WalletContext &context,
116 const std::shared_ptr<CWallet> &wallet)
117 : m_context(context), m_wallet(wallet) {}
118
119 bool encryptWallet(const SecureString &wallet_passphrase) override {
120 return m_wallet->EncryptWallet(wallet_passphrase);
121 }
122 bool isCrypted() override { return m_wallet->IsCrypted(); }
123 bool lock() override { return m_wallet->Lock(); }
124 bool unlock(const SecureString &wallet_passphrase) override {
125 return m_wallet->Unlock(wallet_passphrase);
126 }
127 bool isLocked() override { return m_wallet->IsLocked(); }
128 bool changeWalletPassphrase(
129 const SecureString &old_wallet_passphrase,
130 const SecureString &new_wallet_passphrase) override {
131 return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase,
132 new_wallet_passphrase);
133 }
134 void abortRescan() override { m_wallet->AbortRescan(); }
135 bool backupWallet(const std::string &filename) override {
136 return m_wallet->BackupWallet(filename);
137 }
138 std::string getWalletName() override { return m_wallet->GetName(); }
140 getNewDestination(const OutputType type,
141 const std::string &label) override {
142 LOCK(m_wallet->cs_wallet);
143 return m_wallet->GetNewDestination(type, label);
144 }
145 const CChainParams &getChainParams() override {
146 return m_wallet->GetChainParams();
147 }
148 bool getPubKey(const CScript &script, const CKeyID &address,
149 CPubKey &pub_key) override {
150 std::unique_ptr<SigningProvider> provider =
151 m_wallet->GetSolvingProvider(script);
152 if (provider) {
153 return provider->GetPubKey(address, pub_key);
154 }
155 return false;
156 }
157 SigningResult signMessage(const std::string &message,
158 const PKHash &pkhash,
159 std::string &str_sig) override {
160 return m_wallet->SignMessage(message, pkhash, str_sig);
161 }
162 bool isSpendable(const CTxDestination &dest) override {
163 LOCK(m_wallet->cs_wallet);
164 return m_wallet->IsMine(dest) & ISMINE_SPENDABLE;
165 }
166 bool haveWatchOnly() override {
167 auto spk_man = m_wallet->GetLegacyScriptPubKeyMan();
168 if (spk_man) {
169 return spk_man->HaveWatchOnly();
170 }
171 return false;
172 };
173 bool setAddressBook(const CTxDestination &dest, const std::string &name,
174 const std::string &purpose) override {
175 return m_wallet->SetAddressBook(dest, name, purpose);
176 }
177 bool delAddressBook(const CTxDestination &dest) override {
178 return m_wallet->DelAddressBook(dest);
179 }
180 bool getAddress(const CTxDestination &dest, std::string *name,
181 isminetype *is_mine, std::string *purpose) override {
182 LOCK(m_wallet->cs_wallet);
183 auto it = m_wallet->m_address_book.find(dest);
184 if (it == m_wallet->m_address_book.end() || it->second.IsChange()) {
185 return false;
186 }
187 if (name) {
188 *name = it->second.GetLabel();
189 }
190 if (is_mine) {
191 *is_mine = m_wallet->IsMine(dest);
192 }
193 if (purpose) {
194 *purpose = it->second.purpose;
195 }
196 return true;
197 }
198 std::vector<WalletAddress> getAddresses() override {
199 LOCK(m_wallet->cs_wallet);
200 std::vector<WalletAddress> result;
201 for (const auto &item : m_wallet->m_address_book) {
202 if (item.second.IsChange()) {
203 continue;
204 }
205 result.emplace_back(item.first, m_wallet->IsMine(item.first),
206 item.second.GetLabel(),
207 item.second.purpose);
208 }
209 return result;
210 }
211 bool addDestData(const CTxDestination &dest, const std::string &key,
212 const std::string &value) override {
213 LOCK(m_wallet->cs_wallet);
214 WalletBatch batch{m_wallet->GetDatabase()};
215 return m_wallet->AddDestData(batch, dest, key, value);
216 }
217 bool eraseDestData(const CTxDestination &dest,
218 const std::string &key) override {
219 LOCK(m_wallet->cs_wallet);
220 WalletBatch batch{m_wallet->GetDatabase()};
221 return m_wallet->EraseDestData(batch, dest, key);
222 }
223 std::vector<std::string>
224 getDestValues(const std::string &prefix) override {
225 LOCK(m_wallet->cs_wallet);
226 return m_wallet->GetDestValues(prefix);
227 }
228 void lockCoin(const COutPoint &output) override {
229 LOCK(m_wallet->cs_wallet);
230 return m_wallet->LockCoin(output);
231 }
232 void unlockCoin(const COutPoint &output) override {
233 LOCK(m_wallet->cs_wallet);
234 return m_wallet->UnlockCoin(output);
235 }
236 bool isLockedCoin(const COutPoint &output) override {
237 LOCK(m_wallet->cs_wallet);
238 return m_wallet->IsLockedCoin(output);
239 }
240 void listLockedCoins(std::vector<COutPoint> &outputs) override {
241 LOCK(m_wallet->cs_wallet);
242 return m_wallet->ListLockedCoins(outputs);
243 }
245 createTransaction(const std::vector<CRecipient> &recipients,
246 const CCoinControl &coin_control, bool sign,
247 int &change_pos, Amount &fee) override {
248 LOCK(m_wallet->cs_wallet);
249 auto res = CreateTransaction(*m_wallet, recipients, change_pos,
250 coin_control, sign);
251 if (!res) {
252 return util::Error{util::ErrorString(res)};
253 }
254 const auto &txr = *res;
255 fee = txr.fee;
256 change_pos = txr.change_pos;
257
258 return txr.tx;
259 }
260 void commitTransaction(CTransactionRef tx, WalletValueMap value_map,
261 WalletOrderForm order_form) override {
262 LOCK(m_wallet->cs_wallet);
263 m_wallet->CommitTransaction(std::move(tx), std::move(value_map),
264 std::move(order_form));
265 }
266 bool transactionCanBeAbandoned(const TxId &txid) override {
267 return m_wallet->TransactionCanBeAbandoned(txid);
268 }
269 bool abandonTransaction(const TxId &txid) override {
270 LOCK(m_wallet->cs_wallet);
271 return m_wallet->AbandonTransaction(txid);
272 }
273 CTransactionRef getTx(const TxId &txid) override {
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 TxId &txid) override {
282 LOCK(m_wallet->cs_wallet);
283 auto mi = m_wallet->mapWallet.find(txid);
284 if (mi != m_wallet->mapWallet.end()) {
285 return MakeWalletTx(*m_wallet, mi->second);
286 }
287 return {};
288 }
289 std::vector<WalletTx> getWalletTxs() override {
290 LOCK(m_wallet->cs_wallet);
291 std::vector<WalletTx> result;
292 result.reserve(m_wallet->mapWallet.size());
293 for (const auto &entry : m_wallet->mapWallet) {
294 result.emplace_back(MakeWalletTx(*m_wallet, entry.second));
295 }
296 return result;
297 }
298 bool tryGetTxStatus(const TxId &txid,
300 int &num_blocks, int64_t &block_time) override {
301 TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
302 if (!locked_wallet) {
303 return false;
304 }
305 auto mi = m_wallet->mapWallet.find(txid);
306 if (mi == m_wallet->mapWallet.end()) {
307 return false;
308 }
309 num_blocks = m_wallet->GetLastBlockHeight();
310 block_time = -1;
311 CHECK_NONFATAL(m_wallet->chain().findBlock(
312 m_wallet->GetLastBlockHash(), FoundBlock().time(block_time)));
313 tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
314 return true;
315 }
316 WalletTx getWalletTxDetails(const TxId &txid, WalletTxStatus &tx_status,
317 WalletOrderForm &order_form,
318 bool &in_mempool,
319 int &num_blocks) override {
320 LOCK(m_wallet->cs_wallet);
321 auto mi = m_wallet->mapWallet.find(txid);
322 if (mi != m_wallet->mapWallet.end()) {
323 num_blocks = m_wallet->GetLastBlockHeight();
324 in_mempool = mi->second.InMempool();
325 order_form = mi->second.vOrderForm;
326 tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
327 return MakeWalletTx(*m_wallet, mi->second);
328 }
329 return {};
330 }
331 TransactionError fillPSBT(SigHashType sighash_type, bool sign,
332 bool bip32derivs,
334 bool &complete) const override {
335 return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign,
336 bip32derivs);
337 }
338 WalletBalances getBalances() override {
339 const auto bal = GetBalance(*m_wallet);
340 WalletBalances result;
341 result.balance = bal.m_mine_trusted;
342 result.unconfirmed_balance = bal.m_mine_untrusted_pending;
343 result.immature_balance = bal.m_mine_immature;
344 result.have_watch_only = haveWatchOnly();
345 if (result.have_watch_only) {
346 result.watch_only_balance = bal.m_watchonly_trusted;
348 bal.m_watchonly_untrusted_pending;
349 result.immature_watch_only_balance = bal.m_watchonly_immature;
350 }
351 return result;
352 }
353 bool tryGetBalances(WalletBalances &balances,
354 BlockHash &block_hash) override {
355 TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
356 if (!locked_wallet) {
357 return false;
358 }
359 block_hash = m_wallet->GetLastBlockHash();
360 balances = getBalances();
361 return true;
362 }
363 Amount getBalance() override {
364 return GetBalance(*m_wallet).m_mine_trusted;
365 }
366 Amount getAvailableBalance(const CCoinControl &coin_control) override {
367 return GetAvailableBalance(*m_wallet, &coin_control);
368 }
369 isminetype txinIsMine(const CTxIn &txin) override {
370 LOCK(m_wallet->cs_wallet);
371 return InputIsMine(*m_wallet, txin);
372 }
373 isminetype txoutIsMine(const CTxOut &txout) override {
374 LOCK(m_wallet->cs_wallet);
375 return m_wallet->IsMine(txout);
376 }
377 Amount getDebit(const CTxIn &txin, isminefilter filter) override {
378 LOCK(m_wallet->cs_wallet);
379 return m_wallet->GetDebit(txin, filter);
380 }
381 Amount getCredit(const CTxOut &txout, isminefilter filter) override {
382 LOCK(m_wallet->cs_wallet);
383 return OutputGetCredit(*m_wallet, txout, filter);
384 }
385 CoinsList listCoins() override {
386 LOCK(m_wallet->cs_wallet);
387 CoinsList result;
388 for (const auto &entry : ListCoins(*m_wallet)) {
389 auto &group = result[entry.first];
390 for (const auto &coin : entry.second) {
391 group.emplace_back(COutPoint(coin.tx->GetId(), coin.i),
392 MakeWalletTxOut(*m_wallet, *coin.tx,
393 coin.i, coin.nDepth));
394 }
395 }
396 return result;
397 }
398 std::vector<WalletTxOut>
399 getCoins(const std::vector<COutPoint> &outputs) override {
400 LOCK(m_wallet->cs_wallet);
401 std::vector<WalletTxOut> result;
402 result.reserve(outputs.size());
403 for (const auto &output : outputs) {
404 result.emplace_back();
405 auto it = m_wallet->mapWallet.find(output.GetTxId());
406 if (it != m_wallet->mapWallet.end()) {
407 int depth = m_wallet->GetTxDepthInMainChain(it->second);
408 if (depth >= 0) {
409 result.back() = MakeWalletTxOut(*m_wallet, it->second,
410 output.GetN(), depth);
411 }
412 }
413 }
414 return result;
415 }
416 bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
417 OutputType getDefaultAddressType() override {
418 return m_wallet->m_default_address_type;
419 }
420 bool canGetAddresses() const override {
421 return m_wallet->CanGetAddresses();
422 }
423 bool privateKeysDisabled() override {
424 return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
425 }
426 Amount getDefaultMaxTxFee() override {
427 return m_wallet->m_default_max_tx_fee;
428 }
429 void remove() override {
430 RemoveWallet(m_context, m_wallet, false /* load_on_start */);
431 }
432 bool isLegacy() override { return m_wallet->IsLegacy(); }
433 std::unique_ptr<Handler> handleUnload(UnloadFn fn) override {
434 return MakeHandler(m_wallet->NotifyUnload.connect(fn));
435 }
436 std::unique_ptr<Handler>
437 handleShowProgress(ShowProgressFn fn) override {
438 return MakeHandler(m_wallet->ShowProgress.connect(fn));
439 }
440 std::unique_ptr<Handler>
441 handleStatusChanged(StatusChangedFn fn) override {
442 return MakeHandler(m_wallet->NotifyStatusChanged.connect(
443 [fn](CWallet *) { fn(); }));
444 }
445 std::unique_ptr<Handler>
446 handleAddressBookChanged(AddressBookChangedFn fn) override {
447 return MakeHandler(m_wallet->NotifyAddressBookChanged.connect(
448 [fn](CWallet *, const CTxDestination &address,
449 const std::string &label, bool is_mine,
450 const std::string &purpose, ChangeType status) {
451 fn(address, label, is_mine, purpose, status);
452 }));
453 }
454 std::unique_ptr<Handler>
455 handleTransactionChanged(TransactionChangedFn fn) override {
456 return MakeHandler(m_wallet->NotifyTransactionChanged.connect(
457 [fn](CWallet *, const TxId &txid, ChangeType status) {
458 fn(txid, status);
459 }));
460 }
461 std::unique_ptr<Handler>
462 handleWatchOnlyChanged(WatchOnlyChangedFn fn) override {
463 return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
464 }
465 std::unique_ptr<Handler>
466 handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override {
467 return MakeHandler(
468 m_wallet->NotifyCanGetAddressesChanged.connect(fn));
469 }
470 Amount getRequiredFee(unsigned int tx_bytes) override {
471 return GetRequiredFee(*m_wallet, tx_bytes);
472 }
473 Amount getMinimumFee(unsigned int tx_bytes,
474 const CCoinControl &coin_control) override {
475 return GetMinimumFee(*m_wallet, tx_bytes, coin_control);
476 }
477 CWallet *wallet() override { return m_wallet.get(); }
478
480 std::shared_ptr<CWallet> m_wallet;
481 };
482
483 class WalletClientImpl : public WalletClient {
484 public:
485 WalletClientImpl(Chain &chain, ArgsManager &args) {
486 m_context.chain = &chain;
487 m_context.args = &args;
488 }
489 ~WalletClientImpl() override { UnloadWallets(m_context); }
490
492 void registerRpcs(const Span<const CRPCCommand> &commands) {
493 for (const CRPCCommand &command : commands) {
494 m_rpc_commands.emplace_back(
495 command.category, command.name,
496 [this, &command](const Config &config,
497 const JSONRPCRequest &request,
498 UniValue &result, bool last_handler) {
499 JSONRPCRequest wallet_request = request;
500 wallet_request.context = &m_context;
501 return command.actor(config, wallet_request, result,
502 last_handler);
503 },
504 command.argNames, command.unique_id);
505 m_rpc_handlers.emplace_back(
506 m_context.chain->handleRpc(m_rpc_commands.back()));
507 }
508 }
509
510 void registerRpcs() override {
511 registerRpcs(GetWalletRPCCommands());
512 registerRpcs(GetWalletDumpRPCCommands());
513 registerRpcs(GetWalletEncryptRPCCommands());
514 }
515 bool verify() override { return VerifyWallets(m_context); }
516 bool load() override { return LoadWallets(m_context); }
517 void start(CScheduler &scheduler) override {
518 return StartWallets(m_context, scheduler);
519 }
520 void flush() override { return FlushWallets(m_context); }
521 void stop() override { return StopWallets(m_context); }
522 void setMockTime(int64_t time) override { return SetMockTime(time); }
523
526 createWallet(const std::string &name, const SecureString &passphrase,
527 uint64_t wallet_creation_flags,
528 std::vector<bilingual_str> &warnings) override {
529 DatabaseOptions options;
530 DatabaseStatus status;
531 options.require_create = true;
532 options.create_flags = wallet_creation_flags;
533 options.create_passphrase = passphrase;
535 std::unique_ptr<Wallet> wallet{MakeWallet(
536 m_context, CreateWallet(m_context, name, /*load_on_start=*/true,
537 options, status, error, warnings))};
538 if (wallet) {
539 // std::move should be unneccessary but is temporarily needed to
540 // work around clang bug
541 // (https://github.com/bitcoin/bitcoin/pull/25977#issuecomment-1564350880)
542 return {std::move(wallet)};
543 }
544 return util::Error{error};
545 }
547 loadWallet(const std::string &name,
548 std::vector<bilingual_str> &warnings) override {
549 DatabaseOptions options;
550 DatabaseStatus status;
551 options.require_existing = true;
553 std::unique_ptr<Wallet> wallet{MakeWallet(
554 m_context, CreateWallet(m_context, name, /*load_on_start=*/true,
555 options, status, error, warnings))};
556 if (wallet) {
557 // std::move should be unneccessary but is temporarily needed to
558 // work around clang bug
559 // (https://github.com/bitcoin/bitcoin/pull/25977#issuecomment-1564350880)
560 return {std::move(wallet)};
561 }
562 return util::Error{error};
563 }
565 restoreWallet(const fs::path &backup_file,
566 const std::string &wallet_name,
567 std::vector<bilingual_str> &warnings) override {
568 DatabaseStatus status;
570 std::unique_ptr<Wallet> wallet{MakeWallet(
571 m_context, RestoreWallet(m_context, backup_file, wallet_name,
572 /*load_on_start=*/true, status, error,
573 warnings))};
574 if (wallet) {
575 // std::move should be unneccessary but is temporarily needed to
576 // work around clang bug
577 // (https://github.com/bitcoin/bitcoin/pull/25977#issuecomment-1564350880)
578 return {std::move(wallet)};
579 }
580 return util::Error{error};
581 }
582 std::string getWalletDir() override {
584 }
585 std::vector<std::string> listWalletDir() override {
586 std::vector<std::string> paths;
587 for (auto &path : ListWalletDir()) {
588 paths.push_back(fs::PathToString(path));
589 }
590 return paths;
591 }
592
593 std::vector<std::unique_ptr<Wallet>> getWallets() override {
594 std::vector<std::unique_ptr<Wallet>> wallets;
595 for (const auto &wallet : GetWallets(m_context)) {
596 wallets.emplace_back(MakeWallet(m_context, wallet));
597 }
598 return wallets;
599 }
600
601 std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override {
602 return HandleLoadWallet(m_context, std::move(fn));
603 }
604 WalletContext *context() override { return &m_context; }
605
607 const std::vector<std::string> m_wallet_filenames;
608 std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
609 std::list<CRPCCommand> m_rpc_commands;
610 };
611} // namespace
612} // namespace wallet
613
614namespace interfaces {
615std::unique_ptr<Wallet> MakeWallet(WalletContext &context,
616 const std::shared_ptr<CWallet> &wallet) {
617 return wallet ? std::make_unique<wallet::WalletImpl>(context, wallet)
618 : nullptr;
619}
620
621std::unique_ptr<WalletClient> MakeWalletClient(Chain &chain,
622 ArgsManager &args) {
623 return std::make_unique<wallet::WalletClientImpl>(chain, args);
624}
625} // namespace interfaces
Span< const CRPCCommand > GetWalletDumpRPCCommands()
Definition: backup.cpp:2504
#define CHECK_NONFATAL(condition)
Identity function.
Definition: check.h:53
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:86
Coin Control Features.
Definition: coincontrol.h:21
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
An encapsulated public key.
Definition: pubkey.h:31
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:41
An output of a transaction.
Definition: transaction.h:128
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:269
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:65
bool isAbandoned() const
Definition: transaction.h:279
mapValue_t mapValue
Key/value map with information about the transaction.
Definition: transaction.h:99
CTransactionRef tx
Definition: transaction.h:160
Confirmation m_confirm
Definition: transaction.h:191
TxId GetId() const
Definition: transaction.h:300
int64_t GetTxTime() const
Definition: transaction.cpp:25
bool IsCoinBase() const
Definition: transaction.h:301
unsigned int nTimeReceived
time received by this node
Definition: transaction.h:103
Definition: config.h:19
Signature hash type wrapper class.
Definition: sighashtype.h:37
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:93
Access to the wallet database.
Definition: walletdb.h:176
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:136
Helper for findBlock to selectively return pieces of block data.
Definition: chain.h:55
Generic interface for managing an event handler or callback function registered with another interfac...
Definition: handler.h:22
Wallet chain client that in addition to having chain client methods for starting up,...
Definition: wallet.h:303
Interface for accessing a wallet.
Definition: wallet.h:60
Span< const CRPCCommand > GetWalletEncryptRPCCommands()
Definition: encrypt.cpp:322
TransactionError
Definition: error.h:22
uint8_t isminefilter
Definition: wallet.h:43
isminetype
IsMine() return codes.
Definition: ismine.h:18
@ ISMINE_ALL
Definition: ismine.h:23
@ ISMINE_SPENDABLE
Definition: ismine.h:21
@ ISMINE_NO
Definition: ismine.h:19
void FlushWallets(WalletContext &context)
Flush all wallets in preparation for shutdown.
Definition: load.cpp:177
void StopWallets(WalletContext &context)
Stop all wallets. Wallets will be flushed first.
Definition: load.cpp:183
void StartWallets(WalletContext &context, CScheduler &scheduler)
Complete startup of wallets.
Definition: load.cpp:155
bool LoadWallets(WalletContext &context)
Load wallet databases.
Definition: load.cpp:109
bool VerifyWallets(WalletContext &context)
Responsible for reading and validating the -wallet arguments and verifying.
Definition: load.cpp:24
void UnloadWallets(WalletContext &context)
Close all wallets.
Definition: load.cpp:189
bool error(const char *fmt, const Args &...args)
Definition: logging.h:263
SigningResult
Definition: message.h:47
static std::string PathToString(const path &path)
Convert path object to byte string.
Definition: fs.h:142
std::unique_ptr< Wallet > MakeWallet(const std::shared_ptr< CWallet > &wallet)
Definition: dummywallet.cpp:44
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
Definition: handler.cpp:48
std::vector< std::pair< std::string, std::string > > WalletOrderForm
Definition: wallet.h:56
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
Definition: interfaces.cpp:621
std::map< std::string, std::string > WalletValueMap
Definition: wallet.h:57
bilingual_str ErrorString(const Result< T > &result)
Definition: result.h:90
NodeContext * m_context
Definition: interfaces.cpp:387
OutputType
Definition: outputtype.h:16
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
Amount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
Definition: receive.cpp:183
Amount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
Definition: receive.cpp:164
Amount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
Definition: receive.cpp:51
Amount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
Definition: receive.cpp:139
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< TxId > &trusted_parents)
Definition: receive.cpp:326
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
Definition: receive.cpp:384
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
Definition: receive.cpp:11
const char * prefix
Definition: rest.cpp:817
const char * name
Definition: rest.cpp:47
Span< const CRPCCommand > GetWalletRPCCommands()
Definition: rpcwallet.cpp:4937
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:55
static RPCHelpMan stop()
Definition: server.cpp:211
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
Definition: spend.cpp:252
util::Result< CreatedTransactionResult > CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, int change_pos, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: spend.cpp:991
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
Definition: spend.cpp:217
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:158
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:85
Definition: amount.h:19
Amount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
Definition: receive.h:71
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
bool require_create
Definition: db.h:223
uint64_t create_flags
Definition: db.h:224
bool require_existing
Definition: db.h:222
SecureString create_passphrase
Definition: db.h:225
A version of CTransaction with the PSBT format.
Definition: psbt.h:334
A TxId is the identifier of a transaction.
Definition: txid.h:14
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:35
Bilingual messages:
Definition: translation.h:17
Information about one wallet address.
Definition: wallet.h:341
Collection of wallet balances.
Definition: wallet.h:354
Amount immature_watch_only_balance
Definition: wallet.h:361
Amount unconfirmed_watch_only_balance
Definition: wallet.h:360
std::vector< CTxDestination > txout_address
Definition: wallet.h:379
std::vector< isminetype > txout_is_mine
Definition: wallet.h:378
CTransactionRef tx
Definition: wallet.h:376
std::map< std::string, std::string > value_map
Definition: wallet.h:385
std::vector< isminetype > txout_address_is_mine
Definition: wallet.h:380
std::vector< isminetype > txin_is_mine
Definition: wallet.h:377
Wallet transaction output.
Definition: wallet.h:403
Updated transaction status.
Definition: wallet.h:390
unsigned int time_received
Definition: wallet.h:394
#define LOCK(cs)
Definition: sync.h:306
#define TRY_LOCK(cs, name)
Definition: sync.h:314
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:89
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
AssertLockHeld(pool.cs)
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition: context.h:23
DatabaseStatus
Definition: db.h:229
Amount 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
Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control)
Estimate the minimum fee considering user set parameters and the required fee.
Definition: fees.cpp:17
std::list< CRPCCommand > m_rpc_commands
Definition: interfaces.cpp:609
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:480
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
Definition: interfaces.cpp:608
const std::vector< std::string > m_wallet_filenames
Definition: interfaces.cpp:607
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
Definition: wallet.cpp:168
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:119
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition: wallet.cpp:151
std::shared_ptr< CWallet > RestoreWallet(WalletContext &context, const fs::path &backup_file, const std::string &wallet_name, std::optional< bool > load_on_start, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:397
std::shared_ptr< CWallet > CreateWallet(WalletContext &context, const std::string &name, std::optional< bool > load_on_start, DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:295
fs::path GetWalletDir()
Get the path of the wallet directory.
Definition: walletutil.cpp:13
std::vector< fs::path > ListWalletDir()
Get wallets in wallet directory.
Definition: walletutil.cpp:70
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:55