Bitcoin ABC 0.32.12
P2P Digital Currency
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
45
46namespace wallet {
47namespace {
48
50 WalletTx MakeWalletTx(CWallet &wallet, const CWalletTx &wtx) {
51 LOCK(wallet.cs_wallet);
52 WalletTx result;
53 result.tx = wtx.tx;
54 result.txin_is_mine.reserve(wtx.tx->vin.size());
55 for (const auto &txin : wtx.tx->vin) {
56 result.txin_is_mine.emplace_back(InputIsMine(wallet, txin));
57 }
58 result.txout_is_mine.reserve(wtx.tx->vout.size());
59 result.txout_address.reserve(wtx.tx->vout.size());
60 result.txout_address_is_mine.reserve(wtx.tx->vout.size());
61 for (const auto &txout : wtx.tx->vout) {
62 result.txout_is_mine.emplace_back(wallet.IsMine(txout));
63 result.txout_address.emplace_back();
64 result.txout_address_is_mine.emplace_back(
65 ExtractDestination(txout.scriptPubKey,
66 result.txout_address.back())
67 ? wallet.IsMine(result.txout_address.back())
68 : ISMINE_NO);
69 }
72 result.change = CachedTxGetChange(wallet, wtx);
73 result.time = wtx.GetTxTime();
74 result.value_map = wtx.mapValue;
75 result.is_coinbase = wtx.IsCoinBase();
76 return result;
77 }
78
80 WalletTxStatus MakeWalletTxStatus(const CWallet &wallet,
81 const CWalletTx &wtx)
83 AssertLockHeld(wallet.cs_wallet);
84
85 WalletTxStatus result;
86 result.block_height = wtx.m_confirm.block_height > 0
88 : std::numeric_limits<int>::max();
89 result.blocks_to_maturity = wallet.GetTxBlocksToMaturity(wtx);
90 result.depth_in_main_chain = wallet.GetTxDepthInMainChain(wtx);
91 result.time_received = wtx.nTimeReceived;
92 result.lock_time = wtx.tx->nLockTime;
93 result.is_trusted = CachedTxIsTrusted(wallet, wtx);
94 result.is_abandoned = wtx.isAbandoned();
95 result.is_coinbase = wtx.IsCoinBase();
96 result.is_in_main_chain = wallet.IsTxInMainChain(wtx);
97 return result;
98 }
99
101 WalletTxOut MakeWalletTxOut(const CWallet &wallet, const CWalletTx &wtx,
102 int n, int depth)
104 AssertLockHeld(wallet.cs_wallet);
105
106 WalletTxOut result;
107 result.txout = wtx.tx->vout[n];
108 result.time = wtx.GetTxTime();
109 result.depth_in_main_chain = depth;
110 result.is_spent = wallet.IsSpent(COutPoint(wtx.GetId(), n));
111 return result;
112 }
113
114 class WalletImpl : public Wallet {
115 public:
116 explicit WalletImpl(WalletContext &context,
117 const std::shared_ptr<CWallet> &wallet)
118 : m_context(context), m_wallet(wallet) {}
119
120 bool encryptWallet(const SecureString &wallet_passphrase) override {
121 return m_wallet->EncryptWallet(wallet_passphrase);
122 }
123 bool isCrypted() override { return m_wallet->IsCrypted(); }
124 bool lock() override { return m_wallet->Lock(); }
125 bool unlock(const SecureString &wallet_passphrase) override {
126 return m_wallet->Unlock(wallet_passphrase);
127 }
128 bool isLocked() override { return m_wallet->IsLocked(); }
129 bool changeWalletPassphrase(
130 const SecureString &old_wallet_passphrase,
131 const SecureString &new_wallet_passphrase) override {
132 return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase,
133 new_wallet_passphrase);
134 }
135 void abortRescan() override { m_wallet->AbortRescan(); }
136 bool backupWallet(const std::string &filename) override {
137 return m_wallet->BackupWallet(filename);
138 }
139 std::string getWalletName() override { return m_wallet->GetName(); }
141 getNewDestination(const OutputType type,
142 const std::string &label) override {
143 LOCK(m_wallet->cs_wallet);
144 return m_wallet->GetNewDestination(type, label);
145 }
146 const CChainParams &getChainParams() override {
147 return m_wallet->GetChainParams();
148 }
149 bool getPubKey(const CScript &script, const CKeyID &address,
150 CPubKey &pub_key) override {
151 std::unique_ptr<SigningProvider> provider =
152 m_wallet->GetSolvingProvider(script);
153 if (provider) {
154 return provider->GetPubKey(address, pub_key);
155 }
156 return false;
157 }
158 SigningResult signMessage(const std::string &message,
159 const PKHash &pkhash,
160 std::string &str_sig) override {
161 return m_wallet->SignMessage(message, pkhash, str_sig);
162 }
163 bool isSpendable(const CTxDestination &dest) override {
164 LOCK(m_wallet->cs_wallet);
165 return m_wallet->IsMine(dest) & ISMINE_SPENDABLE;
166 }
167 bool haveWatchOnly() override {
168 auto spk_man = m_wallet->GetLegacyScriptPubKeyMan();
169 if (spk_man) {
170 return spk_man->HaveWatchOnly();
171 }
172 return false;
173 };
174 bool setAddressBook(const CTxDestination &dest, const std::string &name,
175 const std::string &purpose) override {
176 return m_wallet->SetAddressBook(dest, name, purpose);
177 }
178 bool delAddressBook(const CTxDestination &dest) override {
179 return m_wallet->DelAddressBook(dest);
180 }
181 bool getAddress(const CTxDestination &dest, std::string *name,
182 isminetype *is_mine, std::string *purpose) override {
183 LOCK(m_wallet->cs_wallet);
184 auto it = m_wallet->m_address_book.find(dest);
185 if (it == m_wallet->m_address_book.end() || it->second.IsChange()) {
186 return false;
187 }
188 if (name) {
189 *name = it->second.GetLabel();
190 }
191 if (is_mine) {
192 *is_mine = m_wallet->IsMine(dest);
193 }
194 if (purpose) {
195 *purpose = it->second.purpose;
196 }
197 return true;
198 }
199 std::vector<WalletAddress> getAddresses() override {
200 LOCK(m_wallet->cs_wallet);
201 std::vector<WalletAddress> result;
202 for (const auto &item : m_wallet->m_address_book) {
203 if (item.second.IsChange()) {
204 continue;
205 }
206 result.emplace_back(item.first, m_wallet->IsMine(item.first),
207 item.second.GetLabel(),
208 item.second.purpose);
209 }
210 return result;
211 }
212 bool addDestData(const CTxDestination &dest, const std::string &key,
213 const std::string &value) override {
214 LOCK(m_wallet->cs_wallet);
215 WalletBatch batch{m_wallet->GetDatabase()};
216 return m_wallet->AddDestData(batch, dest, key, value);
217 }
218 bool eraseDestData(const CTxDestination &dest,
219 const std::string &key) override {
220 LOCK(m_wallet->cs_wallet);
221 WalletBatch batch{m_wallet->GetDatabase()};
222 return m_wallet->EraseDestData(batch, dest, key);
223 }
224 std::vector<std::string>
225 getDestValues(const std::string &prefix) override {
226 LOCK(m_wallet->cs_wallet);
227 return m_wallet->GetDestValues(prefix);
228 }
229 void lockCoin(const COutPoint &output) override {
230 LOCK(m_wallet->cs_wallet);
231 return m_wallet->LockCoin(output);
232 }
233 void unlockCoin(const COutPoint &output) override {
234 LOCK(m_wallet->cs_wallet);
235 return m_wallet->UnlockCoin(output);
236 }
237 bool isLockedCoin(const COutPoint &output) override {
238 LOCK(m_wallet->cs_wallet);
239 return m_wallet->IsLockedCoin(output);
240 }
241 void listLockedCoins(std::vector<COutPoint> &outputs) override {
242 LOCK(m_wallet->cs_wallet);
243 return m_wallet->ListLockedCoins(outputs);
244 }
246 createTransaction(const std::vector<CRecipient> &recipients,
247 const CCoinControl &coin_control, bool sign,
248 int &change_pos, Amount &fee) override {
249 LOCK(m_wallet->cs_wallet);
250 auto res = CreateTransaction(*m_wallet, recipients, change_pos,
251 coin_control, sign);
252 if (!res) {
253 return util::Error{util::ErrorString(res)};
254 }
255 const auto &txr = *res;
256 fee = txr.fee;
257 change_pos = txr.change_pos;
258
259 return txr.tx;
260 }
261 void commitTransaction(CTransactionRef tx, WalletValueMap value_map,
262 WalletOrderForm order_form) override {
263 LOCK(m_wallet->cs_wallet);
264 m_wallet->CommitTransaction(std::move(tx), std::move(value_map),
265 std::move(order_form));
266 }
267 bool transactionCanBeAbandoned(const TxId &txid) override {
268 return m_wallet->TransactionCanBeAbandoned(txid);
269 }
270 bool abandonTransaction(const TxId &txid) override {
271 LOCK(m_wallet->cs_wallet);
272 return m_wallet->AbandonTransaction(txid);
273 }
274 CTransactionRef getTx(const TxId &txid) override {
275 LOCK(m_wallet->cs_wallet);
276 auto mi = m_wallet->mapWallet.find(txid);
277 if (mi != m_wallet->mapWallet.end()) {
278 return mi->second.tx;
279 }
280 return {};
281 }
282 WalletTx getWalletTx(const TxId &txid) override {
283 LOCK(m_wallet->cs_wallet);
284 auto mi = m_wallet->mapWallet.find(txid);
285 if (mi != m_wallet->mapWallet.end()) {
286 return MakeWalletTx(*m_wallet, mi->second);
287 }
288 return {};
289 }
290 std::vector<WalletTx> getWalletTxs() override {
291 LOCK(m_wallet->cs_wallet);
292 std::vector<WalletTx> result;
293 result.reserve(m_wallet->mapWallet.size());
294 for (const auto &entry : m_wallet->mapWallet) {
295 result.emplace_back(MakeWalletTx(*m_wallet, entry.second));
296 }
297 return result;
298 }
299 bool tryGetTxStatus(const TxId &txid,
301 int &num_blocks, int64_t &block_time) override {
302 TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
303 if (!locked_wallet) {
304 return false;
305 }
306 auto mi = m_wallet->mapWallet.find(txid);
307 if (mi == m_wallet->mapWallet.end()) {
308 return false;
309 }
310 num_blocks = m_wallet->GetLastBlockHeight();
311 block_time = -1;
312 CHECK_NONFATAL(m_wallet->chain().findBlock(
313 m_wallet->GetLastBlockHash(), FoundBlock().time(block_time)));
314 tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
315 return true;
316 }
317 WalletTx getWalletTxDetails(const TxId &txid, WalletTxStatus &tx_status,
318 WalletOrderForm &order_form,
319 bool &in_mempool,
320 int &num_blocks) override {
321 LOCK(m_wallet->cs_wallet);
322 auto mi = m_wallet->mapWallet.find(txid);
323 if (mi != m_wallet->mapWallet.end()) {
324 num_blocks = m_wallet->GetLastBlockHeight();
325 in_mempool = mi->second.InMempool();
326 order_form = mi->second.vOrderForm;
327 tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
328 return MakeWalletTx(*m_wallet, mi->second);
329 }
330 return {};
331 }
332 std::optional<PSBTError> fillPSBT(SigHashType sighash_type, bool sign,
333 bool bip32derivs,
335 bool &complete) const override {
336 return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign,
337 bip32derivs);
338 }
339 WalletBalances getBalances() override {
340 const auto bal = GetBalance(*m_wallet);
341 WalletBalances result;
342 result.balance = bal.m_mine_trusted;
343 result.unconfirmed_balance = bal.m_mine_untrusted_pending;
344 result.immature_balance = bal.m_mine_immature;
345 result.have_watch_only = haveWatchOnly();
346 if (result.have_watch_only) {
347 result.watch_only_balance = bal.m_watchonly_trusted;
349 bal.m_watchonly_untrusted_pending;
350 result.immature_watch_only_balance = bal.m_watchonly_immature;
351 }
352 return result;
353 }
354 bool tryGetBalances(WalletBalances &balances,
355 BlockHash &block_hash) override {
356 TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
357 if (!locked_wallet) {
358 return false;
359 }
360 block_hash = m_wallet->GetLastBlockHash();
361 balances = getBalances();
362 return true;
363 }
364 Amount getBalance() override {
365 return GetBalance(*m_wallet).m_mine_trusted;
366 }
367 Amount getAvailableBalance(const CCoinControl &coin_control) override {
368 return GetAvailableBalance(*m_wallet, &coin_control);
369 }
370 isminetype txinIsMine(const CTxIn &txin) override {
371 LOCK(m_wallet->cs_wallet);
372 return InputIsMine(*m_wallet, txin);
373 }
374 isminetype txoutIsMine(const CTxOut &txout) override {
375 LOCK(m_wallet->cs_wallet);
376 return m_wallet->IsMine(txout);
377 }
378 Amount getDebit(const CTxIn &txin, isminefilter filter) override {
379 LOCK(m_wallet->cs_wallet);
380 return m_wallet->GetDebit(txin, filter);
381 }
382 Amount getCredit(const CTxOut &txout, isminefilter filter) override {
383 LOCK(m_wallet->cs_wallet);
384 return OutputGetCredit(*m_wallet, txout, filter);
385 }
386 CoinsList listCoins() override {
387 LOCK(m_wallet->cs_wallet);
388 CoinsList result;
389 for (const auto &entry : ListCoins(*m_wallet)) {
390 auto &group = result[entry.first];
391 for (const auto &coin : entry.second) {
392 group.emplace_back(COutPoint(coin.tx->GetId(), coin.i),
393 MakeWalletTxOut(*m_wallet, *coin.tx,
394 coin.i, coin.nDepth));
395 }
396 }
397 return result;
398 }
399 std::vector<WalletTxOut>
400 getCoins(const std::vector<COutPoint> &outputs) override {
401 LOCK(m_wallet->cs_wallet);
402 std::vector<WalletTxOut> result;
403 result.reserve(outputs.size());
404 for (const auto &output : outputs) {
405 result.emplace_back();
406 auto it = m_wallet->mapWallet.find(output.GetTxId());
407 if (it != m_wallet->mapWallet.end()) {
408 int depth = m_wallet->GetTxDepthInMainChain(it->second);
409 if (depth >= 0) {
410 result.back() = MakeWalletTxOut(*m_wallet, it->second,
411 output.GetN(), depth);
412 }
413 }
414 }
415 return result;
416 }
417 bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
418 OutputType getDefaultAddressType() override {
419 return m_wallet->m_default_address_type;
420 }
421 bool canGetAddresses() const override {
422 return m_wallet->CanGetAddresses();
423 }
424 bool privateKeysDisabled() override {
425 return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
426 }
427 Amount getDefaultMaxTxFee() override {
428 return m_wallet->m_default_max_tx_fee;
429 }
430 void remove() override {
431 RemoveWallet(m_context, m_wallet, false /* load_on_start */);
432 }
433 bool isLegacy() override { return m_wallet->IsLegacy(); }
434 std::unique_ptr<Handler> handleUnload(UnloadFn fn) override {
435 return MakeHandler(m_wallet->NotifyUnload.connect(fn));
436 }
437 std::unique_ptr<Handler>
438 handleShowProgress(ShowProgressFn fn) override {
439 return MakeHandler(m_wallet->ShowProgress.connect(fn));
440 }
441 std::unique_ptr<Handler>
442 handleStatusChanged(StatusChangedFn fn) override {
443 return MakeHandler(m_wallet->NotifyStatusChanged.connect(
444 [fn](CWallet *) { fn(); }));
445 }
446 std::unique_ptr<Handler>
447 handleAddressBookChanged(AddressBookChangedFn fn) override {
448 return MakeHandler(m_wallet->NotifyAddressBookChanged.connect(
449 [fn](CWallet *, const CTxDestination &address,
450 const std::string &label, bool is_mine,
451 const std::string &purpose, ChangeType status) {
452 fn(address, label, is_mine, purpose, status);
453 }));
454 }
455 std::unique_ptr<Handler>
456 handleTransactionChanged(TransactionChangedFn fn) override {
457 return MakeHandler(m_wallet->NotifyTransactionChanged.connect(
458 [fn](CWallet *, const TxId &txid, ChangeType status) {
459 fn(txid, status);
460 }));
461 }
462 std::unique_ptr<Handler>
463 handleWatchOnlyChanged(WatchOnlyChangedFn fn) override {
464 return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
465 }
466 std::unique_ptr<Handler>
467 handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override {
468 return MakeHandler(
469 m_wallet->NotifyCanGetAddressesChanged.connect(fn));
470 }
471 Amount getRequiredFee(unsigned int tx_bytes) override {
472 return GetRequiredFee(*m_wallet, tx_bytes);
473 }
474 Amount getMinimumFee(unsigned int tx_bytes,
475 const CCoinControl &coin_control) override {
476 return GetMinimumFee(*m_wallet, tx_bytes, coin_control);
477 }
478 CWallet *wallet() override { return m_wallet.get(); }
479
481 std::shared_ptr<CWallet> m_wallet;
482 };
483
484 class WalletClientImpl : public WalletClient {
485 public:
486 WalletClientImpl(Chain &chain, ArgsManager &args) {
487 m_context.chain = &chain;
488 m_context.args = &args;
489 }
490 ~WalletClientImpl() override { UnloadWallets(m_context); }
491
493 void registerRpcs(const Span<const CRPCCommand> &commands) {
494 for (const CRPCCommand &command : commands) {
495 m_rpc_commands.emplace_back(
496 command.category, command.name,
497 [this, &command](const Config &config,
498 const JSONRPCRequest &request,
499 UniValue &result, bool last_handler) {
500 JSONRPCRequest wallet_request = request;
501 wallet_request.context = &m_context;
502 return command.actor(config, wallet_request, result,
503 last_handler);
504 },
505 command.argNames, command.unique_id);
506 m_rpc_handlers.emplace_back(
507 m_context.chain->handleRpc(m_rpc_commands.back()));
508 }
509 }
510
511 void registerRpcs() override {
512 registerRpcs(GetWalletRPCCommands());
513 registerRpcs(GetWalletDumpRPCCommands());
514 registerRpcs(GetWalletEncryptRPCCommands());
515 }
516 bool verify() override { return VerifyWallets(m_context); }
517 bool load() override { return LoadWallets(m_context); }
518 void start(CScheduler &scheduler) override {
519 return StartWallets(m_context, scheduler);
520 }
521 void flush() override { return FlushWallets(m_context); }
522 void stop() override { return StopWallets(m_context); }
523 void setMockTime(int64_t time) override { return SetMockTime(time); }
524
527 createWallet(const std::string &name, const SecureString &passphrase,
528 uint64_t wallet_creation_flags,
529 std::vector<bilingual_str> &warnings) override {
530 DatabaseOptions options;
531 DatabaseStatus status;
532 options.require_create = true;
533 options.create_flags = wallet_creation_flags;
534 options.create_passphrase = passphrase;
535 bilingual_str error;
536 std::unique_ptr<Wallet> wallet{MakeWallet(
537 m_context, CreateWallet(m_context, name, /*load_on_start=*/true,
538 options, status, error, warnings))};
539 if (wallet) {
540 // std::move should be unneccessary but is temporarily needed to
541 // work around clang bug
542 // (https://github.com/bitcoin/bitcoin/pull/25977#issuecomment-1564350880)
543 return {std::move(wallet)};
544 }
545 return util::Error{error};
546 }
548 loadWallet(const std::string &name,
549 std::vector<bilingual_str> &warnings) override {
550 DatabaseOptions options;
551 DatabaseStatus status;
552 options.require_existing = true;
553 bilingual_str error;
554 std::unique_ptr<Wallet> wallet{MakeWallet(
555 m_context, CreateWallet(m_context, name, /*load_on_start=*/true,
556 options, status, error, warnings))};
557 if (wallet) {
558 // std::move should be unneccessary but is temporarily needed to
559 // work around clang bug
560 // (https://github.com/bitcoin/bitcoin/pull/25977#issuecomment-1564350880)
561 return {std::move(wallet)};
562 }
563 return util::Error{error};
564 }
566 restoreWallet(const fs::path &backup_file,
567 const std::string &wallet_name,
568 std::vector<bilingual_str> &warnings) override {
569 DatabaseStatus status;
570 bilingual_str error;
571 std::unique_ptr<Wallet> wallet{MakeWallet(
572 m_context, RestoreWallet(m_context, backup_file, wallet_name,
573 /*load_on_start=*/true, status, error,
574 warnings))};
575 if (wallet) {
576 // std::move should be unneccessary but is temporarily needed to
577 // work around clang bug
578 // (https://github.com/bitcoin/bitcoin/pull/25977#issuecomment-1564350880)
579 return {std::move(wallet)};
580 }
581 return util::Error{error};
582 }
583 std::string getWalletDir() override {
585 }
586 std::vector<std::string> listWalletDir() override {
587 std::vector<std::string> paths;
588 for (auto &path : ListWalletDir()) {
589 paths.push_back(fs::PathToString(path));
590 }
591 return paths;
592 }
593
594 std::vector<std::unique_ptr<Wallet>> getWallets() override {
595 std::vector<std::unique_ptr<Wallet>> wallets;
596 for (const auto &wallet : GetWallets(m_context)) {
597 wallets.emplace_back(MakeWallet(m_context, wallet));
598 }
599 return wallets;
600 }
601
602 std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override {
603 return HandleLoadWallet(m_context, std::move(fn));
604 }
605 WalletContext *context() override { return &m_context; }
606
608 const std::vector<std::string> m_wallet_filenames;
609 std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
610 std::list<CRPCCommand> m_rpc_commands;
611 };
612} // namespace
613} // namespace wallet
614
615namespace interfaces {
616std::unique_ptr<Wallet> MakeWallet(WalletContext &context,
617 const std::shared_ptr<CWallet> &wallet) {
618 return wallet ? std::make_unique<wallet::WalletImpl>(context, wallet)
619 : nullptr;
620}
621
622std::unique_ptr<WalletClient> MakeWalletClient(Chain &chain,
623 ArgsManager &args) {
624 return std::make_unique<wallet::WalletClientImpl>(chain, args);
625}
626} // namespace interfaces
Span< const CRPCCommand > GetWalletDumpRPCCommands()
Definition: backup.cpp:2508
#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:272
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:65
bool isAbandoned() const
Definition: transaction.h:280
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:301
int64_t GetTxTime() const
Definition: transaction.cpp:25
bool IsCoinBase() const
Definition: transaction.h:302
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:94
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:304
Interface for accessing a wallet.
Definition: wallet.h:62
Span< const CRPCCommand > GetWalletEncryptRPCCommands()
Definition: encrypt.cpp:322
uint8_t isminefilter
Definition: wallet.h:45
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:179
void StopWallets(WalletContext &context)
Stop all wallets. Wallets will be flushed first.
Definition: load.cpp:185
void StartWallets(WalletContext &context, CScheduler &scheduler)
Complete startup of wallets.
Definition: load.cpp:157
bool LoadWallets(WalletContext &context)
Load wallet databases.
Definition: load.cpp:111
bool VerifyWallets(WalletContext &context)
Responsible for reading and validating the -wallet arguments and verifying.
Definition: load.cpp:26
void UnloadWallets(WalletContext &context)
Close all wallets.
Definition: load.cpp:191
PSBTError
Definition: types.h:17
static std::string PathToString(const path &path)
Convert path object to byte string.
Definition: fs.h:147
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:58
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
Definition: interfaces.cpp:622
std::map< std::string, std::string > WalletValueMap
Definition: wallet.h:59
bilingual_str ErrorString(const Result< T > &result)
Definition: result.h:90
NodeContext * m_context
Definition: interfaces.cpp:396
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:813
const char * name
Definition: rest.cpp:47
Span< const CRPCCommand > GetWalletRPCCommands()
Definition: rpcwallet.cpp:4922
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:55
static RPCHelpMan stop()
Definition: server.cpp:214
SigningResult
Definition: signmessage.h:47
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:255
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:995
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
Definition: spend.cpp:220
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:21
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:221
uint64_t create_flags
Definition: db.h:222
bool require_existing
Definition: db.h:220
SecureString create_passphrase
Definition: db.h:223
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:342
Collection of wallet balances.
Definition: wallet.h:355
Amount immature_watch_only_balance
Definition: wallet.h:362
Amount unconfirmed_watch_only_balance
Definition: wallet.h:361
std::vector< CTxDestination > txout_address
Definition: wallet.h:380
std::vector< isminetype > txout_is_mine
Definition: wallet.h:379
CTransactionRef tx
Definition: wallet.h:377
std::map< std::string, std::string > value_map
Definition: wallet.h:386
std::vector< isminetype > txout_address_is_mine
Definition: wallet.h:381
std::vector< isminetype > txin_is_mine
Definition: wallet.h:378
Wallet transaction output.
Definition: wallet.h:404
Updated transaction status.
Definition: wallet.h:391
unsigned int time_received
Definition: wallet.h:395
#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:46
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:227
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:610
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:481
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
Definition: interfaces.cpp:609
const std::vector< std::string > m_wallet_filenames
Definition: interfaces.cpp:608
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
Definition: wallet.cpp:173
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:124
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition: wallet.cpp:156
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:402
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:300
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