Bitcoin ABC 0.32.4
P2P Digital Currency
wallet.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2016 The Bitcoin Core developers
3// Copyright (c) 2018-2020 The Bitcoin developers
4// Distributed under the MIT software license, see the accompanying
5// file COPYING or http://www.opensource.org/licenses/mit-license.php.
6
7#ifndef BITCOIN_WALLET_WALLET_H
8#define BITCOIN_WALLET_WALLET_H
9
10#include <common/system.h>
11#include <consensus/amount.h>
12#include <interfaces/chain.h>
13#include <interfaces/handler.h>
14#include <logging.h>
15#include <outputtype.h>
17#include <psbt.h>
18#include <tinyformat.h>
19#include <util/message.h>
20#include <util/result.h>
21#include <util/strencodings.h>
22#include <util/string.h>
23#include <util/translation.h>
24#include <util/ui_change_type.h>
25#include <validationinterface.h>
27#include <wallet/crypter.h>
28#include <wallet/rpcwallet.h>
30#include <wallet/transaction.h>
31#include <wallet/walletdb.h>
32#include <wallet/walletutil.h>
33
34#include <algorithm>
35#include <atomic>
36#include <cstdint>
37#include <map>
38#include <memory>
39#include <optional>
40#include <set>
41#include <stdexcept>
42#include <string>
43#include <utility>
44#include <vector>
45
46#include <boost/signals2/signal.hpp>
47
48struct WalletContext;
49
51 std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
52
53struct bilingual_str;
54
60void UnloadWallet(std::shared_ptr<CWallet> &&wallet);
61
62bool AddWallet(WalletContext &context, const std::shared_ptr<CWallet> &wallet);
63bool RemoveWallet(WalletContext &context,
64 const std::shared_ptr<CWallet> &wallet,
65 std::optional<bool> load_on_start,
66 std::vector<bilingual_str> &warnings);
67bool RemoveWallet(WalletContext &context,
68 const std::shared_ptr<CWallet> &wallet,
69 std::optional<bool> load_on_start);
70
71std::vector<std::shared_ptr<CWallet>> GetWallets(WalletContext &context);
72std::shared_ptr<CWallet> GetWallet(WalletContext &context,
73 const std::string &name);
74std::shared_ptr<CWallet>
75LoadWallet(WalletContext &context, const std::string &name,
76 std::optional<bool> load_on_start, const DatabaseOptions &options,
77 DatabaseStatus &status, bilingual_str &error,
78 std::vector<bilingual_str> &warnings);
79std::shared_ptr<CWallet>
80CreateWallet(WalletContext &context, const std::string &name,
81 std::optional<bool> load_on_start, DatabaseOptions &options,
82 DatabaseStatus &status, bilingual_str &error,
83 std::vector<bilingual_str> &warnings);
84std::shared_ptr<CWallet>
85RestoreWallet(WalletContext &context, const fs::path &backup_file,
86 const std::string &wallet_name, std::optional<bool> load_on_start,
87 DatabaseStatus &status, bilingual_str &error,
88 std::vector<bilingual_str> &warnings);
89std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext &context,
90 LoadWalletFn load_wallet);
92 const std::shared_ptr<CWallet> &wallet);
93std::unique_ptr<WalletDatabase>
94MakeWalletDatabase(const std::string &name, const DatabaseOptions &options,
95 DatabaseStatus &status, bilingual_str &error);
96
115constexpr Amount HIGH_APS_FEE{COIN / 10000};
119static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
120static const bool DEFAULT_WALLETBROADCAST = true;
121static const bool DEFAULT_DISABLE_WALLET = false;
130static constexpr size_t DUMMY_P2PKH_INPUT_SIZE = 148;
131
132class CChainParams;
133class CCoinControl;
134class COutput;
135class CScript;
136class CTxMemPool;
137class CWalletTx;
139
142
143static constexpr uint64_t KNOWN_WALLET_FLAGS =
147
149
150static const std::map<std::string, WalletFlags> WALLET_FLAG_MAP{
151 {"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
152 {"blank", WALLET_FLAG_BLANK_WALLET},
153 {"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
154 {"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
155 {"descriptor_wallet", WALLET_FLAG_DESCRIPTORS},
156};
157
158extern const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS;
159
177protected:
179 const CWallet *const pwallet;
185 int64_t nIndex{-1};
189 bool fInternal{false};
190
191public:
194 explicit ReserveDestination(CWallet *_pwallet, OutputType _type)
195 : pwallet(_pwallet), type(_type) {}
196
199
203
205 bool GetReservedDestination(CTxDestination &pubkey, bool internal);
207 void ReturnDestination();
210 void KeepDestination();
211};
212
215private:
216 bool m_change{true};
217 std::string m_label;
218
219public:
220 std::string purpose;
221
222 CAddressBookData() : purpose("unknown") {}
223
224 typedef std::map<std::string, std::string> StringMap;
226
227 bool IsChange() const { return m_change; }
228 const std::string &GetLabel() const { return m_label; }
229 void SetLabel(const std::string &label) {
230 m_change = false;
231 m_label = label;
232 }
233};
234
239};
240
242 bool use_bnb = true;
250
251 CoinSelectionParams(bool use_bnb_, size_t change_output_size_,
252 size_t change_spend_size_, CFeeRate effective_fee_,
253 size_t tx_noinputs_size_, bool avoid_partial)
254 : use_bnb(use_bnb_), change_output_size(change_output_size_),
255 change_spend_size(change_spend_size_), effective_fee(effective_fee_),
256 tx_noinputs_size(tx_noinputs_size_),
257 m_avoid_partial_spends(avoid_partial) {}
259};
260
261// forward declarations for ScanForWalletTransactions/RescanFromTime
263
268class CWallet final : public WalletStorage,
270private:
272
273 bool Unlock(const CKeyingMaterial &vMasterKeyIn,
274 bool accept_no_keys = false);
275
276 std::atomic<bool> fAbortRescan{false};
277 // controlled by WalletRescanReserver
278 std::atomic<bool> fScanningWallet{false};
279 std::atomic<bool> m_attaching_chain{false};
280 std::atomic<SteadyClock::time_point> m_scanning_start{
281 SteadyClock::time_point{}};
282 std::atomic<double> m_scanning_progress{0};
284
287 int nWalletVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
288
291 int nWalletMaxVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
292
293 int64_t nNextResend = 0;
295 // Local time that the tip block was received. Used to schedule wallet
296 // rebroadcasts.
297 std::atomic<int64_t> m_best_block_time{0};
298
303 typedef std::multimap<COutPoint, TxId> TxSpends;
305 void AddToSpends(const COutPoint &outpoint, const TxId &wtxid)
308
325 CWalletTx::Confirmation confirm, bool fUpdate)
327
332 void MarkConflicted(const BlockHash &hashBlock, int conflicting_height,
333 const TxId &txid);
334
339 void MarkInputsDirty(const CTransactionRef &tx)
341
342 void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>)
344
351 void SyncTransaction(const CTransactionRef &tx,
352 CWalletTx::Confirmation confirm, bool update_tx = true)
354
355 std::atomic<uint64_t> m_wallet_flags{0};
356
357 bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address,
358 const std::string &strName,
359 const std::string &strPurpose);
360
362 void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag);
363
365 void UnsetBlankWalletFlag(WalletBatch &batch) override;
366
369
371 std::string m_name;
372
374 std::unique_ptr<WalletDatabase> database;
375
383 BlockHash m_last_block_processed GUARDED_BY(cs_wallet);
384
385 /* Height of last block processed is used by wallet to know depth of
386 * transactions without relying on Chain interface beyond asynchronous
387 * updates. For safety, we initialize it to -1. Height is a pointer on
388 * node's tip and doesn't imply that the wallet has scanned sequentially all
389 * blocks up to this one.
390 */
391 int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
392
393 std::map<OutputType, ScriptPubKeyMan *> m_external_spk_managers;
394 std::map<OutputType, ScriptPubKeyMan *> m_internal_spk_managers;
395
396 // Indexed by a unique identifier produced by each ScriptPubKeyMan using
397 // ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal
398 // structure
399 std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
400
406 static bool AttachChain(const std::shared_ptr<CWallet> &wallet,
408 std::vector<bilingual_str> &warnings);
409
410public:
411 /*
412 * Main wallet lock.
413 * This lock protects all the fields added by CWallet.
414 */
416
422 WalletDatabase &GetDatabase() override { return *database; }
423
427 const std::string &GetName() const { return m_name; }
428
429 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
431 unsigned int nMasterKeyMaxID = 0;
432
434 CWallet(interfaces::Chain *chain, const std::string &name,
435 std::unique_ptr<WalletDatabase> _database)
436 : m_chain(chain), m_name(name), database(std::move(_database)) {}
437
439 // Should not have slots connected at this point.
440 assert(NotifyUnload.empty());
441 }
442
443 /* Returns the chain params used by this wallet. */
444 const CChainParams &GetChainParams() const override;
445
446 bool IsCrypted() const;
447 bool IsLocked() const override;
448 bool Lock();
449
451 bool HaveChain() const { return m_chain ? true : false; }
452
453 std::map<TxId, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
454
455 typedef std::multimap<int64_t, CWalletTx *> TxItems;
457
458 int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
460
461 std::map<CTxDestination, CAddressBookData>
462 m_address_book GUARDED_BY(cs_wallet);
463 const CAddressBookData *
465 bool allow_change = false) const
467
468 std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
469
472
474 interfaces::Chain &chain() const {
476 return *m_chain;
477 }
478
479 const CWalletTx *GetWalletTx(const TxId &txid) const
481
482 std::set<TxId> GetTxConflicts(const CWalletTx &wtx) const
484
491 int GetTxDepthInMainChain(const CWalletTx &wtx) const
493 bool IsTxInMainChain(const CWalletTx &wtx) const
496
497 return GetTxDepthInMainChain(wtx) > 0;
498 }
499
505 int GetTxBlocksToMaturity(const CWalletTx &wtx) const
507 bool IsTxImmatureCoinBase(const CWalletTx &wtx) const
509
512 bool CanSupportFeature(enum WalletFeature wf) const override
515 return nWalletMaxVersion >= wf;
516 }
517
518 bool IsSpent(const COutPoint &outpoint) const
520
521 // Whether this or any UTXO with the same CTxDestination has been spent.
522 bool IsSpentKey(const TxId &txid, unsigned int n) const
524 void SetSpentKeyState(WalletBatch &batch, const TxId &txid, unsigned int n,
525 bool used, std::set<CTxDestination> &tx_destinations)
527
528 bool IsLockedCoin(const COutPoint &outpoint) const
530 void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
531 void UnlockCoin(const COutPoint &output)
534 void ListLockedCoins(std::vector<COutPoint> &vOutpts) const
536
537 /*
538 * Rescan abort properties
539 */
540 void AbortRescan() { fAbortRescan = true; }
541 bool IsAbortingRescan() const { return fAbortRescan; }
542 bool IsScanning() const { return fScanningWallet; }
543 SteadyClock::duration ScanningDuration() const {
544 return fScanningWallet ? SteadyClock::now() - m_scanning_start.load()
545 : SteadyClock::duration{};
546 }
547 double ScanningProgress() const {
548 return fScanningWallet ? double(m_scanning_progress) : 0;
549 }
550
554
557 nWalletVersion = nVersion;
558 nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion);
559 return true;
560 }
561
567 bool AddDestData(WalletBatch &batch, const CTxDestination &dest,
568 const std::string &key, const std::string &value)
571 bool EraseDestData(WalletBatch &batch, const CTxDestination &dest,
572 const std::string &key)
575 void LoadDestData(const CTxDestination &dest, const std::string &key,
576 const std::string &value)
580 bool GetDestData(const CTxDestination &dest, const std::string &key,
581 std::string *value) const
584 std::vector<std::string> GetDestValues(const std::string &prefix) const
586
590 int64_t nRelockTime GUARDED_BY(cs_wallet){0};
591
592 // Used to prevent concurrent calls to walletpassphrase RPC.
594 bool Unlock(const SecureString &strWalletPassphrase,
595 bool accept_no_keys = false);
596 bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase,
597 const SecureString &strNewWalletPassphrase);
598 bool EncryptWallet(const SecureString &strWalletPassphrase);
599
600 void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const
602 unsigned int ComputeTimeSmart(const CWalletTx &wtx) const;
603
608 int64_t IncOrderPosNext(WalletBatch *batch = nullptr)
611
612 void MarkDirty();
613
622 using UpdateWalletTxFn = std::function<bool(CWalletTx &wtx, bool new_tx)>;
623
625 const CWalletTx::Confirmation &confirm,
626 const UpdateWalletTxFn &update_wtx = nullptr,
627 bool fFlushOnClose = true);
628 bool LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx)
631 uint64_t mempool_sequence) override;
632 void blockConnected(ChainstateRole role, const CBlock &block,
633 int height) override;
634 void blockDisconnected(const CBlock &block, int height) override;
635 void updatedBlockTip() override;
636 int64_t RescanFromTime(int64_t startTime,
637 const WalletRescanReserver &reserver, bool update);
638
639 struct ScanResult {
640 enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
641
646 std::optional<int> last_scanned_height;
647
653 };
655 int start_height,
656 std::optional<int> max_height,
657 const WalletRescanReserver &reserver,
658 bool fUpdate);
661 uint64_t mempool_sequence) override;
664
666 TransactionChangeType(const std::optional<OutputType> &change_type,
667 const std::vector<CRecipient> &vecSend) const;
668
669 // Fetch the inputs and sign with SIGHASH_ALL.
672 // Sign the tx given the input coins and sighash.
674 const std::map<COutPoint, Coin> &coins,
675 SigHashType sighash,
676 std::map<int, std::string> &input_errors) const;
677 SigningResult SignMessage(const std::string &message, const PKHash &pkhash,
678 std::string &str_sig) const;
679
696 FillPSBT(PartiallySignedTransaction &psbtx, bool &complete,
697 SigHashType sighash_type = SigHashType().withForkId(),
698 bool sign = true, bool bip32derivs = true) const;
699
712 CTransactionRef tx, mapValue_t mapValue,
713 std::vector<std::pair<std::string, std::string>> orderForm,
714 bool broadcast = true);
715
721 std::string &err_string, bool relay) const
723
724 bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts,
725 bool use_max_sig = false) const {
726 std::vector<CTxOut> v_txouts(txouts.size());
727 std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
728 return DummySignTx(txNew, v_txouts, use_max_sig);
729 }
731 const std::vector<CTxOut> &txouts,
732 bool use_max_sig = false) const;
733 bool DummySignInput(CTxIn &tx_in, const CTxOut &txout,
734 bool use_max_sig = false) const;
735
736 bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp)
738 bool ImportPrivKeys(const std::map<CKeyID, CKey> &privkey_map,
739 const int64_t timestamp)
741 bool ImportPubKeys(
742 const std::vector<CKeyID> &ordered_pubkeys,
743 const std::map<CKeyID, CPubKey> &pubkey_map,
744 const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> &key_origins,
745 const bool add_keypool, const bool internal, const int64_t timestamp)
747 bool ImportScriptPubKeys(const std::string &label,
748 const std::set<CScript> &script_pub_keys,
749 const bool have_solving_data,
750 const bool apply_label, const int64_t timestamp)
752
757 // Override with -mintxfee
774 std::optional<OutputType> m_default_change_type{};
780
782 bool TopUpKeyPool(unsigned int kpSize = 0);
783
784 int64_t GetOldestKeyPoolTime() const;
785
786 std::set<CTxDestination> GetLabelAddresses(const std::string &label) const
788
793 void MarkDestinationsDirty(const std::set<CTxDestination> &destinations)
795
797 const std::string &label);
799
800 isminetype IsMine(const CTxDestination &dest) const
802 isminetype IsMine(const CScript &script) const
808 Amount GetDebit(const CTxIn &txin, const isminefilter &filter) const;
809 isminetype IsMine(const CTxOut &txout) const
811 ;
812 bool IsMine(const CTransaction &tx) const
815 bool IsFromMe(const CTransaction &tx) const;
816 Amount GetDebit(const CTransaction &tx, const isminefilter &filter) const;
818 const CBlockLocator &loc) override;
819
821 DBErrors ZapSelectTx(std::vector<TxId> &txIdsIn,
822 std::vector<TxId> &txIdsOut)
824
825 bool SetAddressBook(const CTxDestination &address,
826 const std::string &strName, const std::string &purpose);
827
828 bool DelAddressBook(const CTxDestination &address);
829
831
834 void SetMinVersion(enum WalletFeature, WalletBatch *batch_in = nullptr,
835 bool fExplicit = false) override;
836
839 bool SetMaxVersion(int nVersion);
840
843 int GetVersion() const {
845 return nWalletVersion;
846 }
847
850 std::set<TxId> GetConflicts(const TxId &txid) const
852
855 bool HasWalletSpend(const TxId &txid) const
857
859 void Flush();
860
862 void Close();
863
865 boost::signals2::signal<void()> NotifyUnload;
866
871 boost::signals2::signal<void(CWallet *wallet, const CTxDestination &address,
872 const std::string &label, bool isMine,
873 const std::string &purpose, ChangeType status)>
875
880 boost::signals2::signal<void(CWallet *wallet, const TxId &txid,
881 ChangeType status)>
883
885 boost::signals2::signal<void(const std::string &title, int nProgress)>
887
889 boost::signals2::signal<void(bool fHaveWatchOnly)> NotifyWatchonlyChanged;
890
892 boost::signals2::signal<void()> NotifyCanGetAddressesChanged;
893
898 boost::signals2::signal<void(CWallet *wallet)> NotifyStatusChanged;
899
903 void SetBroadcastTransactions(bool broadcast) {
904 fBroadcastTransactions = broadcast;
905 }
906
908 bool TransactionCanBeAbandoned(const TxId &txid) const;
909
914 bool AbandonTransaction(const TxId &txid);
915
920 static std::shared_ptr<CWallet>
921 Create(WalletContext &context, const std::string &name,
922 std::unique_ptr<WalletDatabase> database,
923 uint64_t wallet_creation_flags, bilingual_str &error,
924 std::vector<bilingual_str> &warnings);
925
931 void postInitProcess();
932
933 bool BackupWallet(const std::string &strDest) const;
934
935 /* Returns true if HD is enabled */
936 bool IsHDEnabled() const;
937
942 bool CanGetAddresses(bool internal = false) const;
943
950 void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main)
952
956 void SetWalletFlag(uint64_t flags);
957
961 void UnsetWalletFlag(uint64_t flag);
962
966 bool IsWalletFlagSet(uint64_t flag) const override;
967
972 bool AddWalletFlags(uint64_t flags);
974 bool LoadWalletFlags(uint64_t flags);
975
977 bool IsLegacy() const;
978
983 std::string GetDisplayName() const override {
984 std::string wallet_name =
985 GetName().length() == 0 ? "default wallet" : GetName();
986 return strprintf("[%s]", wallet_name);
987 };
988
993 template <typename... Params>
994 void WalletLogPrintf(std::string fmt, Params... parameters) const {
995 LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
996 };
997
998 template <typename... Params>
999 void WalletLogPrintfToBeContinued(std::string fmt,
1000 Params... parameters) const {
1001 LogPrintfToBeContinued(("%s " + fmt).c_str(), GetDisplayName(),
1002 parameters...);
1003 };
1004
1006 bool UpgradeWallet(int version, bilingual_str &error);
1007
1010 std::set<ScriptPubKeyMan *> GetActiveScriptPubKeyMans() const;
1011
1013 std::set<ScriptPubKeyMan *> GetAllScriptPubKeyMans() const;
1014
1018 bool internal) const;
1019
1021 ScriptPubKeyMan *GetScriptPubKeyMan(const CScript &script) const;
1023 ScriptPubKeyMan *GetScriptPubKeyMan(const uint256 &id) const;
1024
1027 std::set<ScriptPubKeyMan *>
1028 GetScriptPubKeyMans(const CScript &script, SignatureData &sigdata) const;
1029
1031 std::unique_ptr<SigningProvider>
1032 GetSolvingProvider(const CScript &script) const;
1033 std::unique_ptr<SigningProvider>
1034 GetSolvingProvider(const CScript &script, SignatureData &sigdata) const;
1035
1040
1044
1045 bool WithEncryptionKey(
1046 const std::function<bool(const CKeyingMaterial &)> &cb) const override;
1047
1048 bool HasEncryptionKeys() const override;
1049
1053 assert(m_last_block_processed_height >= 0);
1054 return m_last_block_processed_height;
1055 };
1058 assert(m_last_block_processed_height >= 0);
1059 return m_last_block_processed;
1060 }
1062 void SetLastBlockProcessed(int block_height, BlockHash block_hash)
1065 m_last_block_processed_height = block_height;
1066 m_last_block_processed = block_hash;
1067 };
1068
1071
1075
1083 void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1084
1092 void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1093
1101 void DeactivateScriptPubKeyMan(const uint256 &id, OutputType type,
1102 bool internal);
1103
1106
1111
1116 const FlatSigningProvider &signing_provider,
1117 const std::string &label, bool internal)
1119};
1120
1126void MaybeResendWalletTxs(WalletContext &context);
1127
1130private:
1133
1134public:
1136 : m_wallet(w), m_could_reserve(false) {}
1137
1138 bool reserve() {
1140 if (m_wallet.fScanningWallet.exchange(true)) {
1141 return false;
1142 }
1143 m_wallet.m_scanning_start = SteadyClock::now();
1144 m_wallet.m_scanning_progress = 0;
1145 m_could_reserve = true;
1146 return true;
1147 }
1148
1149 bool isReserved() const {
1150 return (m_could_reserve && m_wallet.fScanningWallet);
1151 }
1152
1154 if (m_could_reserve) {
1155 m_wallet.fScanningWallet = false;
1156 }
1157 }
1158};
1159
1161bool AddWalletSetting(interfaces::Chain &chain, const std::string &wallet_name);
1162
1166 const std::string &wallet_name);
1167
1168#endif // BITCOIN_WALLET_WALLET_H
static constexpr Amount SATOSHI
Definition: amount.h:143
static constexpr Amount COIN
Definition: amount.h:144
int flags
Definition: bitcoin-tx.cpp:542
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:21
Address book data.
Definition: wallet.h:214
StringMap destdata
Definition: wallet.h:225
std::map< std::string, std::string > StringMap
Definition: wallet.h:224
std::string m_label
Definition: wallet.h:217
const std::string & GetLabel() const
Definition: wallet.h:228
std::string purpose
Definition: wallet.h:220
bool IsChange() const
Definition: wallet.h:227
void SetLabel(const std::string &label)
Definition: wallet.h:229
Definition: block.h:60
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:86
Coin Control Features.
Definition: coincontrol.h:21
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
A mutable version of CTransaction.
Definition: transaction.h:274
Definition: spend.h:22
CScript()
Definition: script.h:446
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:221
An output of a transaction.
Definition: transaction.h:128
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:269
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
Get the SigningProvider for a script.
Definition: wallet.cpp:3370
std::atomic< int64_t > m_best_block_time
Definition: wallet.h:297
bool Lock()
Definition: wallet.cpp:3270
BlockHash GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:1056
std::map< CTxDestination, CAddressBookData > m_address_book GUARDED_BY(cs_wallet)
int64_t nRelockTime GUARDED_BY(cs_wallet)
Holds a timestamp at which point the wallet is scheduled (externally) to be relocked.
Definition: wallet.h:590
std::set< ScriptPubKeyMan * > GetScriptPubKeyMans(const CScript &script, SignatureData &sigdata) const
Get all of the ScriptPubKeyMans for a script given additional information in sigdata (populated by e....
Definition: wallet.cpp:3341
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:865
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:429
bool HaveChain() const
Interface to assert chain access.
Definition: wallet.h:451
int GetTxBlocksToMaturity(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3239
int nWalletVersion GUARDED_BY(cs_wallet)
the current wallet version: clients below this version are not able to load the wallet
double ScanningProgress() const
Definition: wallet.h:547
bool DummySignTx(CMutableTransaction &txNew, const std::set< CTxOut > &txouts, bool use_max_sig=false) const
Definition: wallet.h:724
uint64_t nAccountingEntryNumber
Definition: wallet.h:459
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
Definition: wallet.cpp:3430
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Adds the active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3483
void SetupLegacyScriptPubKeyMan()
Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
Definition: wallet.cpp:3405
Mutex m_unlock_mutex
Definition: wallet.h:593
bool AddDestData(WalletBatch &batch, const CTxDestination &dest, const std::string &key, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Adds a destination data tuple to the store, and saves it to disk When adding new fields,...
Definition: wallet.cpp:2680
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition: wallet.h:892
MasterKeyMap mapMasterKeys
Definition: wallet.h:430
std::string m_name
Wallet name: relative directory name or "" for default wallet.
Definition: wallet.h:371
TxItems wtxOrdered
Definition: wallet.h:456
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:3229
bool IsTxImmatureCoinBase(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3251
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:886
RecursiveMutex cs_wallet
Definition: wallet.h:415
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
Definition: wallet.cpp:3289
SteadyClock::duration ScanningDuration() const
Definition: wallet.h:543
std::multimap< COutPoint, TxId > TxSpends
Used to keep track of spent outpoints, and detect and report conflicts (double-spends or mutated tran...
Definition: wallet.h:303
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:901
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
Definition: wallet.h:994
bool IsAbortingRescan() const
Definition: wallet.h:541
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition: wallet.h:474
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new DescriptorScriptPubKeyMans and add them to the wallet.
Definition: wallet.cpp:3445
WalletDatabase & GetDatabase() override
Definition: wallet.h:422
interfaces::Chain * m_chain
Interface for accessing chain state.
Definition: wallet.h:368
std::atomic< bool > m_attaching_chain
Definition: wallet.h:279
bool WithEncryptionKey(const std::function< bool(const CKeyingMaterial &)> &cb) const override
Pass the encryption key to cb().
Definition: wallet.cpp:3420
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
Definition: wallet.cpp:3400
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
Definition: wallet.h:393
void DeactivateScriptPubKeyMan(const uint256 &id, OutputType type, bool internal)
Remove specified ScriptPubKeyMan from set of active SPK managers.
Definition: wallet.cpp:3521
bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Look up a destination data tuple in the store, return true if found false otherwise.
Definition: wallet.cpp:2704
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:764
bool IsLegacy() const
Determine if we are a legacy wallet.
Definition: wallet.cpp:3544
std::atomic< bool > fAbortRescan
Definition: wallet.h:276
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
Definition: wallet.h:399
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Loads an active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3494
std::unique_ptr< interfaces::Handler > m_chain_notifications_handler
Registered interfaces::Chain::Notifications handler.
Definition: wallet.h:471
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:903
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition: wallet.h:874
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition: wallet.h:1051
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: wallet.h:898
OutputType m_default_address_type
Definition: wallet.h:767
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
Definition: wallet.cpp:3554
static bool AttachChain(const std::shared_ptr< CWallet > &wallet, interfaces::Chain &chain, 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:3003
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
Definition: wallet.cpp:3438
LegacyScriptPubKeyMan * GetLegacyScriptPubKeyMan() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
Definition: wallet.cpp:3386
std::atomic< uint64_t > m_wallet_flags
Definition: wallet.h:355
Amount m_max_aps_fee
note: this is absolute fee, not fee rate
Definition: wallet.h:766
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:427
CFeeRate m_pay_tx_fee
Definition: wallet.h:753
int64_t nNextResend
Definition: wallet.h:293
bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
check whether we are allowed to upgrade (or already support) to the named feature
Definition: wallet.h:512
bool BackupWallet(const std::string &strDest) const
Definition: wallet.cpp:3203
int64_t nOrderPosNext GUARDED_BY(cs_wallet)=0
BlockHash 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,...
bool IsTxInMainChain(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:493
unsigned int ComputeTimeSmart(const CWalletTx &wtx) const
Compute smart timestamp for a transaction being added to the wallet.
Definition: wallet.cpp:2638
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet)
bool IsScanning() const
Definition: wallet.h:542
TxSpends mapTxSpends GUARDED_BY(cs_wallet)
std::map< TxId, CWalletTx > mapWallet GUARDED_BY(cs_wallet)
void WalletLogPrintfToBeContinued(std::string fmt, Params... parameters) const
Definition: wallet.h:999
std::unique_ptr< WalletDatabase > database
Internal database handle.
Definition: wallet.h:374
std::atomic< SteadyClock::time_point > m_scanning_start
Definition: wallet.h:280
ScriptPubKeyMan * 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:3570
int m_last_block_processed_height GUARDED_BY(cs_wallet)
std::set< ScriptPubKeyMan * > GetActiveScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers.
Definition: wallet.cpp:3304
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:555
CFeeRate m_min_fee
Definition: wallet.h:758
std::vector< std::string > GetDestValues(const std::string &prefix) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get all destination values matching a prefix.
Definition: wallet.cpp:2723
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:889
bool IsLocked() const override
Definition: wallet.cpp:3262
bool m_allow_fallback_fee
will be false if -fallbackfee=0
Definition: wallet.h:756
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
Definition: wallet.h:394
std::atomic< double > m_scanning_progress
Definition: wallet.h:282
~CWallet()
Definition: wallet.h:438
int GetVersion() const
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.h:843
WalletDatabase & GetDBHandle()
Get database handle used by this wallet.
Definition: wallet.h:421
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2546
bool EraseDestData(WalletBatch &batch, const CTxDestination &dest, const std::string &key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Erases a destination data tuple in the store and on disk.
Definition: wallet.cpp:2690
boost::signals2::signal< void(CWallet *wallet, const TxId &txid, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:882
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)
Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error.
Definition: wallet.cpp:2768
bool HasEncryptionKeys() const override
Definition: wallet.cpp:3426
bool m_spend_zero_conf_change
Definition: wallet.h:754
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > _database)
Construct wallet with specified name and database implementation.
Definition: wallet.h:434
Amount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
Definition: wallet.h:779
bool UpgradeWallet(int version, bilingual_str &error)
Upgrade the wallet.
Definition: wallet.cpp:3149
bool fBroadcastTransactions
Definition: wallet.h:294
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
Definition: wallet.cpp:3325
bool IsCrypted() const
Definition: wallet.cpp:3258
std::atomic< bool > fScanningWallet
Definition: wallet.h:278
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
Definition: wallet.cpp:3317
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:455
int nWalletMaxVersion GUARDED_BY(cs_wallet)
the maximum wallet format version: memory-only variable that specifies to what version this wallet ma...
std::string GetDisplayName() const override
Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet ha...
Definition: wallet.h:983
std::optional< OutputType > m_default_change_type
Default output type for change outputs.
Definition: wallet.h:774
void AbortRescan()
Definition: wallet.h:540
void LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Adds a destination data tuple to the store, without saving it to disk.
Definition: wallet.cpp:2699
unsigned int nMasterKeyMaxID
Definition: wallet.h:431
std::function< bool(CWalletTx &wtx, bool new_tx)> UpdateWalletTxFn
Callback for updating transaction metadata in mapWallet.
Definition: wallet.h:622
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition: wallet.cpp:3192
void SetLastBlockProcessed(int block_height, BlockHash block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, currently only use in unit test.
Definition: wallet.h:1062
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3137
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:65
A UTXO entry.
Definition: coins.h:29
A wrapper to reserve an address from a wallet.
Definition: wallet.h:176
bool fInternal
Whether this is from the internal (change output) keypool.
Definition: wallet.h:189
ReserveDestination & operator=(const ReserveDestination &)=delete
OutputType const type
Definition: wallet.h:183
~ReserveDestination()
Destructor.
Definition: wallet.h:202
ReserveDestination(CWallet *_pwallet, OutputType _type)
Construct a ReserveDestination object.
Definition: wallet.h:194
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from.
Definition: wallet.h:182
int64_t nIndex
The index of the address's key in the keypool.
Definition: wallet.h:185
CTxDestination address
The destination.
Definition: wallet.h:187
ReserveDestination(const ReserveDestination &)=delete
const CWallet *const pwallet
The wallet to reserve from.
Definition: wallet.h:179
A class implementing ScriptPubKeyMan manages some (or all) scriptPubKeys used in a wallet.
Signature hash type wrapper class.
Definition: sighashtype.h:37
Access to the wallet database.
Definition: walletdb.h:176
An instance of this class represents one database.
Definition: db.h:100
Descriptor with some wallet metadata.
Definition: walletutil.h:80
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1129
bool isReserved() const
Definition: wallet.h:1149
CWallet & m_wallet
Definition: wallet.h:1131
WalletRescanReserver(CWallet &w)
Definition: wallet.h:1135
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
Chain notifications.
Definition: chain.h:257
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:136
256-bit opaque blob.
Definition: uint256.h:129
std::vector< uint8_t, secure_allocator< uint8_t > > CKeyingMaterial
Definition: crypter.h:57
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
TransactionError
Definition: error.h:22
void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2516
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:2439
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2367
util::Result< CTxDestination > GetNewDestination(const OutputType type, const std::string &label)
Definition: wallet.cpp:2398
util::Result< CTxDestination > GetNewChangeDestination(const OutputType type)
Definition: wallet.cpp:2415
void KeepDestination()
Keep the address.
Definition: wallet.cpp:2499
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2537
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2378
std::set< CTxDestination > GetLabelAddresses(const std::string &label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2460
bool IsLockedCoin(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2531
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Definition: wallet.cpp:2166
void UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2521
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:2326
DBErrors LoadWallet()
Definition: wallet.cpp:2243
OutputType TransactionChangeType(const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
Definition: wallet.cpp:2180
bool SignTransaction(CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2075
void ReturnDestination()
Return reserved address.
Definition: wallet.cpp:2508
void UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2526
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:2388
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::string &strPurpose)
Definition: wallet.cpp:2299
TransactionError FillPSBT(PartiallySignedTransaction &psbtx, bool &complete, SigHashType sighash_type=SigHashType().withForkId(), bool sign=true, bool bip32derivs=true) const
Fills out a PSBT with information from the wallet.
Definition: wallet.cpp:2122
bool GetReservedDestination(CTxDestination &pubkey, bool internal)
Reserve an address.
Definition: wallet.cpp:2478
int64_t GetOldestKeyPoolTime() const
Definition: wallet.cpp:2429
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:2333
DBErrors ZapSelectTx(std::vector< TxId > &txIdsIn, std::vector< TxId > &txIdsOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2267
void CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector< std::pair< std::string, std::string > > orderForm, bool broadcast=true)
Add the transaction to the wallet and maybe attempt to broadcast it.
Definition: wallet.cpp:2196
bool AddWalletFlags(uint64_t flags)
Overwrite all flags by the given uint64_t.
Definition: wallet.cpp:1604
bool ImportPubKeys(const std::vector< CKeyID > &ordered_pubkeys, const std::map< CKeyID, CPubKey > &pubkey_map, const std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > &key_origins, const bool add_keypool, const bool internal, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1679
bool LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1114
void MarkConflicted(const BlockHash &hashBlock, int conflicting_height, const TxId &txid)
Mark a transaction (and its in-wallet descendants) as conflicting with a particular block.
Definition: wallet.cpp:1297
void Flush()
Flush wallet (bitdb flush)
Definition: wallet.cpp:671
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
Definition: wallet.cpp:463
bool SetMaxVersion(int nVersion)
change which version we're allowed to upgrade to (note that this does not immediately imply upgrading...
Definition: wallet.cpp:623
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:636
void MarkDirty()
Definition: wallet.cpp:962
bool SubmitTxMemoryPoolAndRelay(const 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:1953
void AddToSpends(const COutPoint &outpoint, const TxId &wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:749
void SyncTransaction(const CTransactionRef &tx, CWalletTx::Confirmation confirm, bool update_tx=true) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Used by TransactionAddedToMemorypool/BlockConnected/Disconnected/ScanForWalletTransactions.
Definition: wallet.cpp:1354
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1659
CWalletTx * AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation &confirm, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true)
Definition: wallet.cpp:1020
bool HasWalletSpend(const TxId &txid) 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:665
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:507
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:1562
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:1521
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1669
void blockConnected(ChainstateRole role, const CBlock &block, int height) override
Definition: wallet.cpp:1422
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1496
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition: wallet.cpp:1593
bool ImportScriptPubKeys(const std::string &label, const std::set< CScript > &script_pub_keys, const bool have_solving_data, const bool apply_label, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1693
bool CanGetAddresses(bool internal=false) const
Returns true if the wallet can give out new addresses.
Definition: wallet.cpp:1548
ScanResult ScanForWalletTransactions(const BlockHash &start_block, int start_height, std::optional< int > max_height, const WalletRescanReserver &reserver, bool fUpdate)
Scan the block chain (starting in start_block) for transactions from or to us.
Definition: wallet.cpp:1779
bool IsSpentKey(const TxId &txid, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:993
bool TransactionCanBeAbandoned(const TxId &txid) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1222
const CChainParams & GetChainParams() const override
Definition: wallet.cpp:447
Amount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Returns amount of debit if the input matches the filter, otherwise returns 0.
Definition: wallet.cpp:1475
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:1229
bool AddToWalletIfInvolvingMe(const CTransactionRef &tx, CWalletTx::Confirmation confirm, bool fUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Add a transaction to the wallet, or update it.
Definition: wallet.cpp:1165
bool IsSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction, spends it:
Definition: wallet.cpp:728
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1920
bool IsHDEnabled() const
Definition: wallet.cpp:1539
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Definition: wallet.cpp:1576
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:679
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:773
void chainStateFlushed(ChainstateRole role, const CBlockLocator &loc) override
Definition: wallet.cpp:585
void updatedBlockTip() override
Definition: wallet.cpp:1458
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
Definition: wallet.cpp:1571
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Definition: wallet.cpp:1380
bool IsWalletFlagSet(uint64_t flag) const override
Check if a certain wallet flag is set.
Definition: wallet.cpp:1589
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1728
bool AbandonTransaction(const TxId &txid)
Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent.
Definition: wallet.cpp:1238
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
Definition: wallet.cpp:1585
void SetSpentKeyState(WalletBatch &batch, const TxId &txid, unsigned int n, bool used, std::set< CTxDestination > &tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:969
void transactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
Definition: wallet.cpp:1367
DBErrors ReorderTransactions()
Definition: wallet.cpp:894
void blockDisconnected(const CBlock &block, int height) override
Definition: wallet.cpp:1441
void Close()
Close wallet database.
Definition: wallet.cpp:675
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
Definition: wallet.cpp:950
const CWalletTx * GetWalletTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:453
void ResendWalletTransactions()
Definition: wallet.cpp:2014
void SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr, bool fExplicit=false) override
signify that a particular wallet feature is now used.
Definition: wallet.cpp:595
std::set< TxId > GetTxConflicts(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1994
bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig=false) const
Definition: wallet.cpp:1618
uint8_t isminefilter
Definition: wallet.h:43
isminetype
IsMine() return codes.
Definition: ismine.h:18
ChainstateRole
This enum describes the various roles a specific Chainstate instance can take.
Definition: chain.h:14
#define LogPrintfToBeContinued
These are aliases used to explicitly state that the message should not end with a newline character.
Definition: logging.h:459
#define LogPrintf(...)
Definition: logging.h:424
SigningResult
Definition: message.h:47
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
OutputType
Definition: outputtype.h:16
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
const char * prefix
Definition: rest.cpp:812
const char * name
Definition: rest.cpp:47
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:55
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:85
Definition: amount.h:19
static constexpr Amount zero() noexcept
Definition: amount.h:32
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:109
CScript scriptPubKey
Definition: wallet.h:236
Amount nAmount
Definition: wallet.h:237
bool fSubtractFeeFromAmount
Definition: wallet.h:238
std::optional< int > last_scanned_height
Definition: wallet.h:646
BlockHash last_scanned_block
Hash and height of most recent block that was successfully scanned.
Definition: wallet.h:645
BlockHash last_failed_block
Hash of the most recent block that could not be scanned due to read errors or pruning.
Definition: wallet.h:652
Confirmation includes tx status and a triplet of {block height/block hash/tx index in block} at which...
Definition: transaction.h:181
bool m_subtract_fee_outputs
Indicate that we are subtracting the fee from outputs.
Definition: wallet.h:248
CoinSelectionParams(bool use_bnb_, size_t change_output_size_, size_t change_spend_size_, CFeeRate effective_fee_, size_t tx_noinputs_size_, bool avoid_partial)
Definition: wallet.h:251
size_t change_spend_size
Definition: wallet.h:244
size_t tx_noinputs_size
Definition: wallet.h:246
bool m_avoid_partial_spends
Definition: wallet.h:249
CFeeRate effective_fee
Definition: wallet.h:245
size_t change_output_size
Definition: wallet.h:243
A version of CTransaction with the PSBT format.
Definition: psbt.h:334
A TxId is the identifier of a transaction.
Definition: txid.h:14
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:35
Bilingual messages:
Definition: translation.h:17
#define LOCK(cs)
Definition: sync.h:306
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:55
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: txmempool.h:158
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition: context.h:23
DatabaseStatus
Definition: db.h:227
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:480
std::map< std::string, std::string > mapValue_t
Definition: transaction.h:21
constexpr Amount HIGH_TX_FEE_PER_KB
Discourage users to set fees higher than this amount (in satoshis) per kB.
Definition: wallet.h:125
constexpr Amount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:98
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:121
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
Definition: wallet.cpp:168
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:141
static constexpr uint64_t MUTABLE_WALLET_FLAGS
Definition: wallet.h:148
constexpr Amount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition: wallet.h:128
const std::map< uint64_t, std::string > WALLET_FLAG_CAVEATS
Definition: wallet.cpp:46
static const std::map< std::string, WalletFlags > WALLET_FLAG_MAP
Definition: wallet.h:150
static constexpr size_t DUMMY_P2PKH_INPUT_SIZE
Pre-calculated constants for input size estimation.
Definition: wallet.h:130
static const Amount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:100
static const Amount DEFAULT_TRANSACTION_MINFEE_PER_KB
-mintxfee default
Definition: wallet.h:102
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:119
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Definition: wallet.cpp:2736
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Definition: wallet.cpp:211
void MaybeResendWalletTxs(WalletContext &context)
Called periodically by the schedule thread.
Definition: wallet.cpp:2063
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:105
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:119
static constexpr uint64_t KNOWN_WALLET_FLAGS
Definition: wallet.h:143
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition: wallet.cpp:151
constexpr Amount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:123
static const Amount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
Definition: wallet.h:113
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:53
std::shared_ptr< CWallet > RestoreWallet(WalletContext &context, const fs::path &backup_file, const std::string &wallet_name, std::optional< bool > load_on_start, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:397
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:68
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:120
std::shared_ptr< CWallet > GetWallet(WalletContext &context, const std::string &name)
Definition: wallet.cpp:156
constexpr Amount HIGH_APS_FEE
discourage APS fee higher than this amount
Definition: wallet.h:115
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:295
static const Amount WALLET_INCREMENTAL_RELAY_FEE(5000 *SATOSHI)
minimum recommended increment for BIP 125 replacement txs
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:277
void NotifyWalletLoaded(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:178
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:46
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:55
@ WALLET_FLAG_AVOID_REUSE
Definition: walletutil.h:47
@ WALLET_FLAG_KEY_ORIGIN_METADATA
Definition: walletutil.h:51
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:70
@ WALLET_FLAG_BLANK_WALLET
Flag set when a wallet contains no HD seed and no private keys, scripts, addresses,...
Definition: walletutil.h:67
WalletFeature
(client) version numbers for particular wallet features
Definition: walletutil.h:14
@ FEATURE_BASE
Definition: walletutil.h:17