Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
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
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
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(const std::shared_ptr<CWallet> &wallet)
116 : m_wallet(wallet) {}
117
118 bool encryptWallet(const SecureString &wallet_passphrase) override {
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 {
124 return m_wallet->Unlock(wallet_passphrase);
125 }
126 bool isLocked() override { return m_wallet->IsLocked(); }
127 bool changeWalletPassphrase(
129 const SecureString &new_wallet_passphrase) override {
130 return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase,
132 }
133 void abortRescan() override { m_wallet->AbortRescan(); }
134 bool backupWallet(const std::string &filename) override {
135 return m_wallet->BackupWallet(filename);
136 }
137 std::string getWalletName() override { return m_wallet->GetName(); }
138 bool getNewDestination(const OutputType type, const std::string label,
139 CTxDestination &dest) override {
140 LOCK(m_wallet->cs_wallet);
141 std::string error;
142 return m_wallet->GetNewDestination(type, label, dest, error);
143 }
144 const CChainParams &getChainParams() override {
145 return m_wallet->GetChainParams();
146 }
147 bool getPubKey(const CScript &script, const CKeyID &address,
148 CPubKey &pub_key) override {
149 std::unique_ptr<SigningProvider> provider =
150 m_wallet->GetSolvingProvider(script);
151 if (provider) {
152 return provider->GetPubKey(address, pub_key);
153 }
154 return false;
155 }
156 SigningResult signMessage(const std::string &message,
157 const PKHash &pkhash,
158 std::string &str_sig) override {
159 return m_wallet->SignMessage(message, pkhash, str_sig);
160 }
161 bool isSpendable(const CTxDestination &dest) override {
162 LOCK(m_wallet->cs_wallet);
163 return m_wallet->IsMine(dest) & ISMINE_SPENDABLE;
164 }
165 bool haveWatchOnly() override {
166 auto spk_man = m_wallet->GetLegacyScriptPubKeyMan();
167 if (spk_man) {
168 return spk_man->HaveWatchOnly();
169 }
170 return false;
171 };
172 bool setAddressBook(const CTxDestination &dest, const std::string &name,
173 const std::string &purpose) override {
174 return m_wallet->SetAddressBook(dest, name, purpose);
175 }
176 bool delAddressBook(const CTxDestination &dest) override {
177 return m_wallet->DelAddressBook(dest);
178 }
179 bool getAddress(const CTxDestination &dest, std::string *name,
180 isminetype *is_mine, std::string *purpose) override {
181 LOCK(m_wallet->cs_wallet);
182 auto it = m_wallet->m_address_book.find(dest);
183 if (it == m_wallet->m_address_book.end() || it->second.IsChange()) {
184 return false;
185 }
186 if (name) {
187 *name = it->second.GetLabel();
188 }
189 if (is_mine) {
190 *is_mine = m_wallet->IsMine(dest);
191 }
192 if (purpose) {
193 *purpose = it->second.purpose;
194 }
195 return true;
196 }
197 std::vector<WalletAddress> getAddresses() override {
198 LOCK(m_wallet->cs_wallet);
199 std::vector<WalletAddress> result;
200 for (const auto &item : m_wallet->m_address_book) {
201 if (item.second.IsChange()) {
202 continue;
203 }
204 result.emplace_back(item.first, m_wallet->IsMine(item.first),
205 item.second.GetLabel(),
206 item.second.purpose);
207 }
208 return result;
209 }
210 bool addDestData(const CTxDestination &dest, const std::string &key,
211 const std::string &value) override {
212 LOCK(m_wallet->cs_wallet);
213 WalletBatch batch{m_wallet->GetDatabase()};
214 return m_wallet->AddDestData(batch, dest, key, value);
215 }
216 bool eraseDestData(const CTxDestination &dest,
217 const std::string &key) override {
218 LOCK(m_wallet->cs_wallet);
219 WalletBatch batch{m_wallet->GetDatabase()};
220 return m_wallet->EraseDestData(batch, dest, key);
221 }
222 std::vector<std::string>
223 getDestValues(const std::string &prefix) override {
224 LOCK(m_wallet->cs_wallet);
225 return m_wallet->GetDestValues(prefix);
226 }
227 void lockCoin(const COutPoint &output) override {
228 LOCK(m_wallet->cs_wallet);
229 return m_wallet->LockCoin(output);
230 }
231 void unlockCoin(const COutPoint &output) override {
232 LOCK(m_wallet->cs_wallet);
233 return m_wallet->UnlockCoin(output);
234 }
235 bool isLockedCoin(const COutPoint &output) override {
236 LOCK(m_wallet->cs_wallet);
237 return m_wallet->IsLockedCoin(output);
238 }
239 void listLockedCoins(std::vector<COutPoint> &outputs) override {
240 LOCK(m_wallet->cs_wallet);
241 return m_wallet->ListLockedCoins(outputs);
242 }
244 createTransaction(const std::vector<CRecipient> &recipients,
245 const CCoinControl &coin_control, bool sign,
246 int &change_pos, Amount &fee,
247 bilingual_str &fail_reason) override {
248 LOCK(m_wallet->cs_wallet);
250 if (!CreateTransaction(*m_wallet, recipients, tx, fee, change_pos,
251 fail_reason, coin_control, sign)) {
252 return {};
253 }
254 return tx;
255 }
256 void commitTransaction(CTransactionRef tx, WalletValueMap value_map,
257 WalletOrderForm order_form) override {
258 LOCK(m_wallet->cs_wallet);
259 m_wallet->CommitTransaction(std::move(tx), std::move(value_map),
260 std::move(order_form));
261 }
262 bool transactionCanBeAbandoned(const TxId &txid) override {
263 return m_wallet->TransactionCanBeAbandoned(txid);
264 }
265 bool abandonTransaction(const TxId &txid) override {
266 LOCK(m_wallet->cs_wallet);
267 return m_wallet->AbandonTransaction(txid);
268 }
269 CTransactionRef getTx(const TxId &txid) override {
270 LOCK(m_wallet->cs_wallet);
271 auto mi = m_wallet->mapWallet.find(txid);
272 if (mi != m_wallet->mapWallet.end()) {
273 return mi->second.tx;
274 }
275 return {};
276 }
277 WalletTx getWalletTx(const TxId &txid) override {
278 LOCK(m_wallet->cs_wallet);
279 auto mi = m_wallet->mapWallet.find(txid);
280 if (mi != m_wallet->mapWallet.end()) {
281 return MakeWalletTx(*m_wallet, mi->second);
282 }
283 return {};
284 }
285 std::vector<WalletTx> getWalletTxs() override {
286 LOCK(m_wallet->cs_wallet);
287 std::vector<WalletTx> result;
288 result.reserve(m_wallet->mapWallet.size());
289 for (const auto &entry : m_wallet->mapWallet) {
290 result.emplace_back(MakeWalletTx(*m_wallet, entry.second));
291 }
292 return result;
293 }
294 bool tryGetTxStatus(const TxId &txid,
296 int &num_blocks, int64_t &block_time) override {
297 TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
298 if (!locked_wallet) {
299 return false;
300 }
301 auto mi = m_wallet->mapWallet.find(txid);
302 if (mi == m_wallet->mapWallet.end()) {
303 return false;
304 }
305 num_blocks = m_wallet->GetLastBlockHeight();
306 block_time = -1;
307 CHECK_NONFATAL(m_wallet->chain().findBlock(
308 m_wallet->GetLastBlockHash(), FoundBlock().time(block_time)));
310 return true;
311 }
312 WalletTx getWalletTxDetails(const TxId &txid, WalletTxStatus &tx_status,
313 WalletOrderForm &order_form,
314 bool &in_mempool,
315 int &num_blocks) override {
316 LOCK(m_wallet->cs_wallet);
317 auto mi = m_wallet->mapWallet.find(txid);
318 if (mi != m_wallet->mapWallet.end()) {
319 num_blocks = m_wallet->GetLastBlockHeight();
320 in_mempool = mi->second.InMempool();
321 order_form = mi->second.vOrderForm;
323 return MakeWalletTx(*m_wallet, mi->second);
324 }
325 return {};
326 }
327 TransactionError fillPSBT(SigHashType sighash_type, bool sign,
328 bool bip32derivs,
330 bool &complete) const override {
331 return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign,
333 }
334 WalletBalances getBalances() override {
335 const auto bal = GetBalance(*m_wallet);
336 WalletBalances result;
337 result.balance = bal.m_mine_trusted;
338 result.unconfirmed_balance = bal.m_mine_untrusted_pending;
339 result.immature_balance = bal.m_mine_immature;
340 result.have_watch_only = haveWatchOnly();
341 if (result.have_watch_only) {
342 result.watch_only_balance = bal.m_watchonly_trusted;
344 bal.m_watchonly_untrusted_pending;
345 result.immature_watch_only_balance = bal.m_watchonly_immature;
346 }
347 return result;
348 }
349 bool tryGetBalances(WalletBalances &balances,
350 BlockHash &block_hash) override {
351 TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
352 if (!locked_wallet) {
353 return false;
354 }
355 block_hash = m_wallet->GetLastBlockHash();
356 balances = getBalances();
357 return true;
358 }
359 Amount getBalance() override {
360 return GetBalance(*m_wallet).m_mine_trusted;
361 }
362 Amount getAvailableBalance(const CCoinControl &coin_control) override {
364 }
365 isminetype txinIsMine(const CTxIn &txin) override {
366 LOCK(m_wallet->cs_wallet);
367 return InputIsMine(*m_wallet, txin);
368 }
369 isminetype txoutIsMine(const CTxOut &txout) override {
370 LOCK(m_wallet->cs_wallet);
371 return m_wallet->IsMine(txout);
372 }
373 Amount getDebit(const CTxIn &txin, isminefilter filter) override {
374 LOCK(m_wallet->cs_wallet);
375 return m_wallet->GetDebit(txin, filter);
376 }
377 Amount getCredit(const CTxOut &txout, isminefilter filter) override {
378 LOCK(m_wallet->cs_wallet);
379 return OutputGetCredit(*m_wallet, txout, filter);
380 }
381 CoinsList listCoins() override {
382 LOCK(m_wallet->cs_wallet);
383 CoinsList result;
384 for (const auto &entry : ListCoins(*m_wallet)) {
385 auto &group = result[entry.first];
386 for (const auto &coin : entry.second) {
387 group.emplace_back(COutPoint(coin.tx->GetId(), coin.i),
388 MakeWalletTxOut(*m_wallet, *coin.tx,
389 coin.i, coin.nDepth));
390 }
391 }
392 return result;
393 }
394 std::vector<WalletTxOut>
395 getCoins(const std::vector<COutPoint> &outputs) override {
396 LOCK(m_wallet->cs_wallet);
397 std::vector<WalletTxOut> result;
398 result.reserve(outputs.size());
399 for (const auto &output : outputs) {
400 result.emplace_back();
401 auto it = m_wallet->mapWallet.find(output.GetTxId());
402 if (it != m_wallet->mapWallet.end()) {
403 int depth = m_wallet->GetTxDepthInMainChain(it->second);
404 if (depth >= 0) {
405 result.back() = MakeWalletTxOut(*m_wallet, it->second,
406 output.GetN(), depth);
407 }
408 }
409 }
410 return result;
411 }
412 bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
413 OutputType getDefaultAddressType() override {
414 return m_wallet->m_default_address_type;
415 }
416 bool canGetAddresses() const override {
417 return m_wallet->CanGetAddresses();
418 }
419 bool privateKeysDisabled() override {
420 return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
421 }
422 Amount getDefaultMaxTxFee() override {
423 return m_wallet->m_default_max_tx_fee;
424 }
425 void remove() override {
426 RemoveWallet(m_wallet, false /* load_on_start */);
427 }
428 bool isLegacy() override { return m_wallet->IsLegacy(); }
429 std::unique_ptr<Handler> handleUnload(UnloadFn fn) override {
430 return MakeHandler(m_wallet->NotifyUnload.connect(fn));
431 }
432 std::unique_ptr<Handler>
433 handleShowProgress(ShowProgressFn fn) override {
434 return MakeHandler(m_wallet->ShowProgress.connect(fn));
435 }
436 std::unique_ptr<Handler>
437 handleStatusChanged(StatusChangedFn fn) override {
438 return MakeHandler(m_wallet->NotifyStatusChanged.connect(
439 [fn](CWallet *) { fn(); }));
440 }
441 std::unique_ptr<Handler>
442 handleAddressBookChanged(AddressBookChangedFn fn) override {
443 return MakeHandler(m_wallet->NotifyAddressBookChanged.connect(
444 [fn](CWallet *, const CTxDestination &address,
445 const std::string &label, bool is_mine,
446 const std::string &purpose, ChangeType status) {
447 fn(address, label, is_mine, purpose, status);
448 }));
449 }
450 std::unique_ptr<Handler>
451 handleTransactionChanged(TransactionChangedFn fn) override {
452 return MakeHandler(m_wallet->NotifyTransactionChanged.connect(
453 [fn](CWallet *, const TxId &txid, ChangeType status) {
454 fn(txid, status);
455 }));
456 }
457 std::unique_ptr<Handler>
458 handleWatchOnlyChanged(WatchOnlyChangedFn fn) override {
459 return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
460 }
461 std::unique_ptr<Handler>
462 handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override {
463 return MakeHandler(
464 m_wallet->NotifyCanGetAddressesChanged.connect(fn));
465 }
466 Amount getRequiredFee(unsigned int tx_bytes) override {
468 }
469 Amount getMinimumFee(unsigned int tx_bytes,
470 const CCoinControl &coin_control) override {
472 }
473 CWallet *wallet() override { return m_wallet.get(); }
474
475 std::shared_ptr<CWallet> m_wallet;
476 };
477
478 class WalletClientImpl : public WalletClient {
479 public:
480 WalletClientImpl(Chain &chain, ArgsManager &args) {
481 m_context.chain = &chain;
482 m_context.args = &args;
483 }
484 ~WalletClientImpl() override { UnloadWallets(); }
485
487 void registerRpcs(const Span<const CRPCCommand> &commands) {
488 for (const CRPCCommand &command : commands) {
489 m_rpc_commands.emplace_back(
490 command.category, command.name,
491 [this, &command](const Config &config,
492 const JSONRPCRequest &request,
493 UniValue &result, bool last_handler) {
494 JSONRPCRequest wallet_request = request;
495 wallet_request.context = &m_context;
496 return command.actor(config, wallet_request, result,
497 last_handler);
498 },
499 command.argNames, command.unique_id);
500 m_rpc_handlers.emplace_back(
501 m_context.chain->handleRpc(m_rpc_commands.back()));
502 }
503 }
504
505 void registerRpcs() override {
506 registerRpcs(GetWalletRPCCommands());
507 registerRpcs(GetWalletDumpRPCCommands());
508 registerRpcs(GetWalletEncryptRPCCommands());
509 }
510 bool verify() override { return VerifyWallets(*m_context.chain); }
511 bool load() override { return LoadWallets(*m_context.chain); }
512 void start(CScheduler &scheduler) override {
513 return StartWallets(scheduler, *Assert(m_context.args));
514 }
515 void flush() override { return FlushWallets(); }
516 void stop() override { return StopWallets(); }
517 void setMockTime(int64_t time) override { return SetMockTime(time); }
518
520 std::unique_ptr<Wallet>
521 createWallet(const std::string &name, const SecureString &passphrase,
523 std::vector<bilingual_str> &warnings) override {
524 std::shared_ptr<CWallet> wallet;
525 DatabaseOptions options;
526 DatabaseStatus status;
527 options.require_create = true;
530
531 return MakeWallet(CreateWallet(*m_context.chain, name,
532 true /* load_on_start */, options,
533 status, error, warnings));
534 }
535 std::unique_ptr<Wallet>
536 loadWallet(const std::string &name, bilingual_str &error,
537 std::vector<bilingual_str> &warnings) override {
538 DatabaseOptions options;
539 DatabaseStatus status;
540 options.require_existing = true;
541 return MakeWallet(LoadWallet(*m_context.chain, name,
542 true /* load_on_start */, options,
543 status, error, warnings));
544 }
545 std::string getWalletDir() override {
547 }
548 std::vector<std::string> listWalletDir() override {
549 std::vector<std::string> paths;
550 for (auto &path : ListWalletDir()) {
551 paths.push_back(fs::PathToString(path));
552 }
553 return paths;
554 }
555
556 std::vector<std::unique_ptr<Wallet>> getWallets() override {
557 std::vector<std::unique_ptr<Wallet>> wallets;
558 for (const auto &wallet : GetWallets()) {
559 wallets.emplace_back(MakeWallet(wallet));
560 }
561 return wallets;
562 }
563
564 std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override {
565 return HandleLoadWallet(std::move(fn));
566 }
567
569 const std::vector<std::string> m_wallet_filenames;
570 std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
571 std::list<CRPCCommand> m_rpc_commands;
572 };
573} // namespace
574} // namespace wallet
575
576namespace interfaces {
577std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet> &wallet) {
578 return wallet ? std::make_unique<wallet::WalletImpl>(wallet) : nullptr;
579}
580
581std::unique_ptr<WalletClient> MakeWalletClient(Chain &chain,
582 ArgsManager &args) {
583 return std::make_unique<wallet::WalletClientImpl>(chain, args);
584}
585} // namespace interfaces
Span< const CRPCCommand > GetWalletDumpRPCCommands()
Definition backup.cpp:2480
#define CHECK_NONFATAL(condition)
Identity function.
Definition check.h:53
#define Assert(val)
Identity function.
Definition check.h:84
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition chainparams.h:80
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.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition wallet.h:254
A transaction with a bunch of additional info that only the owner cares about.
Definition transaction.h:65
bool isAbandoned() const
mapValue_t mapValue
Key/value map with information about the transaction.
Definition transaction.h:99
CTransactionRef tx
Confirmation m_confirm
TxId GetId() const
int64_t GetTxTime() const
bool IsCoinBase() const
unsigned int nTimeReceived
time received by this node
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:175
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition chain.h:123
Helper for findBlock to selectively return pieces of block data.
Definition chain.h:48
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:59
Span< const CRPCCommand > GetWalletEncryptRPCCommands()
Definition encrypt.cpp:322
TransactionError
Definition error.h:22
uint8_t isminefilter
Definition wallet.h:42
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 StartWallets(CScheduler &scheduler, const ArgsManager &args)
Complete startup of wallets.
Definition load.cpp:149
bool VerifyWallets(interfaces::Chain &chain)
Responsible for reading and validating the -wallet arguments and verifying the wallet database.
Definition load.cpp:23
void UnloadWallets()
Close all wallets.
Definition load.cpp:183
void FlushWallets()
Flush all wallets in preparation for shutdown.
Definition load.cpp:171
void StopWallets()
Stop all wallets. Wallets will be flushed first.
Definition load.cpp:177
bool LoadWallets(interfaces::Chain &chain)
Load wallet databases.
Definition load.cpp:107
bool error(const char *fmt, const Args &...args)
Definition logging.h:226
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)
Return implementation of Wallet interface.
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:55
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
std::map< std::string, std::string > WalletValueMap
Definition wallet.h:56
NodeContext * m_context
OutputType
Definition outputtype.h:16
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
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()
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
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, Amount &nFeeRet, int &nChangePosInOut, bilingual_str &error, 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:993
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
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:23
Bilingual messages:
Definition translation.h:17
Information about one wallet address.
Definition wallet.h:334
Collection of wallet balances.
Definition wallet.h:347
Amount immature_watch_only_balance
Definition wallet.h:354
Amount unconfirmed_watch_only_balance
Definition wallet.h:353
std::vector< CTxDestination > txout_address
Definition wallet.h:372
std::vector< isminetype > txout_is_mine
Definition wallet.h:371
CTransactionRef tx
Definition wallet.h:369
std::map< std::string, std::string > value_map
Definition wallet.h:378
std::vector< isminetype > txout_address_is_mine
Definition wallet.h:373
std::vector< isminetype > txin_is_mine
Definition wallet.h:370
Wallet transaction output.
Definition wallet.h:396
Updated transaction status.
Definition wallet.h:383
unsigned int time_received
Definition wallet.h:387
#define LOCK(cs)
Definition sync.h:306
#define TRY_LOCK(cs, name)
Definition sync.h:314
#define AssertLockHeld(cs)
Definition sync.h:146
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition time.cpp:89
ChangeType
General change type (added, updated, removed).
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
std::shared_ptr< CWallet > m_wallet
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
const std::vector< std::string > m_wallet_filenames
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition wallet.h:48
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
Definition wallet.cpp:167
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition wallet.cpp:121
std::vector< std::shared_ptr< CWallet > > GetWallets()
Definition wallet.cpp:151
std::shared_ptr< CWallet > LoadWallet(interfaces::Chain &chain, 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:265
std::shared_ptr< CWallet > CreateWallet(interfaces::Chain &chain, 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:283
fs::path GetWalletDir()
Get the path of the wallet directory.
std::vector< fs::path > ListWalletDir()
Get wallets in wallet directory.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition walletutil.h:55