Bitcoin ABC 0.32.12
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/signmessage.h>
11#include <common/system.h>
12#include <consensus/amount.h>
13#include <interfaces/chain.h>
14#include <interfaces/handler.h>
15#include <logging.h>
16#include <outputtype.h>
18#include <psbt.h>
19#include <tinyformat.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;
49namespace common {
50enum class PSBTError;
51} // namespace common
52
54 std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
55
56struct bilingual_str;
57
63void UnloadWallet(std::shared_ptr<CWallet> &&wallet);
64
65bool AddWallet(WalletContext &context, const std::shared_ptr<CWallet> &wallet);
66bool RemoveWallet(WalletContext &context,
67 const std::shared_ptr<CWallet> &wallet,
68 std::optional<bool> load_on_start,
69 std::vector<bilingual_str> &warnings);
70bool RemoveWallet(WalletContext &context,
71 const std::shared_ptr<CWallet> &wallet,
72 std::optional<bool> load_on_start);
73
74std::vector<std::shared_ptr<CWallet>> GetWallets(WalletContext &context);
75std::shared_ptr<CWallet> GetWallet(WalletContext &context,
76 const std::string &name);
77std::shared_ptr<CWallet>
78LoadWallet(WalletContext &context, const std::string &name,
79 std::optional<bool> load_on_start, const DatabaseOptions &options,
80 DatabaseStatus &status, bilingual_str &error,
81 std::vector<bilingual_str> &warnings);
82std::shared_ptr<CWallet>
83CreateWallet(WalletContext &context, const std::string &name,
84 std::optional<bool> load_on_start, DatabaseOptions &options,
85 DatabaseStatus &status, bilingual_str &error,
86 std::vector<bilingual_str> &warnings);
87std::shared_ptr<CWallet>
88RestoreWallet(WalletContext &context, const fs::path &backup_file,
89 const std::string &wallet_name, std::optional<bool> load_on_start,
90 DatabaseStatus &status, bilingual_str &error,
91 std::vector<bilingual_str> &warnings);
92std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext &context,
93 LoadWalletFn load_wallet);
95 const std::shared_ptr<CWallet> &wallet);
96std::unique_ptr<WalletDatabase>
97MakeWalletDatabase(const std::string &name, const DatabaseOptions &options,
98 DatabaseStatus &status, bilingual_str &error);
99
118constexpr Amount HIGH_APS_FEE{COIN / 10000};
122static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
123static const bool DEFAULT_WALLETBROADCAST = true;
124static const bool DEFAULT_DISABLE_WALLET = false;
133static constexpr size_t DUMMY_P2PKH_INPUT_SIZE = 148;
134
135class CChainParams;
136class CCoinControl;
137class COutput;
138class CScript;
139class CTxMemPool;
140class CWalletTx;
142
145
146static constexpr uint64_t KNOWN_WALLET_FLAGS =
150
152
153static const std::map<std::string, WalletFlags> WALLET_FLAG_MAP{
154 {"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
155 {"blank", WALLET_FLAG_BLANK_WALLET},
156 {"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
157 {"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
158 {"descriptor_wallet", WALLET_FLAG_DESCRIPTORS},
159};
160
161extern const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS;
162
180protected:
182 const CWallet *const pwallet;
188 int64_t nIndex{-1};
192 bool fInternal{false};
193
194public:
197 explicit ReserveDestination(CWallet *_pwallet, OutputType _type)
198 : pwallet(_pwallet), type(_type) {}
199
202
206
208 bool GetReservedDestination(CTxDestination &pubkey, bool internal);
210 void ReturnDestination();
213 void KeepDestination();
214};
215
218private:
219 bool m_change{true};
220 std::string m_label;
221
222public:
223 std::string purpose;
224
225 CAddressBookData() : purpose("unknown") {}
226
227 typedef std::map<std::string, std::string> StringMap;
229
230 bool IsChange() const { return m_change; }
231 const std::string &GetLabel() const { return m_label; }
232 void SetLabel(const std::string &label) {
233 m_change = false;
234 m_label = label;
235 }
236};
237
242};
243
245 bool use_bnb = true;
253
254 CoinSelectionParams(bool use_bnb_, size_t change_output_size_,
255 size_t change_spend_size_, CFeeRate effective_fee_,
256 size_t tx_noinputs_size_, bool avoid_partial)
257 : use_bnb(use_bnb_), change_output_size(change_output_size_),
258 change_spend_size(change_spend_size_), effective_fee(effective_fee_),
259 tx_noinputs_size(tx_noinputs_size_),
260 m_avoid_partial_spends(avoid_partial) {}
262};
263
264// forward declarations for ScanForWalletTransactions/RescanFromTime
266
271class CWallet final : public WalletStorage,
273private:
275
276 bool Unlock(const CKeyingMaterial &vMasterKeyIn,
277 bool accept_no_keys = false);
278
279 std::atomic<bool> fAbortRescan{false};
280 // controlled by WalletRescanReserver
281 std::atomic<bool> fScanningWallet{false};
282 std::atomic<bool> m_attaching_chain{false};
283 std::atomic<SteadyClock::time_point> m_scanning_start{
284 SteadyClock::time_point{}};
285 std::atomic<double> m_scanning_progress{0};
287
290 int nWalletVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
291
294 int nWalletMaxVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
295
296 int64_t nNextResend = 0;
298 // Local time that the tip block was received. Used to schedule wallet
299 // rebroadcasts.
300 std::atomic<int64_t> m_best_block_time{0};
301
306 typedef std::multimap<COutPoint, TxId> TxSpends;
308 void AddToSpends(const COutPoint &outpoint, const TxId &wtxid)
311
328 CWalletTx::Confirmation confirm, bool fUpdate)
330
335 void MarkConflicted(const BlockHash &hashBlock, int conflicting_height,
336 const TxId &txid);
337
342 void MarkInputsDirty(const CTransactionRef &tx)
344
345 void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>)
347
354 void SyncTransaction(const CTransactionRef &tx,
355 CWalletTx::Confirmation confirm, bool update_tx = true)
357
358 std::atomic<uint64_t> m_wallet_flags{0};
359
360 bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address,
361 const std::string &strName,
362 const std::string &strPurpose);
363
365 void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag);
366
368 void UnsetBlankWalletFlag(WalletBatch &batch) override;
369
372
374 std::string m_name;
375
377 std::unique_ptr<WalletDatabase> database;
378
386 BlockHash m_last_block_processed GUARDED_BY(cs_wallet);
387
388 /* Height of last block processed is used by wallet to know depth of
389 * transactions without relying on Chain interface beyond asynchronous
390 * updates. For safety, we initialize it to -1. Height is a pointer on
391 * node's tip and doesn't imply that the wallet has scanned sequentially all
392 * blocks up to this one.
393 */
394 int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
395
396 std::map<OutputType, ScriptPubKeyMan *> m_external_spk_managers;
397 std::map<OutputType, ScriptPubKeyMan *> m_internal_spk_managers;
398
399 // Indexed by a unique identifier produced by each ScriptPubKeyMan using
400 // ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal
401 // structure
402 std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
403
409 static bool AttachChain(const std::shared_ptr<CWallet> &wallet,
411 std::vector<bilingual_str> &warnings);
412
413public:
414 /*
415 * Main wallet lock.
416 * This lock protects all the fields added by CWallet.
417 */
419
425 WalletDatabase &GetDatabase() override { return *database; }
426
430 const std::string &GetName() const { return m_name; }
431
432 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
434 unsigned int nMasterKeyMaxID = 0;
435
437 CWallet(interfaces::Chain *chain, const std::string &name,
438 std::unique_ptr<WalletDatabase> _database)
439 : m_chain(chain), m_name(name), database(std::move(_database)) {}
440
442 // Should not have slots connected at this point.
443 assert(NotifyUnload.empty());
444 }
445
446 /* Returns the chain params used by this wallet. */
447 const CChainParams &GetChainParams() const override;
448
449 bool IsCrypted() const;
450 bool IsLocked() const override;
451 bool Lock();
452
454 bool HaveChain() const { return m_chain ? true : false; }
455
456 std::map<TxId, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
457
458 typedef std::multimap<int64_t, CWalletTx *> TxItems;
460
461 int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
463
464 std::map<CTxDestination, CAddressBookData>
465 m_address_book GUARDED_BY(cs_wallet);
466 const CAddressBookData *
468 bool allow_change = false) const
470
471 std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
472
475
477 interfaces::Chain &chain() const {
479 return *m_chain;
480 }
481
482 const CWalletTx *GetWalletTx(const TxId &txid) const
484
485 std::set<TxId> GetTxConflicts(const CWalletTx &wtx) const
487
494 int GetTxDepthInMainChain(const CWalletTx &wtx) const
496 bool IsTxInMainChain(const CWalletTx &wtx) const
499
500 return GetTxDepthInMainChain(wtx) > 0;
501 }
502
508 int GetTxBlocksToMaturity(const CWalletTx &wtx) const
510 bool IsTxImmatureCoinBase(const CWalletTx &wtx) const
512
515 bool CanSupportFeature(enum WalletFeature wf) const override
518 return nWalletMaxVersion >= wf;
519 }
520
521 bool IsSpent(const COutPoint &outpoint) const
523
524 // Whether this or any UTXO with the same CTxDestination has been spent.
525 bool IsSpentKey(const TxId &txid, unsigned int n) const
527 void SetSpentKeyState(WalletBatch &batch, const TxId &txid, unsigned int n,
528 bool used, std::set<CTxDestination> &tx_destinations)
530
531 bool IsLockedCoin(const COutPoint &outpoint) const
533 void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
534 void UnlockCoin(const COutPoint &output)
537 void ListLockedCoins(std::vector<COutPoint> &vOutpts) const
539
540 /*
541 * Rescan abort properties
542 */
543 void AbortRescan() { fAbortRescan = true; }
544 bool IsAbortingRescan() const { return fAbortRescan; }
545 bool IsScanning() const { return fScanningWallet; }
546 SteadyClock::duration ScanningDuration() const {
547 return fScanningWallet ? SteadyClock::now() - m_scanning_start.load()
548 : SteadyClock::duration{};
549 }
550 double ScanningProgress() const {
551 return fScanningWallet ? double(m_scanning_progress) : 0;
552 }
553
557
560 nWalletVersion = nVersion;
561 nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion);
562 return true;
563 }
564
570 bool AddDestData(WalletBatch &batch, const CTxDestination &dest,
571 const std::string &key, const std::string &value)
574 bool EraseDestData(WalletBatch &batch, const CTxDestination &dest,
575 const std::string &key)
578 void LoadDestData(const CTxDestination &dest, const std::string &key,
579 const std::string &value)
583 bool GetDestData(const CTxDestination &dest, const std::string &key,
584 std::string *value) const
587 std::vector<std::string> GetDestValues(const std::string &prefix) const
589
593 int64_t nRelockTime GUARDED_BY(cs_wallet){0};
594
595 // Used to prevent concurrent calls to walletpassphrase RPC.
597 bool Unlock(const SecureString &strWalletPassphrase,
598 bool accept_no_keys = false);
599 bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase,
600 const SecureString &strNewWalletPassphrase);
601 bool EncryptWallet(const SecureString &strWalletPassphrase);
602
603 void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const
605 unsigned int ComputeTimeSmart(const CWalletTx &wtx) const;
606
611 int64_t IncOrderPosNext(WalletBatch *batch = nullptr)
614
615 void MarkDirty();
616
625 using UpdateWalletTxFn = std::function<bool(CWalletTx &wtx, bool new_tx)>;
626
628 const CWalletTx::Confirmation &confirm,
629 const UpdateWalletTxFn &update_wtx = nullptr,
630 bool fFlushOnClose = true);
631 bool LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx)
634 uint64_t mempool_sequence) override;
635 void blockConnected(ChainstateRole role, const CBlock &block,
636 int height) override;
637 void blockDisconnected(const CBlock &block, int height) override;
638 void updatedBlockTip() override;
639 int64_t RescanFromTime(int64_t startTime,
640 const WalletRescanReserver &reserver, bool update);
641
642 struct ScanResult {
643 enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
644
649 std::optional<int> last_scanned_height;
650
656 };
658 int start_height,
659 std::optional<int> max_height,
660 const WalletRescanReserver &reserver,
661 bool fUpdate);
664 uint64_t mempool_sequence) override;
667
669 TransactionChangeType(const std::optional<OutputType> &change_type,
670 const std::vector<CRecipient> &vecSend) const;
671
672 // Fetch the inputs and sign with SIGHASH_ALL.
675 // Sign the tx given the input coins and sighash.
677 const std::map<COutPoint, Coin> &coins,
678 SigHashType sighash,
679 std::map<int, std::string> &input_errors) const;
680 SigningResult SignMessage(const std::string &message, const PKHash &pkhash,
681 std::string &str_sig) const;
682
698 std::optional<common::PSBTError>
699 FillPSBT(PartiallySignedTransaction &psbtx, bool &complete,
700 SigHashType sighash_type = SigHashType().withForkId(),
701 bool sign = true, bool bip32derivs = true) const;
702
715 CTransactionRef tx, mapValue_t mapValue,
716 std::vector<std::pair<std::string, std::string>> orderForm,
717 bool broadcast = true);
718
724 std::string &err_string, bool relay) const
726
727 bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts,
728 bool use_max_sig = false) const {
729 std::vector<CTxOut> v_txouts(txouts.size());
730 std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
731 return DummySignTx(txNew, v_txouts, use_max_sig);
732 }
734 const std::vector<CTxOut> &txouts,
735 bool use_max_sig = false) const;
736 bool DummySignInput(CTxIn &tx_in, const CTxOut &txout,
737 bool use_max_sig = false) const;
738
739 bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp)
741 bool ImportPrivKeys(const std::map<CKeyID, CKey> &privkey_map,
742 const int64_t timestamp)
744 bool ImportPubKeys(
745 const std::vector<CKeyID> &ordered_pubkeys,
746 const std::map<CKeyID, CPubKey> &pubkey_map,
747 const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> &key_origins,
748 const bool add_keypool, const bool internal, const int64_t timestamp)
750 bool ImportScriptPubKeys(const std::string &label,
751 const std::set<CScript> &script_pub_keys,
752 const bool have_solving_data,
753 const bool apply_label, const int64_t timestamp)
755
760 // Override with -mintxfee
777 std::optional<OutputType> m_default_change_type{};
783
785 bool TopUpKeyPool(unsigned int kpSize = 0);
786
787 int64_t GetOldestKeyPoolTime() const;
788
789 std::set<CTxDestination> GetLabelAddresses(const std::string &label) const
791
796 void MarkDestinationsDirty(const std::set<CTxDestination> &destinations)
798
800 const std::string &label);
802
803 isminetype IsMine(const CTxDestination &dest) const
805 isminetype IsMine(const CScript &script) const
811 Amount GetDebit(const CTxIn &txin, const isminefilter &filter) const;
812 isminetype IsMine(const CTxOut &txout) const
814 ;
815 bool IsMine(const CTransaction &tx) const
818 bool IsFromMe(const CTransaction &tx) const;
819 Amount GetDebit(const CTransaction &tx, const isminefilter &filter) const;
821 const CBlockLocator &loc) override;
822
824 DBErrors ZapSelectTx(std::vector<TxId> &txIdsIn,
825 std::vector<TxId> &txIdsOut)
827
828 bool SetAddressBook(const CTxDestination &address,
829 const std::string &strName, const std::string &purpose);
830
831 bool DelAddressBook(const CTxDestination &address);
832
834
837 void SetMinVersion(enum WalletFeature, WalletBatch *batch_in = nullptr,
838 bool fExplicit = false) override;
839
842 bool SetMaxVersion(int nVersion);
843
846 int GetVersion() const {
848 return nWalletVersion;
849 }
850
853 std::set<TxId> GetConflicts(const TxId &txid) const
855
858 bool HasWalletSpend(const TxId &txid) const
860
862 void Flush();
863
865 void Close();
866
868 boost::signals2::signal<void()> NotifyUnload;
869
874 boost::signals2::signal<void(CWallet *wallet, const CTxDestination &address,
875 const std::string &label, bool isMine,
876 const std::string &purpose, ChangeType status)>
878
883 boost::signals2::signal<void(CWallet *wallet, const TxId &txid,
884 ChangeType status)>
886
888 boost::signals2::signal<void(const std::string &title, int nProgress)>
890
892 boost::signals2::signal<void(bool fHaveWatchOnly)> NotifyWatchonlyChanged;
893
895 boost::signals2::signal<void()> NotifyCanGetAddressesChanged;
896
901 boost::signals2::signal<void(CWallet *wallet)> NotifyStatusChanged;
902
906 void SetBroadcastTransactions(bool broadcast) {
907 fBroadcastTransactions = broadcast;
908 }
909
911 bool TransactionCanBeAbandoned(const TxId &txid) const;
912
917 bool AbandonTransaction(const TxId &txid);
918
923 static std::shared_ptr<CWallet>
924 Create(WalletContext &context, const std::string &name,
925 std::unique_ptr<WalletDatabase> database,
926 uint64_t wallet_creation_flags, bilingual_str &error,
927 std::vector<bilingual_str> &warnings);
928
934 void postInitProcess();
935
936 bool BackupWallet(const std::string &strDest) const;
937
938 /* Returns true if HD is enabled */
939 bool IsHDEnabled() const;
940
945 bool CanGetAddresses(bool internal = false) const;
946
953 void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main)
955
959 void SetWalletFlag(uint64_t flags);
960
964 void UnsetWalletFlag(uint64_t flag);
965
969 bool IsWalletFlagSet(uint64_t flag) const override;
970
975 bool AddWalletFlags(uint64_t flags);
977 bool LoadWalletFlags(uint64_t flags);
978
980 bool IsLegacy() const;
981
986 std::string GetDisplayName() const override {
987 std::string wallet_name =
988 GetName().length() == 0 ? "default wallet" : GetName();
989 return strprintf("[%s]", wallet_name);
990 };
991
996 template <typename... Params>
997 void WalletLogPrintf(std::string fmt, Params... parameters) const {
998 LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
999 };
1000
1001 template <typename... Params>
1002 void WalletLogPrintfToBeContinued(std::string fmt,
1003 Params... parameters) const {
1004 LogPrintfToBeContinued(("%s " + fmt).c_str(), GetDisplayName(),
1005 parameters...);
1006 };
1007
1009 bool UpgradeWallet(int version, bilingual_str &error);
1010
1013 std::set<ScriptPubKeyMan *> GetActiveScriptPubKeyMans() const;
1014
1016 std::set<ScriptPubKeyMan *> GetAllScriptPubKeyMans() const;
1017
1021 bool internal) const;
1022
1024 ScriptPubKeyMan *GetScriptPubKeyMan(const CScript &script) const;
1026 ScriptPubKeyMan *GetScriptPubKeyMan(const uint256 &id) const;
1027
1030 std::set<ScriptPubKeyMan *>
1031 GetScriptPubKeyMans(const CScript &script, SignatureData &sigdata) const;
1032
1034 std::unique_ptr<SigningProvider>
1035 GetSolvingProvider(const CScript &script) const;
1036 std::unique_ptr<SigningProvider>
1037 GetSolvingProvider(const CScript &script, SignatureData &sigdata) const;
1038
1043
1047
1048 bool WithEncryptionKey(
1049 const std::function<bool(const CKeyingMaterial &)> &cb) const override;
1050
1051 bool HasEncryptionKeys() const override;
1052
1056 assert(m_last_block_processed_height >= 0);
1057 return m_last_block_processed_height;
1058 };
1061 assert(m_last_block_processed_height >= 0);
1062 return m_last_block_processed;
1063 }
1065 void SetLastBlockProcessed(int block_height, BlockHash block_hash)
1068 m_last_block_processed_height = block_height;
1069 m_last_block_processed = block_hash;
1070 };
1071
1074
1078
1086 void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1087
1095 void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1096
1104 void DeactivateScriptPubKeyMan(const uint256 &id, OutputType type,
1105 bool internal);
1106
1109
1114
1119 const FlatSigningProvider &signing_provider,
1120 const std::string &label, bool internal)
1122};
1123
1129void MaybeResendWalletTxs(WalletContext &context);
1130
1133private:
1136
1137public:
1139 : m_wallet(w), m_could_reserve(false) {}
1140
1141 bool reserve() {
1143 if (m_wallet.fScanningWallet.exchange(true)) {
1144 return false;
1145 }
1146 m_wallet.m_scanning_start = SteadyClock::now();
1147 m_wallet.m_scanning_progress = 0;
1148 m_could_reserve = true;
1149 return true;
1150 }
1151
1152 bool isReserved() const {
1153 return (m_could_reserve && m_wallet.fScanningWallet);
1154 }
1155
1157 if (m_could_reserve) {
1158 m_wallet.fScanningWallet = false;
1159 }
1160 }
1161};
1162
1164bool AddWalletSetting(interfaces::Chain &chain, const std::string &wallet_name);
1165
1169 const std::string &wallet_name);
1170
1171#endif // BITCOIN_WALLET_WALLET_H
static constexpr Amount SATOSHI
Definition: amount.h:148
static constexpr Amount COIN
Definition: amount.h:149
int flags
Definition: bitcoin-tx.cpp:546
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:21
Address book data.
Definition: wallet.h:217
StringMap destdata
Definition: wallet.h:228
std::map< std::string, std::string > StringMap
Definition: wallet.h:227
std::string m_label
Definition: wallet.h:220
const std::string & GetLabel() const
Definition: wallet.h:231
std::string purpose
Definition: wallet.h:223
bool IsChange() const
Definition: wallet.h:230
void SetLabel(const std::string &label)
Definition: wallet.h:232
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:272
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
Get the SigningProvider for a script.
Definition: wallet.cpp:3377
std::atomic< int64_t > m_best_block_time
Definition: wallet.h:300
bool Lock()
Definition: wallet.cpp:3277
BlockHash GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:1059
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:593
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:3348
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:868
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:432
bool HaveChain() const
Interface to assert chain access.
Definition: wallet.h:454
int GetTxBlocksToMaturity(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3246
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:550
bool DummySignTx(CMutableTransaction &txNew, const std::set< CTxOut > &txouts, bool use_max_sig=false) const
Definition: wallet.h:727
uint64_t nAccountingEntryNumber
Definition: wallet.h:462
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
Definition: wallet.cpp:3437
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Adds the active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3490
void SetupLegacyScriptPubKeyMan()
Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
Definition: wallet.cpp:3412
Mutex m_unlock_mutex
Definition: wallet.h:596
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:2687
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition: wallet.h:895
MasterKeyMap mapMasterKeys
Definition: wallet.h:433
std::string m_name
Wallet name: relative directory name or "" for default wallet.
Definition: wallet.h:374
TxItems wtxOrdered
Definition: wallet.h:459
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:3236
bool IsTxImmatureCoinBase(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3258
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:889
RecursiveMutex cs_wallet
Definition: wallet.h:418
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
Definition: wallet.cpp:3296
SteadyClock::duration ScanningDuration() const
Definition: wallet.h:546
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:306
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:904
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:997
bool IsAbortingRescan() const
Definition: wallet.h:544
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition: wallet.h:477
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new DescriptorScriptPubKeyMans and add them to the wallet.
Definition: wallet.cpp:3452
WalletDatabase & GetDatabase() override
Definition: wallet.h:425
interfaces::Chain * m_chain
Interface for accessing chain state.
Definition: wallet.h:371
std::atomic< bool > m_attaching_chain
Definition: wallet.h:282
bool WithEncryptionKey(const std::function< bool(const CKeyingMaterial &)> &cb) const override
Pass the encryption key to cb().
Definition: wallet.cpp:3427
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
Definition: wallet.cpp:3407
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
Definition: wallet.h:396
void DeactivateScriptPubKeyMan(const uint256 &id, OutputType type, bool internal)
Remove specified ScriptPubKeyMan from set of active SPK managers.
Definition: wallet.cpp:3528
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:2711
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:767
bool IsLegacy() const
Determine if we are a legacy wallet.
Definition: wallet.cpp:3551
std::atomic< bool > fAbortRescan
Definition: wallet.h:279
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
Definition: wallet.h:402
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Loads an active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3501
std::unique_ptr< interfaces::Handler > m_chain_notifications_handler
Registered interfaces::Chain::Notifications handler.
Definition: wallet.h:474
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:906
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:877
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition: wallet.h:1054
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: wallet.h:901
OutputType m_default_address_type
Definition: wallet.h:770
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
Definition: wallet.cpp:3561
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:3010
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
Definition: wallet.cpp:3445
LegacyScriptPubKeyMan * GetLegacyScriptPubKeyMan() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
Definition: wallet.cpp:3393
std::atomic< uint64_t > m_wallet_flags
Definition: wallet.h:358
Amount m_max_aps_fee
note: this is absolute fee, not fee rate
Definition: wallet.h:769
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:430
CFeeRate m_pay_tx_fee
Definition: wallet.h:756
int64_t nNextResend
Definition: wallet.h:296
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:515
bool BackupWallet(const std::string &strDest) const
Definition: wallet.cpp:3210
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:496
unsigned int ComputeTimeSmart(const CWalletTx &wtx) const
Compute smart timestamp for a transaction being added to the wallet.
Definition: wallet.cpp:2645
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet)
bool IsScanning() const
Definition: wallet.h:545
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:1002
std::unique_ptr< WalletDatabase > database
Internal database handle.
Definition: wallet.h:377
std::atomic< SteadyClock::time_point > m_scanning_start
Definition: wallet.h:283
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:3577
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:3311
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:558
CFeeRate m_min_fee
Definition: wallet.h:761
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:2730
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:892
bool IsLocked() const override
Definition: wallet.cpp:3269
bool m_allow_fallback_fee
will be false if -fallbackfee=0
Definition: wallet.h:759
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
Definition: wallet.h:397
std::atomic< double > m_scanning_progress
Definition: wallet.h:285
~CWallet()
Definition: wallet.h:441
int GetVersion() const
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.h:846
WalletDatabase & GetDBHandle()
Get database handle used by this wallet.
Definition: wallet.h:424
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2553
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:2697
boost::signals2::signal< void(CWallet *wallet, const TxId &txid, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:885
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:2775
bool HasEncryptionKeys() const override
Definition: wallet.cpp:3433
bool m_spend_zero_conf_change
Definition: wallet.h:757
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > _database)
Construct wallet with specified name and database implementation.
Definition: wallet.h:437
Amount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
Definition: wallet.h:782
bool UpgradeWallet(int version, bilingual_str &error)
Upgrade the wallet.
Definition: wallet.cpp:3156
bool fBroadcastTransactions
Definition: wallet.h:297
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
Definition: wallet.cpp:3332
bool IsCrypted() const
Definition: wallet.cpp:3265
std::atomic< bool > fScanningWallet
Definition: wallet.h:281
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
Definition: wallet.cpp:3324
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:458
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:986
std::optional< OutputType > m_default_change_type
Default output type for change outputs.
Definition: wallet.h:777
void AbortRescan()
Definition: wallet.h:543
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:2706
unsigned int nMasterKeyMaxID
Definition: wallet.h:434
std::function< bool(CWalletTx &wtx, bool new_tx)> UpdateWalletTxFn
Callback for updating transaction metadata in mapWallet.
Definition: wallet.h:625
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition: wallet.cpp:3199
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:1065
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3144
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:179
bool fInternal
Whether this is from the internal (change output) keypool.
Definition: wallet.h:192
ReserveDestination & operator=(const ReserveDestination &)=delete
OutputType const type
Definition: wallet.h:186
~ReserveDestination()
Destructor.
Definition: wallet.h:205
ReserveDestination(CWallet *_pwallet, OutputType _type)
Construct a ReserveDestination object.
Definition: wallet.h:197
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from.
Definition: wallet.h:185
int64_t nIndex
The index of the address's key in the keypool.
Definition: wallet.h:188
CTxDestination address
The destination.
Definition: wallet.h:190
ReserveDestination(const ReserveDestination &)=delete
const CWallet *const pwallet
The wallet to reserve from.
Definition: wallet.h:182
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:1132
bool isReserved() const
Definition: wallet.h:1152
CWallet & m_wallet
Definition: wallet.h:1134
WalletRescanReserver(CWallet &w)
Definition: wallet.h:1138
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
void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2523
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:2446
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2374
std::optional< common::PSBTError > 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:2128
util::Result< CTxDestination > GetNewDestination(const OutputType type, const std::string &label)
Definition: wallet.cpp:2405
util::Result< CTxDestination > GetNewChangeDestination(const OutputType type)
Definition: wallet.cpp:2422
void KeepDestination()
Keep the address.
Definition: wallet.cpp:2506
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2544
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2385
std::set< CTxDestination > GetLabelAddresses(const std::string &label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2467
bool IsLockedCoin(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2538
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Definition: wallet.cpp:2173
void UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2528
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:2333
DBErrors LoadWallet()
Definition: wallet.cpp:2250
OutputType TransactionChangeType(const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
Definition: wallet.cpp:2187
bool SignTransaction(CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2081
void ReturnDestination()
Return reserved address.
Definition: wallet.cpp:2515
void UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2533
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:2395
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::string &strPurpose)
Definition: wallet.cpp:2306
bool GetReservedDestination(CTxDestination &pubkey, bool internal)
Reserve an address.
Definition: wallet.cpp:2485
int64_t GetOldestKeyPoolTime() const
Definition: wallet.cpp:2436
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:2340
DBErrors ZapSelectTx(std::vector< TxId > &txIdsIn, std::vector< TxId > &txIdsOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2274
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:2203
bool AddWalletFlags(uint64_t flags)
Overwrite all flags by the given uint64_t.
Definition: wallet.cpp:1609
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:1684
bool LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1119
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:1302
void Flush()
Flush wallet (bitdb flush)
Definition: wallet.cpp:676
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
Definition: wallet.cpp:468
bool SetMaxVersion(int nVersion)
change which version we're allowed to upgrade to (note that this does not immediately imply upgrading...
Definition: wallet.cpp:628
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:641
void MarkDirty()
Definition: wallet.cpp:967
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:1958
void AddToSpends(const COutPoint &outpoint, const TxId &wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:754
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:1359
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1664
CWalletTx * AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation &confirm, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true)
Definition: wallet.cpp:1025
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:670
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:512
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:1567
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:1526
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1674
void blockConnected(ChainstateRole role, const CBlock &block, int height) override
Definition: wallet.cpp:1427
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1501
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition: wallet.cpp:1598
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:1698
bool CanGetAddresses(bool internal=false) const
Returns true if the wallet can give out new addresses.
Definition: wallet.cpp:1553
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:1784
bool IsSpentKey(const TxId &txid, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:998
bool TransactionCanBeAbandoned(const TxId &txid) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1227
const CChainParams & GetChainParams() const override
Definition: wallet.cpp:452
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:1480
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 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:1170
bool IsSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction, spends it:
Definition: wallet.cpp:733
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1925
bool IsHDEnabled() const
Definition: wallet.cpp:1544
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Definition: wallet.cpp:1581
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:684
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:778
void chainStateFlushed(ChainstateRole role, const CBlockLocator &loc) override
Definition: wallet.cpp:590
void updatedBlockTip() override
Definition: wallet.cpp:1463
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
Definition: wallet.cpp:1576
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Definition: wallet.cpp:1385
bool IsWalletFlagSet(uint64_t flag) const override
Check if a certain wallet flag is set.
Definition: wallet.cpp:1594
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1733
bool AbandonTransaction(const TxId &txid)
Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent.
Definition: wallet.cpp:1243
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
Definition: wallet.cpp:1590
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:974
void transactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
Definition: wallet.cpp:1372
DBErrors ReorderTransactions()
Definition: wallet.cpp:899
void blockDisconnected(const CBlock &block, int height) override
Definition: wallet.cpp:1446
void Close()
Close wallet database.
Definition: wallet.cpp:680
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
Definition: wallet.cpp:955
const CWalletTx * GetWalletTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:458
void ResendWalletTransactions()
Definition: wallet.cpp:2019
void SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr, bool fExplicit=false) override
signify that a particular wallet feature is now used.
Definition: wallet.cpp:600
std::set< TxId > GetTxConflicts(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1999
bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig=false) const
Definition: wallet.cpp:1623
uint8_t isminefilter
Definition: wallet.h:45
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
Definition: args.cpp:864
PSBTError
Definition: types.h:17
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:813
const char * name
Definition: rest.cpp:47
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:55
SigningResult
Definition: signmessage.h:47
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:85
Definition: amount.h:21
static constexpr Amount zero() noexcept
Definition: amount.h:34
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:108
CScript scriptPubKey
Definition: wallet.h:239
Amount nAmount
Definition: wallet.h:240
bool fSubtractFeeFromAmount
Definition: wallet.h:241
std::optional< int > last_scanned_height
Definition: wallet.h:649
BlockHash last_scanned_block
Hash and height of most recent block that was successfully scanned.
Definition: wallet.h:648
BlockHash last_failed_block
Hash of the most recent block that could not be scanned due to read errors or pruning.
Definition: wallet.h:655
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:251
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:254
size_t change_spend_size
Definition: wallet.h:247
size_t tx_noinputs_size
Definition: wallet.h:249
bool m_avoid_partial_spends
Definition: wallet.h:252
CFeeRate effective_fee
Definition: wallet.h:248
size_t change_output_size
Definition: wallet.h:246
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:481
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:128
constexpr Amount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:101
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:124
std::unique_ptr< interfaces::Handler > HandleLoadWallet(WalletContext &context, LoadWalletFn load_wallet)
Definition: wallet.cpp:173
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:144
static constexpr uint64_t MUTABLE_WALLET_FLAGS
Definition: wallet.h:151
constexpr Amount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition: wallet.h:131
const std::map< uint64_t, std::string > WALLET_FLAG_CAVEATS
Definition: wallet.cpp:51
static const std::map< std::string, WalletFlags > WALLET_FLAG_MAP
Definition: wallet.h:153
static constexpr size_t DUMMY_P2PKH_INPUT_SIZE
Pre-calculated constants for input size estimation.
Definition: wallet.h:133
static const Amount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:103
static const Amount DEFAULT_TRANSACTION_MINFEE_PER_KB
-mintxfee default
Definition: wallet.h:105
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:124
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Definition: wallet.cpp:2743
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Definition: wallet.cpp:216
void MaybeResendWalletTxs(WalletContext &context)
Called periodically by the schedule thread.
Definition: wallet.cpp:2069
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:110
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:122
static constexpr uint64_t KNOWN_WALLET_FLAGS
Definition: wallet.h:146
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Definition: wallet.cpp:156
constexpr Amount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:126
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:116
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:58
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:402
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:73
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:123
std::shared_ptr< CWallet > GetWallet(WalletContext &context, const std::string &name)
Definition: wallet.cpp:161
constexpr Amount HIGH_APS_FEE
discourage APS fee higher than this amount
Definition: wallet.h:118
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:300
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:282
void NotifyWalletLoaded(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:183
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