Bitcoin Core 29.99.0
P2P Digital Currency
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 <logging.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/fs.h>
26#include <util/hasher.h>
27#include <util/result.h>
28#include <util/string.h>
29#include <util/time.h>
30#include <util/ui_change_type.h>
31#include <wallet/crypter.h>
32#include <wallet/db.h>
34#include <wallet/transaction.h>
35#include <wallet/types.h>
36#include <wallet/walletutil.h>
37
38#include <atomic>
39#include <cassert>
40#include <cstddef>
41#include <cstdint>
42#include <functional>
43#include <limits>
44#include <map>
45#include <memory>
46#include <optional>
47#include <set>
48#include <string>
49#include <unordered_map>
50#include <utility>
51#include <vector>
52
53#include <boost/signals2/signal.hpp>
54
55class CKey;
56class CKeyID;
57class CPubKey;
58class Coin;
59class SigningProvider;
60enum class MemPoolRemovalReason;
61enum class SigningResult;
62namespace common {
63enum class PSBTError;
64} // namespace common
65namespace interfaces {
66class Wallet;
67}
68namespace wallet {
69class CWallet;
70class WalletBatch;
71enum class DBErrors : int;
72} // namespace wallet
73struct CBlockLocator;
74struct CExtKey;
76struct KeyOriginInfo;
78struct SignatureData;
79
80using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
81
82struct bilingual_str;
83
84namespace wallet {
85struct WalletContext;
86
89void WaitForDeleteWallet(std::shared_ptr<CWallet>&& wallet);
90
91bool AddWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
92bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start, std::vector<bilingual_str>& warnings);
93bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start);
94std::vector<std::shared_ptr<CWallet>> GetWallets(WalletContext& context);
95std::shared_ptr<CWallet> GetDefaultWallet(WalletContext& context, size_t& count);
96std::shared_ptr<CWallet> GetWallet(WalletContext& context, const std::string& name);
97std::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);
98std::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);
99std::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);
100std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, LoadWalletFn load_wallet);
101void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
102std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
103
109static const CAmount DEFAULT_DISCARD_FEE = 10000;
113static const CAmount DEFAULT_CONSOLIDATE_FEERATE{10000}; // 10 sat/vbyte
123constexpr CAmount HIGH_APS_FEE{COIN / 10000};
127static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
129static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS{true};
131static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
133static const bool DEFAULT_WALLET_RBF = true;
134static const bool DEFAULT_WALLETBROADCAST = true;
135static const bool DEFAULT_DISABLE_WALLET = false;
136static const bool DEFAULT_WALLETCROSSCHAIN = false;
144static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE = 91;
145
146class CCoinControl;
147
150
151static constexpr uint64_t KNOWN_WALLET_FLAGS =
159
160static constexpr uint64_t MUTABLE_WALLET_FLAGS =
162
163static const std::map<WalletFlags, std::string> WALLET_FLAG_TO_STRING{
164 {WALLET_FLAG_AVOID_REUSE, "avoid_reuse"},
165 {WALLET_FLAG_BLANK_WALLET, "blank"},
166 {WALLET_FLAG_KEY_ORIGIN_METADATA, "key_origin_metadata"},
167 {WALLET_FLAG_LAST_HARDENED_XPUB_CACHED, "last_hardened_xpub_cached"},
168 {WALLET_FLAG_DISABLE_PRIVATE_KEYS, "disable_private_keys"},
169 {WALLET_FLAG_DESCRIPTORS, "descriptor_wallet"},
170 {WALLET_FLAG_EXTERNAL_SIGNER, "external_signer"}
171};
172
173static const std::map<std::string, WalletFlags> STRING_TO_WALLET_FLAG{
181};
182
199{
200protected:
202 const CWallet* const pwallet;
207 int64_t nIndex{-1};
211 bool fInternal{false};
212
213public:
217 , type(type) { }
218
221
224 {
226 }
227
231 void ReturnDestination();
233 void KeepDestination();
234};
235
240{
248 std::optional<std::string> label;
249
255 std::optional<AddressPurpose> purpose;
256
264 bool previously_spent{false};
265
273 std::map<std::string, std::string> receive_requests{};
274
276 bool IsChange() const { return !label.has_value(); }
277 std::string GetLabel() const { return label ? *label : std::string{}; }
278 void SetLabel(std::string name) { label = std::move(name); }
279};
280
281inline std::string PurposeToString(AddressPurpose p)
282{
283 switch(p) {
284 case AddressPurpose::RECEIVE: return "receive";
285 case AddressPurpose::SEND: return "send";
286 case AddressPurpose::REFUND: return "refund";
287 } // no default case so the compiler will warn when a new enum as added
288 assert(false);
289}
290
291inline std::optional<AddressPurpose> PurposeFromString(std::string_view s)
292{
293 if (s == "receive") return AddressPurpose::RECEIVE;
294 else if (s == "send") return AddressPurpose::SEND;
295 else if (s == "refund") return AddressPurpose::REFUND;
296 return {};
297}
298
300{
304};
305
306class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime
311{
312private:
314
315 bool Unlock(const CKeyingMaterial& vMasterKeyIn);
316
317 std::atomic<bool> fAbortRescan{false};
318 std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
319 std::atomic<bool> m_scanning_with_passphrase{false};
320 std::atomic<SteadyClock::time_point> m_scanning_start{SteadyClock::time_point{}};
321 std::atomic<double> m_scanning_progress{0};
323
329 // Local time that the tip block was received. Used to schedule wallet rebroadcasts.
330 std::atomic<int64_t> m_best_block_time {0};
331
332 // First created key time. Used to skip blocks prior to this time.
333 // 'std::numeric_limits<int64_t>::max()' if wallet is blank.
334 std::atomic<int64_t> m_birth_time{std::numeric_limits<int64_t>::max()};
335
341 typedef std::unordered_multimap<COutPoint, Txid, SaltedOutpointHasher> TxSpends;
343 void AddToSpends(const COutPoint& outpoint, const Txid& txid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
345
362 bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const SyncTxState& state, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
363
365 void MarkConflicted(const uint256& hashBlock, int conflicting_height, const Txid& hashTx);
366
367 enum class TxUpdate { UNCHANGED, CHANGED, NOTIFY_CHANGED };
368
369 using TryUpdatingStateFn = std::function<TxUpdate(CWalletTx& wtx)>;
370
372 void RecursiveUpdateTxState(const Txid& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
373 void RecursiveUpdateTxState(WalletBatch* batch, const Txid& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
374
377
378 void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
379
380 bool SyncTransaction(const CTransactionRef& tx, const SyncTxState& state, bool update_tx = true, bool rescanning_old_block = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
381
383 std::atomic<uint64_t> m_wallet_flags{0};
384
385 bool SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& strPurpose);
386
388 void UnsetWalletFlagWithDB(WalletBatch& batch, uint64_t flag);
389
391 void UnsetBlankWalletFlag(WalletBatch& batch) override;
392
395
397 std::string m_name;
398
400 std::unique_ptr<WalletDatabase> m_database;
401
409 uint256 m_last_block_processed GUARDED_BY(cs_wallet);
410
416 int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
417
418 std::map<OutputType, ScriptPubKeyMan*> m_external_spk_managers;
419 std::map<OutputType, ScriptPubKeyMan*> m_internal_spk_managers;
420
421 // Indexed by a unique identifier produced by each ScriptPubKeyMan using
422 // ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal structure
423 std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
424
425 // Appends spk managers into the main 'm_spk_managers'.
426 // Must be the only method adding data to it.
427 void AddScriptPubKeyMan(const uint256& id, std::unique_ptr<ScriptPubKeyMan> spkm_man);
428
429 // Same as 'AddActiveScriptPubKeyMan' but designed for use within a batch transaction context
430 void AddActiveScriptPubKeyManWithDb(WalletBatch& batch, uint256 id, OutputType type, bool internal);
431
433 void SetWalletFlagWithDB(WalletBatch& batch, uint64_t flags);
434
436 std::unordered_map<CScript, std::vector<ScriptPubKeyMan*>, SaltedSipHasher> m_cached_spks;
437
439 std::unordered_map<COutPoint, WalletTXO, SaltedOutpointHasher> m_txos GUARDED_BY(cs_wallet);
440
446 static bool AttachChain(const std::shared_ptr<CWallet>& wallet, interfaces::Chain& chain, const bool rescan_required, bilingual_str& error, std::vector<bilingual_str>& warnings);
447
449
450 // Update last block processed in memory only
451 void SetLastBlockProcessedInMem(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
452
454 void UpdateTrucSiblingConflicts(const CWalletTx& parent_wtx, const Txid& child_txid, bool add_conflict) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
455
456public:
462
463 WalletDatabase& GetDatabase() const override
464 {
465 assert(static_cast<bool>(m_database));
466 return *m_database;
467 }
468
471 const std::string& GetName() const { return m_name; }
472
473 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
475 unsigned int nMasterKeyMaxID = 0;
476
478 CWallet(interfaces::Chain* chain, const std::string& name, std::unique_ptr<WalletDatabase> database)
479 : m_chain(chain),
480 m_name(name),
481 m_database(std::move(database))
482 {
483 }
484
486 {
487 // Should not have slots connected at this point.
488 assert(NotifyUnload.empty());
489 }
490
491 bool IsCrypted() const;
492 bool IsLocked() const override;
493 bool Lock();
494
496 bool HaveChain() const { return m_chain ? true : false; }
497
500 std::unordered_map<Txid, CWalletTx, SaltedTxidHasher> mapWallet GUARDED_BY(cs_wallet);
501
502 typedef std::multimap<int64_t, CWalletTx*> TxItems;
504
505 int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
506
507 std::map<CTxDestination, CAddressBookData> m_address_book GUARDED_BY(cs_wallet);
508 const CAddressBookData* FindAddressBookEntry(const CTxDestination&, bool allow_change = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
509
516 std::map<COutPoint, bool> m_locked_coins GUARDED_BY(cs_wallet);
517
520
522 interfaces::Chain& chain() const { assert(m_chain); return *m_chain; }
523
525
526 std::set<Txid> GetTxConflicts(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
527
528 const std::unordered_map<COutPoint, WalletTXO, SaltedOutpointHasher>& GetTXOs() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return m_txos; };
529 std::optional<WalletTXO> GetTXO(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
530
535
550
558
559 bool IsSpent(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
560
561 // Whether this or any known scriptPubKey with the same single key has been spent.
562 bool IsSpentKey(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
563 void SetSpentKeyState(WalletBatch& batch, const Txid& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
564
567
568 bool IsLockedCoin(const COutPoint& output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
569 void LoadLockedCoin(const COutPoint& coin, bool persistent) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
570 bool LockCoin(const COutPoint& output, bool persist) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
573 void ListLockedCoins(std::vector<COutPoint>& vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
574
575 /*
576 * Rescan abort properties
577 */
578 void AbortRescan() { fAbortRescan = true; }
579 bool IsAbortingRescan() const { return fAbortRescan; }
580 bool IsScanning() const { return fScanningWallet; }
582 SteadyClock::duration ScanningDuration() const { return fScanningWallet ? SteadyClock::now() - m_scanning_start.load() : SteadyClock::duration{}; }
583 double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }
584
587
591 void LoadAddressReceiveRequest(const CTxDestination& dest, const std::string& id, const std::string& request) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
592
594 int64_t nRelockTime GUARDED_BY(cs_wallet){0};
595
596 // Used to prevent concurrent calls to walletpassphrase RPC.
598 // Used to prevent deleting the passphrase from memory when it is still in use.
600
601 bool Unlock(const SecureString& strWalletPassphrase);
602 bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
603 bool EncryptWallet(const SecureString& strWalletPassphrase);
604
605 unsigned int ComputeTimeSmart(const CWalletTx& wtx, bool rescanning_old_block) const;
606
613
614 void MarkDirty();
615
622 using UpdateWalletTxFn = std::function<bool(CWalletTx& wtx, bool new_tx)>;
623
628 CWalletTx* AddToWallet(CTransactionRef tx, const TxState& state, const UpdateWalletTxFn& update_wtx=nullptr, bool rescanning_old_block = false);
629 bool LoadToWallet(const Txid& hash, const UpdateWalletTxFn& fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
630 void transactionAddedToMempool(const CTransactionRef& tx) override;
631 void blockConnected(ChainstateRole role, const interfaces::BlockInfo& block) override;
632 void blockDisconnected(const interfaces::BlockInfo& block) override;
633 void updatedBlockTip() override;
634 int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update);
635
636 struct ScanResult {
637 enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
638
643 std::optional<int> last_scanned_height;
644
650 };
651 ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate, const bool save_progress);
656 bool ShouldResend() const;
657 void ResubmitWalletTransactions(bool relay, bool force);
658
659 OutputType TransactionChangeType(const std::optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const;
660
664 bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const;
665 SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const;
666
682 std::optional<common::PSBTError> FillPSBT(PartiallySignedTransaction& psbtx,
683 bool& complete,
684 std::optional<int> sighash_type = std::nullopt,
685 bool sign = true,
686 bool bip32derivs = true,
687 size_t* n_signed = nullptr,
688 bool finalize = true) const;
689
699 void CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm);
700
702 bool SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string, bool relay) const
704
706 void MaybeUpdateBirthTime(int64_t time);
707
722
726
732
742 std::optional<OutputType> m_default_change_type{};
745
748
751
753 bool TopUpKeyPool(unsigned int kpSize = 0);
754
755 // Filter struct for 'ListAddrBookAddresses'
757 // Fetch addresses with the provided label
758 std::optional<std::string> m_op_label{std::nullopt};
759 // Don't include change addresses by default
760 bool ignore_change{true};
761 };
762
766 std::vector<CTxDestination> ListAddrBookAddresses(const std::optional<AddrBookFilter>& filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
767
771 std::set<std::string> ListAddrBookLabels(const std::optional<AddressPurpose> purpose) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
772
777 using ListAddrBookFunc = std::function<void(const CTxDestination& dest, const std::string& label, bool is_change, const std::optional<AddressPurpose> purpose)>;
779
784 void MarkDestinationsDirty(const std::set<CTxDestination>& destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
785
786 util::Result<CTxDestination> GetNewDestination(const OutputType type, const std::string label);
788
792 CAmount GetDebit(const CTxIn& txin) const;
793 bool IsMine(const CTxOut& txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
795 bool IsMine(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
797 bool IsFromMe(const CTransaction& tx) const;
798 CAmount GetDebit(const CTransaction& tx) const;
799
801
803 util::Result<void> RemoveTxs(std::vector<Txid>& txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
804 util::Result<void> RemoveTxs(WalletBatch& batch, std::vector<Txid>& txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
805
806 bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& purpose);
807
808 bool DelAddressBook(const CTxDestination& address);
809 bool DelAddressBookWithDB(WalletBatch& batch, const CTxDestination& address);
810
813
814 std::vector<std::string> GetAddressReceiveRequests() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
815 bool SetAddressReceiveRequest(WalletBatch& batch, const CTxDestination& dest, const std::string& id, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
817
819
822
825
827 void Close();
828
830 boost::signals2::signal<void ()> NotifyUnload;
831
836 boost::signals2::signal<void(const CTxDestination& address,
837 const std::string& label, bool isMine,
838 AddressPurpose purpose, ChangeType status)>
840
845 boost::signals2::signal<void(const Txid& hashTx, ChangeType status)> NotifyTransactionChanged;
846
848 boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
849
851 boost::signals2::signal<void ()> NotifyCanGetAddressesChanged;
852
857 boost::signals2::signal<void (CWallet* wallet)> NotifyStatusChanged;
858
862 void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
863
865 bool TransactionCanBeAbandoned(const Txid& hashTx) const;
866
867 /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
868 bool AbandonTransaction(const Txid& hashTx);
870
872 bool MarkReplaced(const Txid& originalHash, const Txid& newHash);
873
874 /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
875 static std::shared_ptr<CWallet> Create(WalletContext& context, const std::string& name, std::unique_ptr<WalletDatabase> database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector<bilingual_str>& warnings);
876
881 void postInitProcess();
882
883 bool BackupWallet(const std::string& strDest) const;
884
885 /* Returns true if HD is enabled */
886 bool IsHDEnabled() const;
887
888 /* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */
889 bool CanGetAddresses(bool internal = false) const;
890
891 /* Returns the time of the first created key or, in case of an import, it could be the time of the first received transaction */
892 int64_t GetBirthTime() const { return m_birth_time; }
893
900 void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main) EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet);
901
903 void SetWalletFlag(uint64_t flags);
904
906 void UnsetWalletFlag(uint64_t flag);
907
909 bool IsWalletFlagSet(uint64_t flag) const override;
910
914 void InitWalletFlags(uint64_t flags);
916 bool LoadWalletFlags(uint64_t flags);
918 uint64_t GetWalletFlags() const;
919
921 std::string LogName() const override
922 {
923 std::string name{GetName()};
924 return name.empty() ? "default wallet" : name;
925 };
926
928 std::string DisplayName() const
929 {
930 std::string name{GetName()};
931 return name.empty() ? _("default wallet") : name;
932 };
933
935 template <typename... Params>
936 void WalletLogPrintf(util::ConstevalFormatString<sizeof...(Params)> wallet_fmt, const Params&... params) const
937 {
938 LogInfo("[%s] %s", LogName(), tfm::format(wallet_fmt, params...));
939 };
940
942 std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
943 bool IsActiveScriptPubKeyMan(const ScriptPubKeyMan& spkm) const;
944
946 std::set<ScriptPubKeyMan*> GetAllScriptPubKeyMans() const;
947
949 ScriptPubKeyMan* GetScriptPubKeyMan(const OutputType& type, bool internal) const;
950
952 std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script) const;
955
957 std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
958 std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
959
961 std::vector<WalletDescriptor> GetWalletDescriptors(const CScript& script) const;
962
966
969
970 bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const override;
971
972 bool HasEncryptionKeys() const override;
973 bool HaveCryptedKeys() const;
974
977 {
979 assert(m_last_block_processed_height >= 0);
980 return m_last_block_processed_height;
981 };
983 {
985 assert(m_last_block_processed_height >= 0);
986 return m_last_block_processed;
987 }
989 void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
992
995
998
1003 void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1004
1009 void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1010
1015 void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1016
1022
1025
1028
1032 std::optional<bool> IsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const;
1033
1035 util::Result<std::reference_wrapper<DescriptorScriptPubKeyMan>> AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1036
1043
1046
1050
1052 bool CanGrindR() const;
1053
1055 void CacheNewScriptPubKeys(const std::set<CScript>& spks, ScriptPubKeyMan* spkm);
1056
1057 void TopUpCallback(const std::set<CScript>& spks, ScriptPubKeyMan* spkm) override;
1058
1061
1064 std::optional<CKey> GetKey(const CKeyID& keyid) const;
1065};
1066
1071void MaybeResendWalletTxs(WalletContext& context);
1072
1075{
1076private:
1077 using Clock = std::chrono::steady_clock;
1078 using NowFn = std::function<Clock::time_point()>;
1080 bool m_could_reserve{false};
1082public:
1084
1085 bool reserve(bool with_passphrase = false)
1086 {
1087 assert(!m_could_reserve);
1088 if (m_wallet.fScanningWallet.exchange(true)) {
1089 return false;
1090 }
1091 m_wallet.m_scanning_with_passphrase.exchange(with_passphrase);
1092 m_wallet.m_scanning_start = SteadyClock::now();
1093 m_wallet.m_scanning_progress = 0;
1094 m_could_reserve = true;
1095 return true;
1096 }
1097
1098 bool isReserved() const
1099 {
1100 return (m_could_reserve && m_wallet.fScanningWallet);
1101 }
1102
1103 Clock::time_point now() const { return m_now ? m_now() : Clock::now(); };
1104
1105 void setNow(NowFn now) { m_now = std::move(now); }
1106
1108 {
1109 if (m_could_reserve) {
1110 m_wallet.fScanningWallet = false;
1111 m_wallet.m_scanning_with_passphrase = false;
1112 }
1113 }
1114};
1115
1117bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
1118
1120bool RemoveWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
1121
1123 std::string wallet_name;
1124 std::shared_ptr<CWallet> wallet;
1125 std::shared_ptr<CWallet> watchonly_wallet;
1126 std::shared_ptr<CWallet> solvables_wallet;
1127 fs::path backup_path;
1128};
1129
1131[[nodiscard]] util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& wallet_name, const SecureString& passphrase, WalletContext& context);
1133[[nodiscard]] util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet> local_wallet, const SecureString& passphrase, WalletContext& context);
1134} // namespace wallet
1135
1136#endif // BITCOIN_WALLET_WALLET_H
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Definition: addresstype.h:143
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition: amount.h:15
int flags
Definition: bitcoin-tx.cpp:529
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:35
An encapsulated private key.
Definition: key.h:35
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:24
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:29
An encapsulated public key.
Definition: pubkey.h:34
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:413
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:296
An input of a transaction.
Definition: transaction.h:67
An output of a transaction.
Definition: transaction.h:150
A UTXO entry.
Definition: coins.h:33
An interface to be implemented by keystores that support signing.
Chain notifications.
Definition: chain.h:312
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:130
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:311
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:2516
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::optional< AddressPurpose > &purpose)
Definition: wallet.cpp:2404
std::atomic< bool > fAbortRescan
Definition: wallet.h:317
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:2479
bool HaveChain() const
Interface to assert chain access.
Definition: wallet.h:496
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:860
bool m_signal_rbf
Definition: wallet.h:713
int64_t GetBirthTime() const
Definition: wallet.h:892
bool IsCrypted() const
Definition: wallet.cpp:3278
std::atomic< SteadyClock::time_point > m_scanning_start
Definition: wallet.h:320
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2468
std::function< bool(CWalletTx &wtx, bool new_tx)> UpdateWalletTxFn
Callback for updating transaction metadata in mapWallet.
Definition: wallet.h:622
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:830
CAmount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
Definition: wallet.h:744
std::optional< WalletTXO > GetTXO(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:4464
bool IsActiveScriptPubKeyMan(const ScriptPubKeyMan &spkm) const
Definition: wallet.cpp:3338
OutputType m_default_address_type
Definition: wallet.h:735
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...
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:725
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Adds the active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3601
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Loads an active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3615
std::unique_ptr< WalletDatabase > m_database
Internal database handle.
Definition: wallet.h:400
bool IsLockedCoin(const COutPoint &output) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2663
bool SignTransaction(CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Fetch the inputs and sign with SIGHASH_ALL.
Definition: wallet.cpp:2088
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > database)
Construct wallet with specified name and database implementation.
Definition: wallet.h:478
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:777
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
Get the SigningProvider for a script.
Definition: wallet.cpp:3391
bool IsTxImmatureCoinBase(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3270
void RefreshAllTXOs() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Cache outputs that belong to the wallet for all transactions in the wallet.
Definition: wallet.cpp:4456
void AddActiveScriptPubKeyManWithDb(WalletBatch &batch, uint256 id, OutputType type, bool internal)
Definition: wallet.cpp:3607
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:4385
DBErrors LoadWallet()
Definition: wallet.cpp:2289
std::set< ScriptPubKeyMan * > GetActiveScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers.
Definition: wallet.cpp:3324
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3218
CFeeRate m_pay_tx_fee
Definition: wallet.h:708
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition: wallet.cpp:3228
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:3244
std::optional< common::PSBTError > FillPSBT(PartiallySignedTransaction &psbtx, bool &complete, std::optional< int > sighash_type=std::nullopt, bool sign=true, bool bip32derivs=true, size_t *n_signed=nullptr, bool finalize=true) const
Fills out a PSBT with information from the wallet.
Definition: wallet.cpp:2122
unsigned int nMasterKeyMaxID
Definition: wallet.h:475
bool IsScanning() const
Definition: wallet.h:580
bool SetAddressReceiveRequest(WalletBatch &batch, const CTxDestination &dest, const std::string &id, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2792
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition: wallet.h:976
std::atomic< double > m_scanning_progress
Definition: wallet.h:321
LegacyDataSPKM * GetLegacyDataSPKM() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
Definition: wallet.cpp:3422
CAmount m_max_aps_fee
The maximum fee amount we're willing to pay to prioritize partial spend avoidance.
Definition: wallet.h:734
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:2539
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
Definition: wallet.cpp:3652
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
Definition: wallet.h:418
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,...
DescriptorScriptPubKeyMan & LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
Definition: wallet.cpp:3492
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet)
const std::unordered_map< COutPoint, WalletTXO, SaltedOutpointHasher > & GetTXOs() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:528
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:862
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:3821
std::optional< OutputType > m_default_change_type
Default output type for change outputs.
Definition: wallet.h:742
bool HaveCryptedKeys() const
Definition: wallet.cpp:3476
int64_t nOrderPosNext GUARDED_BY(cs_wallet)=0
LegacyDataSPKM * GetOrCreateLegacyDataSPKM()
Definition: wallet.cpp:3442
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition: wallet.h:522
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:471
bool Unlock(const CKeyingMaterial &vMasterKeyIn)
Definition: wallet.cpp:3309
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:3747
bool BackupWallet(const std::string &strDest) const
Definition: wallet.cpp:3238
std::unique_ptr< interfaces::Handler > m_chain_notifications_handler
Registered interfaces::Chain::Notifications handler.
Definition: wallet.h:519
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
Definition: wallet.h:419
std::string m_name
Wallet name: relative directory name or "" for default wallet.
Definition: wallet.h:397
bool SetAddressPreviouslySpent(WalletBatch &batch, const CTxDestination &dest, bool used) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2751
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:2314
double ScanningProgress() const
Definition: wallet.h:583
SteadyClock::duration ScanningDuration() const
Definition: wallet.h:582
util::Result< CTxDestination > GetNewDestination(const OutputType type, const std::string label)
Definition: wallet.cpp:2489
RecursiveMutex m_relock_mutex
Definition: wallet.h:599
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:750
std::vector< std::string > GetAddressReceiveRequests() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2781
std::vector< WalletDescriptor > GetWalletDescriptors(const CScript &script) const
Get the wallet descriptors for a script.
Definition: wallet.cpp:3410
bool fBroadcastTransactions
Whether this wallet will submit newly created transactions to the node's mempool and prompt rebroadca...
Definition: wallet.h:328
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2456
void CacheNewScriptPubKeys(const std::set< CScript > &spks, ScriptPubKeyMan *spkm)
Add scriptPubKeys for this ScriptPubKeyMan into the scriptPubKey cache.
Definition: wallet.cpp:4378
int GetTxBlocksToMaturity(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3258
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:936
bool HasEncryptionKeys() const override
Definition: wallet.cpp:3471
static std::shared_ptr< CWallet > Create(WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:2839
bool CanGrindR() const
Whether the (external) signer performs R-value signature grinding.
Definition: wallet.cpp:4051
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:921
std::optional< bool > IsInternalScriptPubKeyMan(ScriptPubKeyMan *spk_man) const
Returns whether the provided ScriptPubKeyMan is internal.
Definition: wallet.cpp:3667
void SetNextResend()
Set the next time this wallet should resend transactions to 12-36 hours from now, ~1 day on average.
Definition: wallet.h:654
void LoadLockedCoin(const COutPoint &coin, bool persistent) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2619
TxItems wtxOrdered
Definition: wallet.h:503
std::atomic< bool > m_scanning_with_passphrase
Definition: wallet.h:319
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Definition: wallet.cpp:2176
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:712
MasterKeyMap mapMasterKeys
Definition: wallet.h:474
boost::signals2::signal< void(const Txid &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:845
unsigned int m_confirm_target
Definition: wallet.h:709
CFeeRate m_consolidate_feerate
When the actual feerate is less than the consolidate feerate, we will tend to make transactions which...
Definition: wallet.h:731
util::Result< void > ApplyMigrationData(WalletBatch &local_wallet_batch, MigrationData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Adds the ScriptPubKeyMans given in MigrationData to this wallet, removes LegacyScriptPubKeyMan,...
Definition: wallet.cpp:3840
NodeClock::time_point m_next_resend
The next scheduled rebroadcast of wallet transactions.
Definition: wallet.h:325
WalletDatabase & GetDatabase() const override
Definition: wallet.h:463
std::optional< CKey > GetKey(const CKeyID &keyid) const
Find the private key for the given key id from the wallet's descriptors, if available Returns nullopt...
Definition: wallet.cpp:4412
bool EraseAddressReceiveRequest(WalletBatch &batch, const CTxDestination &dest, const std::string &id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2799
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::optional< AddressPurpose > &strPurpose)
Definition: wallet.cpp:2368
void WriteBestBlock() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Write the current best block to database.
Definition: wallet.cpp:4427
void AbortRescan()
Definition: wallet.h:578
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:848
bool DelAddressBookWithDB(WalletBatch &batch, const CTxDestination &address)
Definition: wallet.cpp:2417
std::string DisplayName() const
Return wallet name for display, like LogName() but translates "default wallet" string.
Definition: wallet.h:928
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:2770
Mutex m_unlock_mutex
Definition: wallet.h:597
void AddScriptPubKeyMan(const uint256 &id, std::unique_ptr< ScriptPubKeyMan > spkm_man)
Definition: wallet.cpp:3432
void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Remove specified ScriptPubKeyMan from set of active SPK managers.
Definition: wallet.cpp:3635
std::atomic< uint64_t > m_wallet_flags
WalletFlags set on this wallet.
Definition: wallet.h:383
interfaces::Chain * m_chain
Interface for accessing chain state.
Definition: wallet.h:394
bool LockCoin(const COutPoint &output, bool persist) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2625
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:721
std::set< CExtPubKey > GetActiveHDPubKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Retrieve the xpubs in use by the active descriptors.
Definition: wallet.cpp:4391
std::set< std::string > ListAddrBookLabels(const std::optional< AddressPurpose > purpose) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Retrieve all the known labels in the address book.
Definition: wallet.cpp:2555
bool IsLocked() const override
Definition: wallet.cpp:3283
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:473
OutputType TransactionChangeType(const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
Definition: wallet.cpp:2189
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition: wallet.h:851
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
Definition: wallet.cpp:3349
void RefreshTXOsFromTx(const CWalletTx &wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Cache outputs that belong to the wallet from a single transaction.
Definition: wallet.cpp:4442
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:2700
TxSpends mapTxSpends GUARDED_BY(cs_wallet)
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:2669
bool IsAbortingRescan() const
Definition: wallet.h:579
void CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector< std::pair< std::string, std::string > > orderForm)
Submit the transaction to the node's mempool and then relay to peers.
Definition: wallet.cpp:2250
bool UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2651
util::Result< CTxDestination > GetNewChangeDestination(const OutputType type)
Definition: wallet.cpp:2505
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
Definition: wallet.cpp:3358
bool IsAddressPreviouslySpent(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2775
bool WithEncryptionKey(std::function< bool(const CKeyingMaterial &)> cb) const override
Pass the encryption key to cb().
Definition: wallet.cpp:3465
uint256 GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:982
bool m_allow_fallback_fee
will be false if -fallbackfee=0
Definition: wallet.h:714
int64_t m_keypool_size
Number of pre-generated keys/scripts by each spkm (part of the look-ahead process,...
Definition: wallet.h:747
RecursiveMutex cs_wallet
Main wallet lock.
Definition: wallet.h:461
void ForEachAddrBookEntry(const ListAddrBookFunc &func) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2530
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
Definition: wallet.cpp:3484
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:2410
CFeeRate m_min_fee
Override with -mintxfee.
Definition: wallet.h:715
std::atomic< int64_t > m_best_block_time
Definition: wallet.h:330
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:436
void SetupLegacyScriptPubKeyMan()
Make a Legacy(Data)SPKM and set it for all types, internal, and external.
Definition: wallet.cpp:3448
static bool AttachChain(const std::shared_ptr< CWallet > &wallet, interfaces::Chain &chain, const 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:3098
boost::signals2::signal< void(const CTxDestination &address, const std::string &label, bool isMine, AddressPurpose purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition: wallet.h:839
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:502
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:3534
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: wallet.h:857
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3550
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:3504
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
Definition: wallet.h:423
std::function< TxUpdate(CWalletTx &wtx)> TryUpdatingStateFn
Definition: wallet.h:369
bool UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2636
std::atomic< int64_t > m_birth_time
Definition: wallet.h:334
void LoadAddressPreviouslySpent(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Marks destination as previously spent.
Definition: wallet.cpp:2765
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:3686
std::atomic< bool > fScanningWallet
Definition: wallet.h:318
std::set< ScriptPubKeyMan * > GetScriptPubKeyMans(const CScript &script) const
Get all the ScriptPubKeyMans for a script.
Definition: wallet.cpp:3368
util::Result< void > DisplayAddress(const CTxDestination &dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Display address on an external signer.
Definition: wallet.cpp:2604
bool IsScanningWithPassphrase() const
Definition: wallet.h:581
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:341
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:195
A wrapper to reserve an address from a wallet.
Definition: wallet.h:199
const CWallet *const pwallet
The wallet to reserve from.
Definition: wallet.h:202
void KeepDestination()
Keep the address. Do not return its key to the keypool when this object goes out of scope.
Definition: wallet.cpp:2586
CTxDestination address
The destination.
Definition: wallet.h:209
bool fInternal
Whether this is from the internal (change output) keypool.
Definition: wallet.h:211
~ReserveDestination()
Destructor. If a key has been reserved and not KeepKey'ed, it will be returned to the keypool.
Definition: wallet.h:223
ReserveDestination(CWallet *pwallet, OutputType type)
Construct a ReserveDestination object. This does NOT reserve an address yet.
Definition: wallet.h:215
void ReturnDestination()
Return reserved address.
Definition: wallet.cpp:2595
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called.
Definition: wallet.h:204
ReserveDestination & operator=(const ReserveDestination &)=delete
int64_t nIndex
The index of the address's key in the keypool.
Definition: wallet.h:207
OutputType const type
Definition: wallet.h:205
util::Result< CTxDestination > GetReservedDestination(bool internal)
Reserve an address.
Definition: wallet.cpp:2569
ReserveDestination(const ReserveDestination &)=delete
Access to the wallet database.
Definition: walletdb.h:190
An instance of this class represents one database.
Definition: db.h:130
Descriptor with some wallet metadata.
Definition: walletutil.h:64
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1075
std::function< Clock::time_point()> NowFn
Definition: wallet.h:1078
std::chrono::steady_clock Clock
Definition: wallet.h:1077
WalletRescanReserver(CWallet &w)
Definition: wallet.h:1083
Clock::time_point now() const
Definition: wallet.h:1103
void setNow(NowFn now)
Definition: wallet.h:1105
bool reserve(bool with_passphrase=false)
Definition: wallet.h:1085
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:966
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
Definition: wallet.cpp:894
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:1312
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:1234
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:666
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:595
bool AbandonTransaction(const Txid &hashTx)
Definition: wallet.cpp:1244
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:683
void SetWalletFlagWithDB(WalletBatch &batch, uint64_t flags)
Store wallet flags.
Definition: wallet.cpp:1682
uint64_t GetWalletFlags() const
Retrieve all of the wallet's flags.
Definition: wallet.cpp:1742
void updatedBlockTip() override
Definition: wallet.cpp:1556
bool TransactionCanBeAbandoned(const Txid &hashTx) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1210
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:1676
void blockConnected(ChainstateRole role, const interfaces::BlockInfo &block) override
Definition: wallet.cpp:1480
void MaybeUpdateBirthTime(int64_t time)
Updates wallet birth time if 'time' is below it.
Definition: wallet.cpp:1747
void blockDisconnected(const interfaces::BlockInfo &block) override
Definition: wallet.cpp:1509
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:643
bool IsWalletFlagSet(uint64_t flag) const override
check if a certain wallet flag is set
Definition: wallet.cpp:1709
void AddToSpends(const COutPoint &outpoint, const Txid &txid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:741
void SetLastBlockProcessedInMem(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:627
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Definition: wallet.cpp:1696
bool IsSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction spends it:
Definition: wallet.cpp:724
std::set< Txid > GetTxConflicts(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1988
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
Definition: wallet.cpp:1704
void ResubmitWalletTransactions(bool relay, bool force)
Definition: wallet.cpp:2041
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:979
bool MarkReplaced(const Txid &originalHash, const Txid &newHash)
Mark a transaction as replaced by another transaction.
Definition: wallet.cpp:915
bool CanGetAddresses(bool internal=false) const
Definition: wallet.cpp:1663
void MarkDirty()
Definition: wallet.cpp:906
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:1217
ScanResult ScanForWalletTransactions(const uint256 &start_block, int start_height, std::optional< int > max_height, const WalletRescanReserver &reserver, bool fUpdate, const bool save_progress)
Scan the block chain (starting in start_block) for transactions from or to us.
Definition: wallet.cpp:1807
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition: wallet.cpp:1714
bool IsHDEnabled() const
Definition: wallet.cpp:1652
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason) override
Definition: wallet.cpp:1411
static NodeClock::time_point GetDefaultNextResend()
Definition: wallet.cpp:2015
bool ShouldResend() const
Return true if all conditions for periodically resending transactions are met.
Definition: wallet.cpp:1998
const CWalletTx * GetWalletTx(const Txid &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:510
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:1726
bool SyncTransaction(const CTransactionRef &tx, const SyncTxState &state, bool update_tx=true, bool rescanning_old_block=false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1356
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
Definition: wallet.cpp:1690
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:762
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:635
bool LoadToWallet(const Txid &hash, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1110
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1763
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:1635
DBErrors ReorderTransactions()
Definition: wallet.cpp:837
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, const SyncTxState &state, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Add a transaction to the wallet, or update it.
Definition: wallet.cpp:1144
bool IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1589
void UpgradeDescriptorCache() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade DescriptorCaches.
Definition: wallet.cpp:519
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:947
CAmount GetDebit(const CTxIn &txin) const
Returns amount of debit, i.e.
Definition: wallet.cpp:1573
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:1282
void transactionAddedToMempool(const CTransactionRef &tx) override
Definition: wallet.cpp:1368
void Close()
Close wallet database.
Definition: wallet.cpp:678
bool SubmitTxMemoryPoolAndRelay(CWalletTx &wtx, std::string &err_string, bool relay) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Pass this transaction to node for mempool insertion and relay to peers if flag set to true.
Definition: wallet.cpp:1958
ChainstateRole
This enum describes the various roles a specific Chainstate instance can take.
Definition: chain.h:25
#define LogInfo(...)
Definition: logging.h:356
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
static int sign(const secp256k1_context *ctx, struct signer_secrets *signer_secrets, struct signer *signer, const secp256k1_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64)
Definition: musig.c:106
Definition: args.cpp:877
PSBTError
Definition: types.h:17
void format(std::ostream &out, FormatStringCheck< sizeof...(Args)> fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1079
static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE
Pre-calculated constants for input size estimation in virtual size
Definition: wallet.h:144
constexpr CAmount HIGH_APS_FEE
discourage APS fee higher than this amount
Definition: wallet.h:123
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:363
static const CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:107
void MaybeResendWalletTxs(WalletContext &context)
Called periodically by the schedule thread.
Definition: wallet.cpp:2078
std::variant< TxStateConfirmed, TxStateInMempool, TxStateInactive > SyncTxState
Subset of states transaction sync logic is implemented to handle.
Definition: transaction.h:82
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition: wallet.cpp:193
constexpr CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:138
std::variant< TxStateConfirmed, TxStateInMempool, TxStateBlockConflicted, TxStateInactive, TxStateUnrecognized > TxState
All possible CWalletTx states.
Definition: transaction.h:79
std::map< std::string, std::string > mapValue_t
Definition: transaction.h:167
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
Definition: crypter.h:63
static const CAmount DEFAULT_DISCARD_FEE
-discardfee default
Definition: wallet.h:109
DBErrors
Overview of wallet database classes:
Definition: walletdb.h:41
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:95
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:108
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)
Definition: wallet.cpp:463
static const bool DEFAULT_WALLETCROSSCHAIN
Definition: wallet.h:136
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
Definition: wallet.cpp:215
static const CAmount DEFAULT_TRANSACTION_MINFEE
-mintxfee default
Definition: wallet.h:111
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
util::Result< MigrationResult > MigrateLegacyToDescriptor(const std::string &wallet_name, const SecureString &passphrase, WalletContext &context)
Do all steps to migrate a legacy wallet to a descriptor wallet.
Definition: wallet.cpp:4173
static const bool DEFAULT_WALLET_RBF
-walletrbf default
Definition: wallet.h:133
constexpr CAmount HIGH_TX_FEE_PER_KB
Discourage users to set fees higher than this amount (in satoshis) per kB.
Definition: wallet.h:140
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:149
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
Definition: wallet.cpp:2828
void NotifyWalletLoaded(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:222
constexpr CAmount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition: wallet.h:142
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:105
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:135
static const CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
Definition: wallet.h:121
static const unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
Definition: wallet.h:131
std::string PurposeToString(AddressPurpose p)
Definition: wallet.h:281
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
Definition: types.h:28
@ REFUND
Never set in current code may be present in older wallet databases.
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:134
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:150
static const CAmount WALLET_INCREMENTAL_RELAY_FEE
minimum recommended increment for replacement txs
Definition: wallet.h:125
static constexpr uint64_t KNOWN_WALLET_FLAGS
Definition: wallet.h:151
static const CAmount DEFAULT_CONSOLIDATE_FEERATE
-consolidatefeerate default
Definition: wallet.h:113
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:376
@ 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
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
Definition: walletutil.h:50
std::optional< AddressPurpose > PurposeFromString(std::string_view s)
Definition: wallet.h:291
void WaitForDeleteWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly delete the wallet.
Definition: wallet.cpp:253
static const std::map< std::string, WalletFlags > STRING_TO_WALLET_FLAG
Definition: wallet.h:173
static constexpr uint64_t MUTABLE_WALLET_FLAGS
Definition: wallet.h:160
std::shared_ptr< CWallet > GetWallet(WalletContext &context, const std::string &name)
Definition: wallet.cpp:206
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:127
static const std::map< WalletFlags, std::string > WALLET_FLAG_TO_STRING
Definition: wallet.h:163
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition: wallet.h:129
DatabaseStatus
Definition: db.h:186
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:162
std::shared_ptr< CWallet > GetDefaultWallet(WalletContext &context, size_t &count)
Definition: wallet.cpp:199
OutputType
Definition: outputtype.h:17
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
const char * name
Definition: rest.cpp:50
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:58
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:124
Definition: key.h:227
A mutable version of CTransaction.
Definition: transaction.h:378
std::chrono::time_point< NodeClock > time_point
Definition: time.h:19
A version of CTransaction with the PSBT format.
Definition: psbt.h:1119
Bilingual messages:
Definition: translation.h:24
A wrapper for a compile-time partially validated format string.
Definition: string.h:92
Address book data.
Definition: wallet.h:240
std::optional< AddressPurpose > purpose
Address purpose which was originally recorded for payment protocol support but now serves as a cached...
Definition: wallet.h:255
void SetLabel(std::string name)
Definition: wallet.h:278
std::string GetLabel() const
Definition: wallet.h:277
bool previously_spent
Whether coins with this address have previously been spent.
Definition: wallet.h:264
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:273
std::optional< std::string > label
Address label which is always nullopt for change addresses.
Definition: wallet.h:248
bool IsChange() const
Accessor methods.
Definition: wallet.h:276
CAmount nAmount
Definition: wallet.h:302
bool fSubtractFeeFromAmount
Definition: wallet.h:303
CTxDestination dest
Definition: wallet.h:301
std::optional< int > last_scanned_height
Definition: wallet.h:643
uint256 last_scanned_block
Hash and height of most recent block that was successfully scanned.
Definition: wallet.h:642
uint256 last_failed_block
Height of the most recent block that could not be scanned due to read errors or pruning.
Definition: wallet.h:649
struct containing information needed for migrating legacy wallets to descriptor wallets
std::shared_ptr< CWallet > watchonly_wallet
Definition: wallet.h:1125
std::string wallet_name
Definition: wallet.h:1123
std::shared_ptr< CWallet > solvables_wallet
Definition: wallet.h:1126
std::shared_ptr< CWallet > wallet
Definition: wallet.h:1124
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:36
static int count
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:50
consteval auto _(util::TranslatedLiteral str)
Definition: translation.h:79
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:533
is a home for public enum and struct type definitions that are used by internally by wallet code,...
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition: wallet.h:80