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