Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
wallet.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-present The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_WALLET_WALLET_H
7#define BITCOIN_WALLET_WALLET_H
8
9#include <addresstype.h>
10#include <consensus/amount.h>
11#include <interfaces/chain.h>
12#include <interfaces/handler.h>
13#include <kernel/cs_main.h>
14#include <node/types.h>
15#include <outputtype.h>
16#include <policy/feerate.h>
19#include <script/interpreter.h>
20#include <script/script.h>
22#include <sync.h>
23#include <tinyformat.h>
24#include <uint256.h>
25#include <util/btcsignals.h>
26#include <util/expected.h>
27#include <util/fs.h>
28#include <util/hasher.h>
29#include <util/log.h>
30#include <util/result.h>
31#include <util/string.h>
32#include <util/time.h>
33#include <util/ui_change_type.h>
34#include <wallet/crypter.h>
35#include <wallet/db.h>
37#include <wallet/transaction.h>
38#include <wallet/types.h>
39#include <wallet/walletutil.h>
40
41#include <atomic>
42#include <cassert>
43#include <cstddef>
44#include <cstdint>
45#include <functional>
46#include <limits>
47#include <map>
48#include <memory>
49#include <optional>
50#include <set>
51#include <string>
52#include <unordered_map>
53#include <utility>
54#include <vector>
55
56class CKey;
57class CKeyID;
58class CPubKey;
59class Coin;
60class SigningProvider;
61enum class MemPoolRemovalReason;
62enum class SigningResult;
63namespace common {
64enum class PSBTError;
65} // namespace common
66namespace interfaces {
67class Wallet;
68}
69namespace wallet {
70class CWallet;
71class WalletBatch;
72enum class DBErrors : int;
73} // namespace wallet
74struct CBlockLocator;
75struct CExtKey;
77struct KeyOriginInfo;
79struct SignatureData;
80
81using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
82
83struct bilingual_str;
84
85namespace wallet {
86struct WalletContext;
87
90void WaitForDeleteWallet(std::shared_ptr<CWallet>&& wallet);
91
92bool AddWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
93bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start, std::vector<bilingual_str>& warnings);
94bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start);
95std::vector<std::shared_ptr<CWallet>> GetWallets(WalletContext& context);
96std::shared_ptr<CWallet> GetDefaultWallet(WalletContext& context, size_t& count);
97std::shared_ptr<CWallet> GetWallet(WalletContext& context, const std::string& name);
98std::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);
99std::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);
100std::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, bool load_after_restore = true, bool allow_unnamed = false);
101std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, LoadWalletFn load_wallet);
102void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
103std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
104
106inline constexpr CAmount DEFAULT_FALLBACK_FEE = 0;
108inline constexpr CAmount DEFAULT_DISCARD_FEE{10'000};
110inline constexpr CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
112inline constexpr CAmount DEFAULT_CONSOLIDATE_FEERATE{10'000}; // 10 sat/vbyte
122inline constexpr CAmount HIGH_APS_FEE{COIN / 10000};
124inline constexpr CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
126inline constexpr bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
128inline constexpr bool DEFAULT_WALLET_REJECT_LONG_CHAINS{true};
130inline constexpr unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
132inline constexpr bool DEFAULT_WALLET_RBF = true;
133inline constexpr bool DEFAULT_WALLETBROADCAST = true;
134inline constexpr bool DEFAULT_DISABLE_WALLET = false;
135inline constexpr bool DEFAULT_WALLETCROSSCHAIN = false;
139inline constexpr CAmount HIGH_TX_FEE_PER_KB{COIN / 100};
143inline constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE = 91;
144
145class CCoinControl;
146
149
150inline constexpr uint64_t KNOWN_WALLET_FLAGS =
158
159inline constexpr uint64_t MUTABLE_WALLET_FLAGS =
161
162static const std::map<WalletFlags, std::string> WALLET_FLAG_TO_STRING{
163 {WALLET_FLAG_AVOID_REUSE, "avoid_reuse"},
164 {WALLET_FLAG_BLANK_WALLET, "blank"},
165 {WALLET_FLAG_KEY_ORIGIN_METADATA, "key_origin_metadata"},
166 {WALLET_FLAG_LAST_HARDENED_XPUB_CACHED, "last_hardened_xpub_cached"},
167 {WALLET_FLAG_DISABLE_PRIVATE_KEYS, "disable_private_keys"},
168 {WALLET_FLAG_DESCRIPTORS, "descriptor_wallet"},
169 {WALLET_FLAG_EXTERNAL_SIGNER, "external_signer"}
170};
171
181
198{
199protected:
201 const CWallet* const pwallet;
206 int64_t nIndex{-1};
210 bool fInternal{false};
211
212public:
217
220
226
230 void ReturnDestination();
232 void KeepDestination();
233};
234
239{
247 std::optional<std::string> label;
248
254 std::optional<AddressPurpose> purpose;
255
263 bool previously_spent{false};
264
272 std::map<std::string, std::string> receive_requests{};
273
275 bool IsChange() const { return !label.has_value(); }
276 std::string GetLabel() const { return label ? *label : std::string{}; }
277 void SetLabel(std::string name) { label = std::move(name); }
278};
279
280inline std::string PurposeToString(AddressPurpose p)
281{
282 switch(p) {
283 case AddressPurpose::RECEIVE: return "receive";
284 case AddressPurpose::SEND: return "send";
285 case AddressPurpose::REFUND: return "refund";
286 } // no default case, so the compiler can warn about missing cases
287 assert(false);
288}
289
290inline std::optional<AddressPurpose> PurposeFromString(std::string_view s)
291{
292 if (s == "receive") return AddressPurpose::RECEIVE;
293 else if (s == "send") return AddressPurpose::SEND;
294 else if (s == "refund") return AddressPurpose::REFUND;
295 return {};
296}
297
304
305class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime
309class CWallet final : public WalletStorage, public interfaces::Chain::Notifications
310{
311private:
313
314 bool Unlock(const CKeyingMaterial& vMasterKeyIn);
315
316 std::atomic<bool> fAbortRescan{false};
317 std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
318 std::atomic<bool> m_scanning_with_passphrase{false};
319 std::atomic<SteadyClock::time_point> m_scanning_start{SteadyClock::time_point{}};
320 std::atomic<double> m_scanning_progress{0};
322
328 // Local time that the tip block was received. Used to schedule wallet rebroadcasts.
329 std::atomic<int64_t> m_best_block_time {0};
330
331 // First created key time. Used to skip blocks prior to this time.
332 // 'std::numeric_limits<int64_t>::max()' if wallet is blank.
333 std::atomic<int64_t> m_birth_time{std::numeric_limits<int64_t>::max()};
334
340 typedef std::unordered_multimap<COutPoint, Txid, SaltedOutpointHasher> TxSpends;
342 void AddToSpends(const COutPoint& outpoint, const Txid& txid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
344
360 bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const SyncTxState& state, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
361
363 void MarkConflicted(const uint256& hashBlock, int conflicting_height, const Txid& hashTx);
364
365 enum class TxUpdate { UNCHANGED, CHANGED, NOTIFY_CHANGED };
366
367 using TryUpdatingStateFn = std::function<TxUpdate(CWalletTx& wtx)>;
368
370 void RecursiveUpdateTxState(const Txid& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
371 void RecursiveUpdateTxState(WalletBatch* batch, const Txid& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
372
375
378 std::set<CWalletTx*, WalletTxOrderComparator> GetMalleatedVariants(const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
379
381
382 bool SyncTransaction(const CTransactionRef& tx, const SyncTxState& state, bool rescanning_old_block = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
383
385 std::atomic<uint64_t> m_wallet_flags{0};
386
387 bool SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& strPurpose);
388
390 void UnsetWalletFlagWithDB(WalletBatch& batch, uint64_t flag);
391
393 void UnsetBlankWalletFlag(WalletBatch& batch) override;
394
397
399 std::string m_name;
400
402 std::unique_ptr<WalletDatabase> m_database;
403
411 uint256 m_last_block_processed GUARDED_BY(cs_wallet);
412
418 int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
419
420 std::map<OutputType, ScriptPubKeyMan*> m_external_spk_managers;
421 std::map<OutputType, ScriptPubKeyMan*> m_internal_spk_managers;
422
423 // Indexed by a unique identifier produced by each ScriptPubKeyMan using
424 // ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal structure
425 std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
426
427 // Appends spk managers into the main 'm_spk_managers'.
428 // Must be the only method adding data to it.
429 void AddScriptPubKeyMan(const uint256& id, std::unique_ptr<ScriptPubKeyMan> spkm_man);
430
431 // Same as 'AddActiveScriptPubKeyMan' but designed for use within a batch transaction context
432 void AddActiveScriptPubKeyManWithDb(WalletBatch& batch, uint256 id, OutputType type, bool internal);
433
435 void SetWalletFlagWithDB(WalletBatch& batch, uint64_t flags);
436
438 std::unordered_map<CScript, std::vector<ScriptPubKeyMan*>, SaltedSipHasher> m_cached_spks;
439
441 std::unordered_map<COutPoint, WalletTXO, SaltedOutpointHasher> m_txos GUARDED_BY(cs_wallet);
442
448 static bool AttachChain(const std::shared_ptr<CWallet>& wallet, interfaces::Chain& chain, bool rescan_required, bilingual_str& error, std::vector<bilingual_str>& warnings);
449
451
452 // Update last block processed in memory only
453 void SetLastBlockProcessedInMem(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
454
456 void UpdateTrucSiblingConflicts(const CWalletTx& parent_wtx, const Txid& child_txid, bool add_conflict) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
457
458public:
464
465 WalletDatabase& GetDatabase() const override
466 {
467 assert(static_cast<bool>(m_database));
468 return *m_database;
469 }
470
473 const std::string& GetName() const { return m_name; }
474
475 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
477 unsigned int nMasterKeyMaxID = 0;
478
480 CWallet(interfaces::Chain* chain, const std::string& name, std::unique_ptr<WalletDatabase> database)
481 : m_chain(chain),
482 m_name(name),
483 m_database(std::move(database))
484 {
485 }
486
488 {
489 // Should not have slots connected at this point.
491 }
492
493 bool IsLocked() const override;
494 bool Lock();
495
497 bool HaveChain() const { return m_chain ? true : false; }
498
501 std::unordered_map<Txid, CWalletTx, SaltedTxidHasher> mapWallet GUARDED_BY(cs_wallet);
502
503 typedef std::multimap<int64_t, CWalletTx*> TxItems;
505
506 int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
507
508 std::map<CTxDestination, CAddressBookData> m_address_book GUARDED_BY(cs_wallet);
509 const CAddressBookData* FindAddressBookEntry(const CTxDestination&, bool allow_change = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
510
517 std::map<COutPoint, bool> m_locked_coins GUARDED_BY(cs_wallet);
518
521
523 interfaces::Chain& chain() const { assert(m_chain); return *m_chain; }
524
526
527 std::set<Txid> GetTxConflicts(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
528
529 const std::unordered_map<COutPoint, WalletTXO, SaltedOutpointHasher>& GetTXOs() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return m_txos; };
530 std::optional<WalletTXO> GetTXO(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
531
536
551
559
560 enum class SpendType {
561 UNSPENT,
562 CONFIRMED,
563 MEMPOOL,
564 NONMEMPOOL,
565 };
567 bool IsSpent(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
568
569 // Whether this or any known scriptPubKey with the same single key has been spent.
570 bool IsSpentKey(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
571 void SetSpentKeyState(WalletBatch& batch, const Txid& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
572
575
576 bool IsLockedCoin(const COutPoint& output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
577 void LoadLockedCoin(const COutPoint& coin, bool persistent) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
578 bool LockCoin(const COutPoint& output, bool persist) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
581 void ListLockedCoins(std::vector<COutPoint>& vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
582
583 /*
584 * Rescan abort properties
585 */
586 void AbortRescan() { fAbortRescan = true; }
587 bool IsAbortingRescan() const { return fAbortRescan; }
588 bool IsScanning() const { return fScanningWallet; }
590 SteadyClock::duration ScanningDuration() const { return fScanningWallet ? SteadyClock::now() - m_scanning_start.load() : SteadyClock::duration{}; }
591 double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }
592
595
599 void LoadAddressReceiveRequest(const CTxDestination& dest, const std::string& id, const std::string& request) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
600
602 int64_t nRelockTime GUARDED_BY(cs_wallet){0};
603
604 // Used to prevent concurrent calls to walletpassphrase RPC.
606 // Used to prevent deleting the passphrase from memory when it is still in use.
608
609 bool Unlock(const SecureString& strWalletPassphrase);
610 bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
611 bool EncryptWallet(const SecureString& strWalletPassphrase);
612
613 unsigned int ComputeTimeSmart(const CWalletTx& wtx, bool rescanning_old_block) const;
614
621
622 void MarkDirty();
623
630 using UpdateWalletTxFn = std::function<bool(CWalletTx& wtx, bool new_tx)>;
631
636 CWalletTx* AddToWallet(CTransactionRef tx, const TxState& state, const UpdateWalletTxFn& update_wtx=nullptr, bool rescanning_old_block = false);
638 void transactionAddedToMempool(const CTransactionRef& tx) override;
639 void blockConnected(const kernel::ChainstateRole& role, const interfaces::BlockInfo& block) override;
640 void blockDisconnected(const interfaces::BlockInfo& block) override;
641 void updatedBlockTip() override;
642 int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver);
643
644 struct ScanResult {
645 enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
646
651 std::optional<int> last_scanned_height;
652
658 };
659 ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool save_progress);
664 bool ShouldResend() const;
665 void ResubmitWalletTransactions(node::TxBroadcast broadcast_method, bool force);
666
667 OutputType TransactionChangeType(const std::optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const;
668
672 bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const;
673 SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const;
674
687 std::optional<common::PSBTError> FillPSBT(PartiallySignedTransaction& psbtx,
688 const common::PSBTFillOptions& options,
689 bool& complete,
690 size_t* n_signed = nullptr) const;
691
705 std::optional<Txid> replaces_txid = std::nullopt,
706 std::optional<std::string> comment = std::nullopt,
707 std::optional<std::string> comment_to = std::nullopt,
708 const std::vector<std::string>& messages = {},
709 const std::vector<std::string>& payment_requests = {}
710 );
711
713 bool SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string, node::TxBroadcast broadcast_method) const
715
717 void MaybeUpdateBirthTime(int64_t time);
718
732
736
742
752 std::optional<OutputType> m_default_change_type{};
755
758
761
763 bool TopUpKeyPool(unsigned int kpSize = 0);
764
765 // Filter struct for 'ListAddrBookAddresses'
767 // Fetch addresses with the provided label
768 std::optional<std::string> m_op_label{std::nullopt};
769 // Don't include change addresses by default
770 bool ignore_change{true};
771 };
772
776 std::vector<CTxDestination> ListAddrBookAddresses(const std::optional<AddrBookFilter>& filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
777
781 std::set<std::string> ListAddrBookLabels(std::optional<AddressPurpose> purpose) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
782
787 using ListAddrBookFunc = std::function<void(const CTxDestination& dest, const std::string& label, bool is_change, const std::optional<AddressPurpose> purpose)>;
789
794 void MarkDestinationsDirty(const std::set<CTxDestination>& destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
795
796 util::Result<CTxDestination> GetNewDestination(OutputType type, const std::string& label);
798
802 CAmount GetDebit(const CTxIn& txin) const;
803 bool IsMine(const CTxOut& txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
805 bool IsMine(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
807 bool IsFromMe(const CTransaction& tx) const;
808 CAmount GetDebit(const CTransaction& tx) const;
809
810 DBErrors PopulateWalletFromDB(bilingual_str& error, std::vector<bilingual_str>& warnings);
811
813 util::Result<void> RemoveTxs(std::vector<Txid>& txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
814 util::Result<void> RemoveTxs(WalletBatch& batch, std::vector<Txid>& txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
815
816 bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& purpose);
817
818 bool DelAddressBook(const CTxDestination& address);
819 bool DelAddressBookWithDB(WalletBatch& batch, const CTxDestination& address);
820
823
824 std::vector<std::string> GetAddressReceiveRequests() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
825 bool SetAddressReceiveRequest(WalletBatch& batch, const CTxDestination& dest, const std::string& id, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
827
829
832
835
837 void Close();
838
840 btcsignals::signal<void ()> NotifyUnload;
841
846 btcsignals::signal<void(const CTxDestination& address,
847 const std::string& label, bool isMine,
848 AddressPurpose purpose, ChangeType status)>
850
855 btcsignals::signal<void(const Txid& hashTx, ChangeType status)> NotifyTransactionChanged;
856
858 btcsignals::signal<void (const std::string &title, int nProgress)> ShowProgress;
859
862
868
872 void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
873
875 bool TransactionCanBeAbandoned(const Txid& hashTx) const;
876
877 /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
878 bool AbandonTransaction(const Txid& hashTx);
880
882 bool MarkReplaced(const Txid& originalHash, const Txid& newHash);
883
884 static bool LoadWalletArgs(std::shared_ptr<CWallet> wallet, const WalletContext& context, bilingual_str& error, std::vector<bilingual_str>& warnings);
885
886 /* Initializes, creates and returns a new CWallet; returns a null pointer in case of an error */
887 static std::shared_ptr<CWallet> CreateNew(WalletContext& context, const std::string& name, std::unique_ptr<WalletDatabase> database, uint64_t wallet_creation_flags, bool born_encrypted, bilingual_str& error, std::vector<bilingual_str>& warnings);
888
889 /* Initializes, loads, and returns a CWallet from an existing wallet; returns a null pointer in case of an error */
890 static std::shared_ptr<CWallet> LoadExisting(WalletContext& context, const std::string& name, std::unique_ptr<WalletDatabase> database, bilingual_str& error, std::vector<bilingual_str>& warnings);
891
896 void postInitProcess();
897
898 [[nodiscard]] bool BackupWallet(const std::string& strDest) const;
899
900 /* Returns true if HD is enabled */
901 bool IsHDEnabled() const;
902
903 /* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */
904 bool CanGetAddresses(bool internal = false) const;
905
906 /* Returns the time of the first created key or, in case of an import, it could be the time of the first received transaction */
907 int64_t GetBirthTime() const { return m_birth_time; }
908
915 void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main) EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet);
916
918 void SetWalletFlag(uint64_t flags);
919
921 void UnsetWalletFlag(uint64_t flag);
922
924 bool IsWalletFlagSet(uint64_t flag) const override;
925
929 void InitWalletFlags(uint64_t flags);
931 bool LoadWalletFlags(uint64_t flags);
933 uint64_t GetWalletFlags() const;
934
936 std::string LogName() const override
937 {
938 std::string name{GetName()};
939 return name.empty() ? "default wallet" : name;
940 };
941
943 std::string DisplayName() const
944 {
945 std::string name{GetName()};
946 return name.empty() ? _("default wallet") : name;
947 };
948
950 template <typename... Params>
951 void WalletLogPrintf(util::ConstevalFormatString<sizeof...(Params)> wallet_fmt, const Params&... params) const
952 {
953 LogInfo("[%s] %s", LogName(), tfm::format(wallet_fmt, params...));
954 };
955
957 {
959 WalletLogPrintf("setKeyPool.size() = %u\n", GetKeyPoolSize());
960 WalletLogPrintf("mapWallet.size() = %u\n", mapWallet.size());
961 WalletLogPrintf("m_address_book.size() = %u\n", m_address_book.size());
962 };
963
965 std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
966 bool IsActiveScriptPubKeyMan(const ScriptPubKeyMan& spkm) const;
967
969 std::set<ScriptPubKeyMan*> GetAllScriptPubKeyMans() const;
970
972 ScriptPubKeyMan* GetScriptPubKeyMan(const OutputType& type, bool internal) const;
973
975 std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script) const;
978
980 std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
981 std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
982
984 std::vector<WalletDescriptor> GetWalletDescriptors(const CScript& script) const;
985
989
991 void SetupLegacyDataSPKM();
992
993 bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const override;
994
995 bool HasEncryptionKeys() const override;
996 bool HaveCryptedKeys() const;
997
1000 {
1002 assert(m_last_block_processed_height >= 0);
1003 return m_last_block_processed_height;
1004 };
1006 {
1008 assert(m_last_block_processed_height >= 0);
1009 return m_last_block_processed;
1010 }
1011
1012 void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1015
1018
1020 void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc, const KeyMap& keys, const CryptedKeyMap& ckeys);
1021
1026 void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1027
1032 void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1033
1038 void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1039
1045
1048
1051
1054
1058 std::optional<bool> IsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const;
1059
1061 util::Result<std::reference_wrapper<DescriptorScriptPubKeyMan>> AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1062
1069
1072
1076
1078 bool CanGrindR() const;
1079
1081 void CacheNewScriptPubKeys(const std::set<CScript>& spks, ScriptPubKeyMan* spkm);
1082
1083 void TopUpCallback(const std::set<CScript>& spks, ScriptPubKeyMan* spkm) override;
1084
1086 enum class HDKeyFilter {
1087 Active,
1089 UnusedKey,
1090 };
1091 using HDPubKeyMap = std::map<CExtPubKey, std::set<DescriptorScriptPubKeyMan*>>;
1094
1097 std::optional<CKey> GetKey(const CKeyID& keyid) const;
1098
1101 std::optional<CExtKey> GetExtKey(const CExtPubKey& xpub) const;
1102
1105};
1106
1111void MaybeResendWalletTxs(WalletContext& context);
1112
1115{
1116private:
1117 using Clock = std::chrono::steady_clock;
1118 using NowFn = std::function<Clock::time_point()>;
1120 bool m_could_reserve{false};
1122public:
1124
1125 bool reserve(bool with_passphrase = false)
1126 {
1128 if (m_wallet.fScanningWallet.exchange(true)) {
1129 return false;
1130 }
1131 // Discard any abort request left over from previous reservation, so
1132 // that an abort requested while the reservation is held always applies
1133 // to abort this rescan, even if it arrives before the scan loop starts.
1134 m_wallet.fAbortRescan = false;
1135 m_wallet.m_scanning_with_passphrase.exchange(with_passphrase);
1136 m_wallet.m_scanning_start = SteadyClock::now();
1138 m_could_reserve = true;
1139 return true;
1140 }
1141
1142 bool isReserved() const
1143 {
1145 }
1146
1147 Clock::time_point now() const { return m_now ? m_now() : Clock::now(); };
1148
1149 void setNow(NowFn now) { m_now = std::move(now); }
1150
1152 {
1153 if (m_could_reserve) {
1154 m_wallet.fScanningWallet = false;
1156 }
1157 }
1158};
1159
1161bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
1162
1164bool RemoveWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
1165
1167 std::string wallet_name;
1168 std::optional<std::string> watchonly_wallet_name;
1169 std::optional<std::string> solvables_wallet_name;
1170 std::shared_ptr<CWallet> wallet;
1171 std::shared_ptr<CWallet> watchonly_wallet;
1172 std::shared_ptr<CWallet> solvables_wallet;
1173 fs::path backup_path;
1174};
1175
1177[[nodiscard]] util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& wallet_name, const SecureString& passphrase, WalletContext& context, bool load_wallet = true);
1179[[nodiscard]] util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet> local_wallet, const SecureString& passphrase, WalletContext& context, bool load_wallet = true);
1180
1182util::Result<fs::path> GetWalletPath(const std::string& name);
1183} // namespace wallet
1184
1185#endif // BITCOIN_WALLET_WALLET_H
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition wallet.cpp:161
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition wallet.cpp:173
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
int64_t CAmount
Amount in satoshis (Can be negative).
Definition amount.h:12
constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition amount.h:15
const CChainParams & Params()
Return the currently selected parameters.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition feerate.h:32
An encapsulated private key.
Definition key.h:40
A reference to a CKey: the Hash160 of its serialized public key.
Definition pubkey.h:26
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition transaction.h:30
An encapsulated public key.
Definition pubkey.h:40
Serialized script, used inside transaction inputs and outputs.
Definition script.h:406
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
Definition transaction.h:63
An output of a transaction.
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > database)
Construct wallet with specified name and database implementation.
Definition wallet.h:480
Definition chain.h:117
A UTXO entry.
Definition coins.h:46
A version of CTransaction with the PSBT format.
Definition psbt.h:1239
An interface to be implemented by keystores that support signing.
bool empty() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Definition btcsignals.h:250
Chain notifications.
Definition chain.h:305
Interface for accessing a wallet.
Definition wallet.h:62
256-bit opaque blob.
Definition uint256.h:196
Coin Control Features.
Definition coincontrol.h:83
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition wallet.h:310
void MarkDestinationsDirty(const std::set< CTxDestination > &destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Marks all outputs in each one of the destinations dirty, so their cache is reset and does not return ...
Definition wallet.cpp:2667
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::optional< AddressPurpose > &purpose)
Definition wallet.cpp:2555
std::atomic< bool > fAbortRescan
Definition wallet.h:316
bool TopUpKeyPool(unsigned int kpSize=0)
Definition wallet.cpp:2630
bool HaveChain() const
Interface to assert chain access.
Definition wallet.h:497
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition wallet.h:870
bool m_signal_rbf
Definition wallet.h:723
int64_t GetBirthTime() const
Definition wallet.h:907
std::atomic< SteadyClock::time_point > m_scanning_start
Definition wallet.h:319
DBErrors PopulateWalletFromDB(bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition wallet.cpp:2404
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2619
std::function< bool(CWalletTx &wtx, bool new_tx)> UpdateWalletTxFn
Definition wallet.h:630
CAmount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
Definition wallet.h:754
btcsignals::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition wallet.h:840
std::optional< WalletTXO > GetTXO(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:4656
bool IsActiveScriptPubKeyMan(const ScriptPubKeyMan &spkm) const
Definition wallet.cpp:3467
static bool AttachChain(const std::shared_ptr< CWallet > &wallet, interfaces::Chain &chain, bool rescan_required, bilingual_str &error, std::vector< bilingual_str > &warnings)
Catch wallet up to current chain, scanning new blocks, updating the best block locator and m_last_blo...
Definition wallet.cpp:3232
OutputType m_default_address_type
Definition wallet.h:745
int m_last_block_processed_height GUARDED_BY(cs_wallet)
Height of last block processed is used by wallet to know depth of transactions without relying on Cha...
static std::shared_ptr< CWallet > LoadExisting(WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition wallet.cpp:3188
CFeeRate m_discard_rate
If the cost to spend a change output at this feerate is greater than the value of the output itself,...
Definition wallet.h:735
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Definition wallet.cpp:3738
void LogStats() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.h:956
btcsignals::signal< void(const CTxDestination &address, const std::string &label, bool isMine, AddressPurpose purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition wallet.h:849
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Definition wallet.cpp:3752
std::unique_ptr< WalletDatabase > m_database
Internal database handle.
Definition wallet.h:402
bool IsLockedCoin(const COutPoint &output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2814
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > database)
Construct wallet with specified name and database implementation.
Definition wallet.h:480
std::function< void(const CTxDestination &dest, const std::string &label, bool is_change, const std::optional< AddressPurpose > purpose)> ListAddrBookFunc
Walk-through the address book entries.
Definition wallet.h:787
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
Get the SigningProvider for a script.
Definition wallet.cpp:3520
bool IsTxImmatureCoinBase(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:3404
void RefreshAllTXOs() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Cache outputs that belong to the wallet for all transactions in the wallet.
Definition wallet.cpp:4648
void AddActiveScriptPubKeyManWithDb(WalletBatch &batch, uint256 id, OutputType type, bool internal)
Definition wallet.cpp:3744
void TopUpCallback(const std::set< CScript > &spks, ScriptPubKeyMan *spkm) override
Callback function for after TopUp completes containing any scripts that were added by a SPKMan.
Definition wallet.cpp:4567
std::set< ScriptPubKeyMan * > GetActiveScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers.
Definition wallet.cpp:3453
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:3352
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition wallet.cpp:3362
std::optional< CExtKey > GetExtKey(const CExtPubKey &xpub) const
Definition wallet.cpp:4611
int GetTxDepthInMainChain(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
Definition wallet.cpp:3378
unsigned int nMasterKeyMaxID
Definition wallet.h:477
bool IsScanning() const
Definition wallet.h:588
bool SetAddressReceiveRequest(WalletBatch &batch, const CTxDestination &dest, const std::string &id, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2943
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition wallet.h:999
std::atomic< double > m_scanning_progress
Definition wallet.h:320
LegacyDataSPKM * GetLegacyDataSPKM() const
Get the LegacyDataSPKM used for all legacy output types and both internal and external chains.
Definition wallet.cpp:3551
void DisconnectChainNotifications()
Disconnect chain notifications and wait for all notifications to be processed.
Definition wallet.cpp:4666
CAmount m_max_aps_fee
The maximum fee amount we're willing to pay to prioritize partial spend avoidance.
Definition wallet.h:744
std::optional< common::PSBTError > FillPSBT(PartiallySignedTransaction &psbtx, const common::PSBTFillOptions &options, bool &complete, size_t *n_signed=nullptr) const
Fills out a PSBT with information from the wallet.
Definition wallet.cpp:2228
void SetupWalletGeneration() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Setup new descriptors or seed for new address generation.
Definition wallet.cpp:3726
std::vector< CTxDestination > ListAddrBookAddresses(const std::optional< AddrBookFilter > &filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Filter and retrieve destinations stored in the addressbook.
Definition wallet.cpp:2690
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
Definition wallet.cpp:3789
btcsignals::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition wallet.h:867
btcsignals::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition wallet.h:861
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
Definition wallet.h:420
uint256 m_last_block_processed GUARDED_BY(cs_wallet)
The following is used to keep track of how far behind the wallet is from the chain sync,...
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet)
const std::unordered_map< COutPoint, WalletTXO, SaltedOutpointHasher > & GetTXOs() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.h:529
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition wallet.h:872
std::optional< MigrationData > GetDescriptorsForLegacy(bilingual_str &error) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get all of the descriptors from a legacy wallet.
Definition wallet.cpp:3950
std::optional< OutputType > m_default_change_type
Default output type for change outputs.
Definition wallet.h:752
bool HaveCryptedKeys() const
Definition wallet.cpp:3605
int64_t nOrderPosNext GUARDED_BY(cs_wallet)=0
LegacyDataSPKM * GetOrCreateLegacyDataSPKM()
Definition wallet.cpp:3571
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition wallet.h:523
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition wallet.h:473
std::map< CExtPubKey, std::set< DescriptorScriptPubKeyMan * > > HDPubKeyMap
Definition wallet.h:1091
bool Unlock(const CKeyingMaterial &vMasterKeyIn)
Definition wallet.cpp:3438
bool MigrateToSQLite(bilingual_str &error) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Move all records from the BDB database to a new SQLite database for storage.
Definition wallet.cpp:3876
bool BackupWallet(const std::string &strDest) const
Definition wallet.cpp:3372
std::unique_ptr< interfaces::Handler > m_chain_notifications_handler
Registered interfaces::Chain::Notifications handler.
Definition wallet.h:520
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
Definition wallet.h:421
std::string m_name
Wallet name: relative directory name or "" for default wallet.
Definition wallet.h:399
bool SetAddressPreviouslySpent(WalletBatch &batch, const CTxDestination &dest, bool used) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2902
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc, const KeyMap &keys, const CryptedKeyMap &ckeys)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
Definition wallet.cpp:3625
util::Result< void > RemoveTxs(std::vector< Txid > &txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Erases the provided transactions from the wallet.
Definition wallet.cpp:2458
double ScanningProgress() const
Definition wallet.h:591
SteadyClock::duration ScanningDuration() const
Definition wallet.h:590
RecursiveMutex m_relock_mutex
Definition wallet.h:607
btcsignals::signal< void(const Txid &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition wallet.h:855
std::string m_notify_tx_changed_script
Notify external script when a wallet transaction comes in or is updated (handled by -walletnotify).
Definition wallet.h:760
std::vector< std::string > GetAddressReceiveRequests() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2932
std::vector< WalletDescriptor > GetWalletDescriptors(const CScript &script) const
Get the wallet descriptors for a script.
Definition wallet.cpp:3539
bool fBroadcastTransactions
Whether this wallet will submit newly created transactions to the node's mempool and prompt rebroadca...
Definition wallet.h:327
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2607
void CacheNewScriptPubKeys(const std::set< CScript > &spks, ScriptPubKeyMan *spkm)
Add scriptPubKeys for this ScriptPubKeyMan into the scriptPubKey cache.
Definition wallet.cpp:4560
int GetTxBlocksToMaturity(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:3392
void WalletLogPrintf(util::ConstevalFormatString< sizeof...(Params)> wallet_fmt, const Params &... params) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
Definition wallet.h:951
bool HasEncryptionKeys() const override
Definition wallet.cpp:3600
bool CanGrindR() const
Whether the (external) signer performs R-value signature grinding.
Definition wallet.cpp:4178
std::map< CTxDestination, CAddressBookData > m_address_book GUARDED_BY(cs_wallet)
std::string LogName() const override
Return wallet name for use in logs, will return "default wallet" if the wallet has no name.
Definition wallet.h:936
void CommitTransaction(CTransactionRef tx, std::optional< Txid > replaces_txid=std::nullopt, std::optional< std::string > comment=std::nullopt, std::optional< std::string > comment_to=std::nullopt, const std::vector< std::string > &messages={}, const std::vector< std::string > &payment_requests={})
Submit the transaction to the node's mempool and then relay to peers.
Definition wallet.cpp:2357
util::Result< CTxDestination > GetNewChangeDestination(OutputType type)
Definition wallet.cpp:2656
std::optional< bool > IsInternalScriptPubKeyMan(ScriptPubKeyMan *spk_man) const
Definition wallet.cpp:3803
void SetNextResend()
Set the next time this wallet should resend transactions to 12-36 hours from now, ~1 day on average.
Definition wallet.h:662
void LoadLockedCoin(const COutPoint &coin, bool persistent) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2770
void SetupLegacyDataSPKM()
Create a LegacyDataSPKM and set it for all legacy output types and both internal and external chains.
Definition wallet.cpp:3577
TxItems wtxOrdered
Definition wallet.h:504
std::atomic< bool > m_scanning_with_passphrase
Definition wallet.h:318
static std::shared_ptr< CWallet > CreateNew(WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bool born_encrypted, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition wallet.cpp:3133
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Definition wallet.cpp:2283
bool m_spend_zero_conf_change
Allow Coin Selection to pick unconfirmed UTXOs that were sent from our own wallet if it cannot fund t...
Definition wallet.h:722
MasterKeyMap mapMasterKeys
Definition wallet.h:476
unsigned int m_confirm_target
Definition wallet.h:719
CFeeRate m_consolidate_feerate
When the actual feerate is less than the consolidate feerate, we will tend to make transactions which...
Definition wallet.h:741
btcsignals::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition wallet.h:858
util::Result< void > ApplyMigrationData(WalletBatch &local_wallet_batch, MigrationData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:3969
NodeClock::time_point m_next_resend
The next scheduled rebroadcast of wallet transactions.
Definition wallet.h:324
HDKeyFilter
Which descriptors GetHDPubKeys() should consider.
Definition wallet.h:1086
WalletDatabase & GetDatabase() const override
Definition wallet.h:465
std::optional< CKey > GetKey(const CKeyID &keyid) const
Definition wallet.cpp:4596
bool EraseAddressReceiveRequest(WalletBatch &batch, const CTxDestination &dest, const std::string &id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2950
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::optional< AddressPurpose > &strPurpose)
Definition wallet.cpp:2519
void WriteBestBlock() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Write the current best block to database.
Definition wallet.cpp:4619
void AbortRescan()
Definition wallet.h:586
bool DelAddressBookWithDB(WalletBatch &batch, const CTxDestination &address)
Definition wallet.cpp:2568
std::string DisplayName() const
Return wallet name for display, like LogName() but translates "default wallet" string.
Definition wallet.h:943
void LoadAddressReceiveRequest(const CTxDestination &dest, const std::string &id, const std::string &request) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Appends payment request to destination.
Definition wallet.cpp:2921
Mutex m_unlock_mutex
Definition wallet.h:605
void AddScriptPubKeyMan(const uint256 &id, std::unique_ptr< ScriptPubKeyMan > spkm_man)
Definition wallet.cpp:3561
void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Definition wallet.cpp:3772
std::atomic< uint64_t > m_wallet_flags
WalletFlags set on this wallet.
Definition wallet.h:385
interfaces::Chain * m_chain
Interface for accessing chain state.
Definition wallet.h:396
bool LockCoin(const COutPoint &output, bool persist) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2776
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition wallet.h:731
bool IsLocked() const override
Definition wallet.cpp:3412
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition wallet.h:475
OutputType TransactionChangeType(const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
Definition wallet.cpp:2296
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
Definition wallet.cpp:3478
void RefreshTXOsFromTx(const CWalletTx &wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Cache outputs that belong to the wallet from a single transaction.
Definition wallet.cpp:4634
unsigned int ComputeTimeSmart(const CWalletTx &wtx, bool rescanning_old_block) const
Compute smart timestamp for a transaction being added to the wallet.
Definition wallet.cpp:2851
TxSpends mapTxSpends GUARDED_BY(cs_wallet)
std::set< std::string > ListAddrBookLabels(std::optional< AddressPurpose > purpose) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Retrieve all the known labels in the address book.
Definition wallet.cpp:2706
std::unordered_map< COutPoint, WalletTXO, SaltedOutpointHasher > m_txos GUARDED_BY(cs_wallet)
Set of both spent and unspent transaction outputs owned by this wallet.
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2820
bool IsAbortingRescan() const
Definition wallet.h:587
bool UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2802
util::Result< CTxDestination > GetNewDestination(OutputType type, const std::string &label)
Definition wallet.cpp:2640
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
Definition wallet.cpp:3487
bool IsAddressPreviouslySpent(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2926
bool WithEncryptionKey(std::function< bool(const CKeyingMaterial &)> cb) const override
Pass the encryption key to cb().
Definition wallet.cpp:3594
uint256 GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.h:1005
bool m_allow_fallback_fee
will be false if -fallbackfee=0
Definition wallet.h:724
int64_t m_keypool_size
Number of pre-generated keys/scripts by each spkm (part of the look-ahead process,...
Definition wallet.h:757
RecursiveMutex cs_wallet
Main wallet lock.
Definition wallet.h:463
void ForEachAddrBookEntry(const ListAddrBookFunc &func) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2681
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
Definition wallet.cpp:3613
bool DelAddressBook(const CTxDestination &address)
Definition wallet.cpp:2561
friend class WalletRescanReserver
Definition wallet.h:321
CFeeRate m_min_fee
Definition wallet.h:725
std::atomic< int64_t > m_best_block_time
Definition wallet.h:329
std::unordered_map< CScript, std::vector< ScriptPubKeyMan * >, SaltedSipHasher > m_cached_spks
Cache of descriptor ScriptPubKeys used for IsMine. Maps ScriptPubKey to set of spkms.
Definition wallet.h:438
std::multimap< int64_t, CWalletTx * > TxItems
Definition wallet.h:503
std::unordered_map< Txid, CWalletTx, SaltedTxidHasher > mapWallet GUARDED_BY(cs_wallet)
Map from txid to CWalletTx for all transactions this wallet is interested in, including received and ...
void SetupOwnDescriptorScriptPubKeyMans(WalletBatch &batch) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new seed and default DescriptorScriptPubKeyMans for this wallet.
Definition wallet.cpp:3660
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:3676
DescriptorScriptPubKeyMan & SetupDescriptorScriptPubKeyMan(WalletBatch &batch, const CExtKey &master_key, const OutputType &output_type, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new DescriptorScriptPubKeyMan and add it to the wallet.
Definition wallet.cpp:3636
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
Definition wallet.h:425
std::function< TxUpdate(CWalletTx &wtx)> TryUpdatingStateFn
Definition wallet.h:367
bool UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2787
std::atomic< int64_t > m_birth_time
Definition wallet.h:333
void LoadAddressPreviouslySpent(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Marks destination as previously spent.
Definition wallet.cpp:2916
util::Result< std::reference_wrapper< DescriptorScriptPubKeyMan > > AddWalletDescriptor(WalletDescriptor &desc, const FlatSigningProvider &signing_provider, const std::string &label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type.
Definition wallet.cpp:3822
static bool LoadWalletArgs(std::shared_ptr< CWallet > wallet, const WalletContext &context, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition wallet.cpp:3007
HDPubKeyMap GetHDPubKeys(HDKeyFilter filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Retrieve descriptor xpubs matching the requested filter.
Definition wallet.cpp:4573
std::atomic< bool > fScanningWallet
Definition wallet.h:317
std::set< ScriptPubKeyMan * > GetScriptPubKeyMans(const CScript &script) const
Get all the ScriptPubKeyMans for a script.
Definition wallet.cpp:3497
util::Result< void > DisplayAddress(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Display address on an external signer.
Definition wallet.cpp:2755
bool IsScanningWithPassphrase() const
Definition wallet.h:589
std::unordered_multimap< COutPoint, Txid, SaltedOutpointHasher > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
Definition wallet.h:340
A transaction with a bunch of additional info that only the owner cares about.
const CWallet *const pwallet
The wallet to reserve from.
Definition wallet.h:201
void KeepDestination()
Keep the address. Do not return its key to the keypool when this object goes out of scope.
Definition wallet.cpp:2737
CTxDestination address
The destination.
Definition wallet.h:208
bool fInternal
Whether this is from the internal (change output) keypool.
Definition wallet.h:210
~ReserveDestination()
Destructor. If a key has been reserved and not KeepKey'ed, it will be returned to the keypool.
Definition wallet.h:222
ReserveDestination(CWallet *pwallet, OutputType type)
Construct a ReserveDestination object. This does NOT reserve an address yet.
Definition wallet.h:214
void ReturnDestination()
Return reserved address.
Definition wallet.cpp:2746
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called.
Definition wallet.h:203
ReserveDestination & operator=(const ReserveDestination &)=delete
int64_t nIndex
The index of the address's key in the keypool.
Definition wallet.h:206
OutputType const type
Definition wallet.h:204
util::Result< CTxDestination > GetReservedDestination(bool internal)
Reserve an address.
Definition wallet.cpp:2720
ReserveDestination(const ReserveDestination &)=delete
Access to the wallet database.
Definition walletdb.h:197
An instance of this class represents one database.
Definition db.h:129
Descriptor with some wallet metadata.
Definition walletutil.h:64
RAII object to check and reserve a wallet rescan.
Definition wallet.h:1115
std::function< Clock::time_point()> NowFn
Definition wallet.h:1118
std::chrono::steady_clock Clock
Definition wallet.h:1117
WalletRescanReserver(CWallet &w)
Definition wallet.h:1123
Clock::time_point now() const
Definition wallet.h:1147
void setNow(NowFn now)
Definition wallet.h:1149
bool reserve(bool with_passphrase=false)
Definition wallet.h:1125
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:8
bool IsSpentKey(const CScript &scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:1065
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
Definition wallet.cpp:982
void RecursiveUpdateTxState(const Txid &tx_hash, const TryUpdatingStateFn &try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Mark a transaction (and its in-wallet descendants) as a particular tx state.
Definition wallet.cpp:1402
void MarkInputsDirty(const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed.
Definition wallet.cpp:1324
bool HasWalletSpend(const CTransactionRef &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Check if a given transaction has any of its outputs spent by another transaction in the wallet.
Definition wallet.cpp:718
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition wallet.cpp:647
bool AbandonTransaction(const Txid &hashTx)
Definition wallet.cpp:1334
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver)
Scan active chain for relevant transactions after importing keys.
Definition wallet.cpp:1857
void SetWalletFlagWithDB(WalletBatch &batch, uint64_t flags)
Store wallet flags.
Definition wallet.cpp:1776
uint64_t GetWalletFlags() const
Retrieve all of the wallet's flags.
Definition wallet.cpp:1836
void updatedBlockTip() override
Definition wallet.cpp:1646
bool TransactionCanBeAbandoned(const Txid &hashTx) const
Return whether transaction can be abandoned.
Definition wallet.cpp:1300
void SyncMalleatedTxMetadata(WalletBatch &batch, const CWalletTx &wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:765
void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(void SetWalletFlag(uint64_t flags)
Blocks until the wallet state is up-to-date to /at least/ the current chain at the time this function...
Definition wallet.cpp:1770
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, const SyncTxState &state, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Add a transaction to the wallet, or update it.
Definition wallet.cpp:1235
ScanResult ScanForWalletTransactions(const uint256 &start_block, int start_height, std::optional< int > max_height, const WalletRescanReserver &reserver, bool save_progress)
Scan the block chain (starting in start_block) for transactions from or to us.
Definition wallet.cpp:1900
void MaybeUpdateBirthTime(int64_t time)
Updates wallet birth time if 'time' is below it.
Definition wallet.cpp:1841
void blockDisconnected(const interfaces::BlockInfo &block) override
Definition wallet.cpp:1599
std::set< Txid > GetConflicts(const Txid &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get wallet transactions that conflict with given transaction (spend same outputs).
Definition wallet.cpp:695
bool IsWalletFlagSet(uint64_t flag) const override
check if a certain wallet flag is set
Definition wallet.cpp:1803
SpendType HowSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:810
void AddToSpends(const COutPoint &outpoint, const Txid &txid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:833
void SetLastBlockProcessedInMem(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:679
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Definition wallet.cpp:1790
bool IsSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction spends it:
Definition wallet.cpp:793
void ResubmitWalletTransactions(node::TxBroadcast broadcast_method, bool force)
Definition wallet.cpp:2147
std::set< Txid > GetTxConflicts(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:2093
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
Definition wallet.cpp:1798
CWalletTx * AddToWallet(CTransactionRef tx, const TxState &state, const UpdateWalletTxFn &update_wtx=nullptr, bool rescanning_old_block=false)
Add the transaction to the wallet, wrapping it up inside a CWalletTx.
Definition wallet.cpp:1078
bool MarkReplaced(const Txid &originalHash, const Txid &newHash)
Mark a transaction as replaced by another transaction.
Definition wallet.cpp:1003
bool CanGetAddresses(bool internal=false) const
Definition wallet.cpp:1757
void MarkDirty()
Definition wallet.cpp:994
bool LoadToWallet(CWalletTx &&wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:1203
void UpdateTrucSiblingConflicts(const CWalletTx &parent_wtx, const Txid &child_txid, bool add_conflict) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Update mempool conflicts for TRUC sibling transactions.
Definition wallet.cpp:1307
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition wallet.cpp:1808
bool IsHDEnabled() const
Definition wallet.cpp:1746
bool SubmitTxMemoryPoolAndRelay(CWalletTx &wtx, std::string &err_string, node::TxBroadcast broadcast_method) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Pass this transaction to node for optional mempool insertion and relay to peers.
Definition wallet.cpp:2050
void blockConnected(const kernel::ChainstateRole &role, const interfaces::BlockInfo &block) override
Definition wallet.cpp:1570
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason) override
Definition wallet.cpp:1501
static NodeClock::time_point GetDefaultNextResend()
Definition wallet.cpp:2120
bool ShouldResend() const
Return true if all conditions for periodically resending transactions are met.
Definition wallet.cpp:2103
bool SyncTransaction(const CTransactionRef &tx, const SyncTxState &state, bool rescanning_old_block=false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:1446
const CWalletTx * GetWalletTx(const Txid &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:543
void InitWalletFlags(uint64_t flags)
overwrite all flags by the given uint64_t flags must be uninitialised (or 0) only known flags may be ...
Definition wallet.cpp:1820
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
Definition wallet.cpp:1784
std::set< CWalletTx *, WalletTxOrderComparator > GetMalleatedVariants(const CWalletTx &wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Collects all wallet txs that differ from wtx only in their scriptSigs (i.e.
Definition wallet.cpp:735
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition wallet.cpp:850
void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, and write to database.
Definition wallet.cpp:687
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition wallet.cpp:1725
DBErrors ReorderTransactions()
Definition wallet.cpp:925
bool IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:1679
void UpgradeDescriptorCache() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade DescriptorCaches.
Definition wallet.cpp:552
void SetSpentKeyState(WalletBatch &batch, const Txid &hash, unsigned int n, bool used, std::set< CTxDestination > &tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition wallet.cpp:1046
CAmount GetDebit(const CTxIn &txin) const
Returns amount of debit, i.e.
Definition wallet.cpp:1663
void MarkConflicted(const uint256 &hashBlock, int conflicting_height, const Txid &hashTx)
Mark a transaction (and its in-wallet descendants) as conflicting with a particular block.
Definition wallet.cpp:1372
void transactionAddedToMempool(const CTransactionRef &tx) override
Definition wallet.cpp:1458
void Close()
Close wallet database.
Definition wallet.cpp:730
const std::string request
#define LogInfo(...)
Definition log.h:125
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
btcsignals is a simple mechanism for signaling events to multiple subscribers.
Definition handler.h:11
PSBTError
Definition types.h:19
TxBroadcast
How to broadcast a local transaction.
Definition types.h:35
void format(std::ostream &out, FormatStringCheck< sizeof...(Args)> fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE
Pre-calculated constants for input size estimation in virtual size.
Definition wallet.h:143
constexpr bool DEFAULT_WALLET_RBF
-walletrbf default
Definition wallet.h:132
constexpr bool DEFAULT_WALLETCROSSCHAIN
Definition wallet.h:135
std::variant< TxStateConfirmed, TxStateInMempool, TxStateInactive > SyncTxState
Subset of states transaction sync logic is implemented to handle.
Definition transaction.h:84
constexpr CAmount HIGH_APS_FEE
discourage APS fee higher than this amount
Definition wallet.h:122
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:374
constexpr unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
constexpr bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition wallet.h:128
void MaybeResendWalletTxs(WalletContext &context)
Called periodically by the schedule thread.
Definition wallet.cpp:2184
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition wallet.cpp:204
util::Result< MigrationResult > MigrateLegacyToDescriptor(const std::string &wallet_name, const SecureString &passphrase, WalletContext &context, bool load_wallet)
Do all steps to migrate a legacy wallet to a descriptor wallet.
Definition wallet.cpp:4311
constexpr CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition wallet.h:137
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
Definition crypter.h:63
constexpr CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
Definition wallet.h:120
DBErrors
Overview of wallet database classes:
Definition walletdb.h:46
bool AddWalletSetting(interfaces::Chain &chain, const std::string &wallet_name)
Add wallet name to persistent configuration so it will be loaded on startup.
Definition wallet.cpp:99
bool RemoveWalletSetting(interfaces::Chain &chain, const std::string &wallet_name)
Remove wallet name from persistent configuration so it will not be loaded on startup.
Definition wallet.cpp:112
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
Definition wallet.cpp:226
constexpr bool DEFAULT_DISABLE_WALLET
Definition wallet.h:134
constexpr CAmount WALLET_INCREMENTAL_RELAY_FEE
minimum recommended increment for replacement txs
Definition wallet.h:124
constexpr CAmount HIGH_TX_FEE_PER_KB
Discourage users to set fees higher than this amount (in satoshis) per kB.
Definition wallet.h:139
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition wallet.h:148
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
Definition wallet.cpp:2996
void NotifyWalletLoaded(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition wallet.cpp:233
constexpr CAmount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition wallet.h:141
constexpr CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition wallet.h:106
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, bool load_after_restore, bool allow_unnamed)
Definition wallet.cpp:459
std::string PurposeToString(AddressPurpose p)
Definition wallet.h:280
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
Definition types.h:44
@ REFUND
Never set in current code may be present in older wallet databases.
Definition types.h:47
std::map< CKeyID, CKey > KeyMap
constexpr uint64_t KNOWN_WALLET_FLAGS
Definition wallet.h:150
std::variant< TxStateConfirmed, TxStateInMempool, TxStateBlockConflicted, TxStateInactive, TxStateUnrecognized > TxState
All possible CWalletTx states.
Definition transaction.h:81
constexpr CAmount DEFAULT_CONSOLIDATE_FEERATE
-consolidatefeerate default
Definition wallet.h:112
constexpr CAmount DEFAULT_TRANSACTION_MINFEE
-mintxfee default
Definition wallet.h:110
constexpr CAmount DEFAULT_DISCARD_FEE
-discardfee default
Definition wallet.h:108
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:387
@ WALLET_FLAG_EXTERNAL_SIGNER
Indicates that the wallet needs an external signer.
Definition walletutil.h:56
@ WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
Definition walletutil.h:27
@ WALLET_FLAG_KEY_ORIGIN_METADATA
Definition walletutil.h:24
@ WALLET_FLAG_AVOID_REUSE
Definition walletutil.h:21
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition walletutil.h:53
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition walletutil.h:30
@ WALLET_FLAG_BLANK_WALLET
Definition walletutil.h:50
std::optional< AddressPurpose > PurposeFromString(std::string_view s)
Definition wallet.h:290
void WaitForDeleteWallet(std::shared_ptr< CWallet > &&wallet)
Definition wallet.cpp:264
static const std::map< std::string, WalletFlags > STRING_TO_WALLET_FLAG
Definition wallet.h:172
constexpr uint64_t MUTABLE_WALLET_FLAGS
Definition wallet.h:159
std::shared_ptr< CWallet > GetWallet(WalletContext &context, const std::string &name)
Definition wallet.cpp:217
util::Result< fs::path > GetWalletPath(const std::string &name)
Determine the path that the wallet is stored in.
Definition wallet.cpp:2957
static const std::map< WalletFlags, std::string > WALLET_FLAG_TO_STRING
Definition wallet.h:162
constexpr bool DEFAULT_WALLETBROADCAST
Definition wallet.h:133
std::shared_ptr< CWallet > GetDefaultWallet(WalletContext &context, size_t &count)
Definition wallet.cpp:210
constexpr bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition wallet.h:126
constexpr unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
Definition wallet.h:130
std::map< CKeyID, std::pair< CPubKey, std::vector< unsigned char > > > CryptedKeyMap
OutputType
Definition outputtype.h:18
std::shared_ptr< const CTransaction > CTransactionRef
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition secure.h:53
SigningResult
Definition signmessage.h:43
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition block.h:117
Definition key.h:232
A mutable version of CTransaction.
Information about chainstate that notifications are sent from.
Definition types.h:18
std::chrono::time_point< NodeClock > time_point
Definition time.h:28
Bilingual messages:
Definition translation.h:24
Instructions for how a PSBT should be signed or filled with information.
Definition types.h:31
A wrapper for a compile-time partially validated format string.
Definition string.h:96
Address book data.
Definition wallet.h:239
std::optional< AddressPurpose > purpose
Address purpose which was originally recorded for payment protocol support but now serves as a cached...
Definition wallet.h:254
void SetLabel(std::string name)
Definition wallet.h:277
std::string GetLabel() const
Definition wallet.h:276
bool previously_spent
Whether coins with this address have previously been spent.
Definition wallet.h:263
std::map< std::string, std::string > receive_requests
Map containing data about previously generated receive requests requesting funds to be sent to this a...
Definition wallet.h:272
std::optional< std::string > label
Address label which is always nullopt for change addresses.
Definition wallet.h:247
bool IsChange() const
Accessor methods.
Definition wallet.h:275
CAmount nAmount
Definition wallet.h:301
bool fSubtractFeeFromAmount
Definition wallet.h:302
CTxDestination dest
Definition wallet.h:300
std::optional< std::string > m_op_label
Definition wallet.h:768
std::optional< int > last_scanned_height
Definition wallet.h:651
struct containing information needed for migrating legacy wallets to descriptor wallets
std::optional< std::string > solvables_wallet_name
Definition wallet.h:1169
std::optional< std::string > watchonly_wallet_name
Definition wallet.h:1168
std::shared_ptr< CWallet > watchonly_wallet
Definition wallet.h:1171
std::string wallet_name
Definition wallet.h:1167
std::shared_ptr< CWallet > solvables_wallet
Definition wallet.h:1172
AnnotatedMixin< std::mutex > Mutex
Wrapped mutex: supports waiting but not recursive locking.
Definition sync.h:131
AnnotatedMixin< std::recursive_mutex > RecursiveMutex
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition sync.h:128
#define AssertLockHeld(cs)
Definition sync.h:144
std::vector< uint16_t > keys
#define EXCLUSIVE_LOCKS_REQUIRED(...)
#define LOCKS_EXCLUDED(...)
transaction_identifier< false > Txid
Txid commits to all transaction fields except the witness.
consteval auto _(util::TranslatedLiteral str)
Definition translation.h:79
ChangeType
General change type (added, updated, removed).
assert(!tx.IsCoinBase())
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition wallet.h:81
DatabaseStatus
Definition db.h:180