Bitcoin ABC 0.30.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/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/strencodings.h>
21#include <util/string.h>
22#include <util/translation.h>
23#include <util/ui_change_type.h>
24#include <validationinterface.h>
26#include <wallet/crypter.h>
27#include <wallet/rpcwallet.h>
29#include <wallet/transaction.h>
30#include <wallet/walletdb.h>
31#include <wallet/walletutil.h>
32
33#include <algorithm>
34#include <atomic>
35#include <cstdint>
36#include <map>
37#include <memory>
38#include <optional>
39#include <set>
40#include <stdexcept>
41#include <string>
42#include <utility>
43#include <vector>
44
45#include <boost/signals2/signal.hpp>
46
48 std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
49
50struct bilingual_str;
51
57void UnloadWallet(std::shared_ptr<CWallet> &&wallet);
58
59bool AddWallet(const std::shared_ptr<CWallet> &wallet);
60bool RemoveWallet(const std::shared_ptr<CWallet> &wallet,
61 std::optional<bool> load_on_start,
62 std::vector<bilingual_str> &warnings);
63bool RemoveWallet(const std::shared_ptr<CWallet> &wallet,
64 std::optional<bool> load_on_start);
65std::vector<std::shared_ptr<CWallet>> GetWallets();
66std::shared_ptr<CWallet> GetWallet(const std::string &name);
67std::shared_ptr<CWallet>
68LoadWallet(interfaces::Chain &chain, const std::string &name,
69 std::optional<bool> load_on_start, const DatabaseOptions &options,
71 std::vector<bilingual_str> &warnings);
72std::shared_ptr<CWallet>
73CreateWallet(interfaces::Chain &chain, const std::string &name,
74 std::optional<bool> load_on_start, const DatabaseOptions &options,
76 std::vector<bilingual_str> &warnings);
77std::unique_ptr<interfaces::Handler> HandleLoadWallet(LoadWalletFn load_wallet);
78std::unique_ptr<WalletDatabase>
79MakeWalletDatabase(const std::string &name, const DatabaseOptions &options,
81
100constexpr Amount HIGH_APS_FEE{COIN / 10000};
104static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
105static const bool DEFAULT_WALLETBROADCAST = true;
106static const bool DEFAULT_DISABLE_WALLET = false;
115static constexpr size_t DUMMY_P2PKH_INPUT_SIZE = 148;
116
117class CChainParams;
118class CCoinControl;
119class COutput;
120class CScript;
121class CTxMemPool;
122class CWalletTx;
124
127
128static constexpr uint64_t KNOWN_WALLET_FLAGS =
132
134
135static const std::map<std::string, WalletFlags> WALLET_FLAG_MAP{
136 {"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
137 {"blank", WALLET_FLAG_BLANK_WALLET},
138 {"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
139 {"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
140 {"descriptor_wallet", WALLET_FLAG_DESCRIPTORS},
141};
142
143extern const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS;
144
162protected:
164 const CWallet *const pwallet;
170 int64_t nIndex{-1};
174 bool fInternal{false};
175
176public:
179 explicit ReserveDestination(CWallet *_pwallet, OutputType _type)
180 : pwallet(_pwallet), type(_type) {}
181
184
188
190 bool GetReservedDestination(CTxDestination &pubkey, bool internal);
192 void ReturnDestination();
195 void KeepDestination();
196};
197
200private:
201 bool m_change{true};
202 std::string m_label;
203
204public:
205 std::string purpose;
206
207 CAddressBookData() : purpose("unknown") {}
208
209 typedef std::map<std::string, std::string> StringMap;
211
212 bool IsChange() const { return m_change; }
213 const std::string &GetLabel() const { return m_label; }
214 void SetLabel(const std::string &label) {
215 m_change = false;
216 m_label = label;
217 }
218};
219
224};
225
227 bool use_bnb = true;
235
236 CoinSelectionParams(bool use_bnb_, size_t change_output_size_,
237 size_t change_spend_size_, CFeeRate effective_fee_,
238 size_t tx_noinputs_size_, bool avoid_partial)
239 : use_bnb(use_bnb_), change_output_size(change_output_size_),
240 change_spend_size(change_spend_size_), effective_fee(effective_fee_),
241 tx_noinputs_size(tx_noinputs_size_),
242 m_avoid_partial_spends(avoid_partial) {}
244};
245
246// forward declarations for ScanForWalletTransactions/RescanFromTime
248
253class CWallet final : public WalletStorage,
255private:
257
258 bool Unlock(const CKeyingMaterial &vMasterKeyIn,
259 bool accept_no_keys = false);
260
261 std::atomic<bool> fAbortRescan{false};
262 // controlled by WalletRescanReserver
263 std::atomic<bool> fScanningWallet{false};
264 std::atomic<int64_t> m_scanning_start{0};
265 std::atomic<double> m_scanning_progress{0};
267
270 int nWalletVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
271
274 int nWalletMaxVersion GUARDED_BY(cs_wallet) = FEATURE_BASE;
275
276 int64_t nNextResend = 0;
278 // Local time that the tip block was received. Used to schedule wallet
279 // rebroadcasts.
280 std::atomic<int64_t> m_best_block_time{0};
281
286 typedef std::multimap<COutPoint, TxId> TxSpends;
288 void AddToSpends(const COutPoint &outpoint, const TxId &wtxid)
291
308 CWalletTx::Confirmation confirm, bool fUpdate)
310
315 void MarkConflicted(const BlockHash &hashBlock, int conflicting_height,
316 const TxId &txid);
317
322 void MarkInputsDirty(const CTransactionRef &tx)
324
325 void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>)
327
334 void SyncTransaction(const CTransactionRef &tx,
335 CWalletTx::Confirmation confirm, bool update_tx = true)
337
338 std::atomic<uint64_t> m_wallet_flags{0};
339
340 bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address,
341 const std::string &strName,
342 const std::string &strPurpose);
343
345 void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag);
346
348 void UnsetBlankWalletFlag(WalletBatch &batch) override;
349
352
354 std::string m_name;
355
357 std::unique_ptr<WalletDatabase> database;
358
366 BlockHash m_last_block_processed GUARDED_BY(cs_wallet);
367
368 /* Height of last block processed is used by wallet to know depth of
369 * transactions without relying on Chain interface beyond asynchronous
370 * updates. For safety, we initialize it to -1. Height is a pointer on
371 * node's tip and doesn't imply that the wallet has scanned sequentially all
372 * blocks up to this one.
373 */
374 int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
375
376 std::map<OutputType, ScriptPubKeyMan *> m_external_spk_managers;
377 std::map<OutputType, ScriptPubKeyMan *> m_internal_spk_managers;
378
379 // Indexed by a unique identifier produced by each ScriptPubKeyMan using
380 // ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal
381 // structure
382 std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
383
389 static bool AttachChain(const std::shared_ptr<CWallet> &wallet,
391 std::vector<bilingual_str> &warnings);
392
393public:
394 /*
395 * Main wallet lock.
396 * This lock protects all the fields added by CWallet.
397 */
399
405 WalletDatabase &GetDatabase() override { return *database; }
406
410 const std::string &GetName() const { return m_name; }
411
412 typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
414 unsigned int nMasterKeyMaxID = 0;
415
417 CWallet(interfaces::Chain *chain, const std::string &name,
418 std::unique_ptr<WalletDatabase> _database)
419 : m_chain(chain), m_name(name), database(std::move(_database)) {}
420
422 // Should not have slots connected at this point.
423 assert(NotifyUnload.empty());
424 }
425
426 /* Returns the chain params used by this wallet. */
427 const CChainParams &GetChainParams() const override;
428
429 bool IsCrypted() const;
430 bool IsLocked() const override;
431 bool Lock();
432
434 bool HaveChain() const { return m_chain ? true : false; }
435
436 std::map<TxId, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
437
438 typedef std::multimap<int64_t, CWalletTx *> TxItems;
440
441 int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
443
444 std::map<CTxDestination, CAddressBookData>
445 m_address_book GUARDED_BY(cs_wallet);
446 const CAddressBookData *
448 bool allow_change = false) const
450
451 std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
452
455
457 interfaces::Chain &chain() const {
459 return *m_chain;
460 }
461
462 const CWalletTx *GetWalletTx(const TxId &txid) const
464
465 std::set<TxId> GetTxConflicts(const CWalletTx &wtx) const
467
474 int GetTxDepthInMainChain(const CWalletTx &wtx) const
476 bool IsTxInMainChain(const CWalletTx &wtx) const
479
480 return GetTxDepthInMainChain(wtx) > 0;
481 }
482
488 int GetTxBlocksToMaturity(const CWalletTx &wtx) const
490 bool IsTxImmatureCoinBase(const CWalletTx &wtx) const
492
495 bool CanSupportFeature(enum WalletFeature wf) const override
498 return nWalletMaxVersion >= wf;
499 }
500
501 bool IsSpent(const COutPoint &outpoint) const
503
504 // Whether this or any UTXO with the same CTxDestination has been spent.
505 bool IsSpentKey(const TxId &txid, unsigned int n) const
507 void SetSpentKeyState(WalletBatch &batch, const TxId &txid, unsigned int n,
508 bool used, std::set<CTxDestination> &tx_destinations)
510
511 bool IsLockedCoin(const COutPoint &outpoint) const
513 void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
514 void UnlockCoin(const COutPoint &output)
517 void ListLockedCoins(std::vector<COutPoint> &vOutpts) const
519
520 /*
521 * Rescan abort properties
522 */
523 void AbortRescan() { fAbortRescan = true; }
524 bool IsAbortingRescan() const { return fAbortRescan; }
525 bool IsScanning() const { return fScanningWallet; }
526 int64_t ScanningDuration() const {
528 }
529 double ScanningProgress() const {
530 return fScanningWallet ? double(m_scanning_progress) : 0;
531 }
532
536
539 nWalletVersion = nVersion;
540 nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion);
541 return true;
542 }
543
549 bool AddDestData(WalletBatch &batch, const CTxDestination &dest,
550 const std::string &key, const std::string &value)
553 bool EraseDestData(WalletBatch &batch, const CTxDestination &dest,
554 const std::string &key)
557 void LoadDestData(const CTxDestination &dest, const std::string &key,
558 const std::string &value)
562 bool GetDestData(const CTxDestination &dest, const std::string &key,
563 std::string *value) const
566 std::vector<std::string> GetDestValues(const std::string &prefix) const
568
572 int64_t nRelockTime GUARDED_BY(cs_wallet){0};
573
574 // Used to prevent concurrent calls to walletpassphrase RPC.
576 bool Unlock(const SecureString &strWalletPassphrase,
577 bool accept_no_keys = false);
578 bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase,
579 const SecureString &strNewWalletPassphrase);
580 bool EncryptWallet(const SecureString &strWalletPassphrase);
581
582 void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const
584 unsigned int ComputeTimeSmart(const CWalletTx &wtx) const;
585
590 int64_t IncOrderPosNext(WalletBatch *batch = nullptr)
593
594 void MarkDirty();
595
604 using UpdateWalletTxFn = std::function<bool(CWalletTx &wtx, bool new_tx)>;
605
607 const CWalletTx::Confirmation &confirm,
608 const UpdateWalletTxFn &update_wtx = nullptr,
609 bool fFlushOnClose = true);
610 bool LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx)
613 uint64_t mempool_sequence) override;
614 void blockConnected(const CBlock &block, int height) override;
615 void blockDisconnected(const CBlock &block, int height) override;
616 void updatedBlockTip() override;
617 int64_t RescanFromTime(int64_t startTime,
618 const WalletRescanReserver &reserver, bool update);
619
620 struct ScanResult {
621 enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
622
627 std::optional<int> last_scanned_height;
628
634 };
636 int start_height,
637 std::optional<int> max_height,
638 const WalletRescanReserver &reserver,
639 bool fUpdate);
642 uint64_t mempool_sequence) override;
645
647 TransactionChangeType(const std::optional<OutputType> &change_type,
648 const std::vector<CRecipient> &vecSend) const;
649
650 // Fetch the inputs and sign with SIGHASH_ALL.
653 // Sign the tx given the input coins and sighash.
655 const std::map<COutPoint, Coin> &coins,
656 SigHashType sighash,
657 std::map<int, std::string> &input_errors) const;
658 SigningResult SignMessage(const std::string &message, const PKHash &pkhash,
659 std::string &str_sig) const;
660
677 FillPSBT(PartiallySignedTransaction &psbtx, bool &complete,
678 SigHashType sighash_type = SigHashType().withForkId(),
679 bool sign = true, bool bip32derivs = true) const;
680
693 CTransactionRef tx, mapValue_t mapValue,
694 std::vector<std::pair<std::string, std::string>> orderForm,
695 bool broadcast = true);
696
702 std::string &err_string, bool relay) const
704
705 bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts,
706 bool use_max_sig = false) const {
707 std::vector<CTxOut> v_txouts(txouts.size());
708 std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
709 return DummySignTx(txNew, v_txouts, use_max_sig);
710 }
712 const std::vector<CTxOut> &txouts,
713 bool use_max_sig = false) const;
714 bool DummySignInput(CTxIn &tx_in, const CTxOut &txout,
715 bool use_max_sig = false) const;
716
717 bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp)
719 bool ImportPrivKeys(const std::map<CKeyID, CKey> &privkey_map,
720 const int64_t timestamp)
722 bool ImportPubKeys(
723 const std::vector<CKeyID> &ordered_pubkeys,
724 const std::map<CKeyID, CPubKey> &pubkey_map,
725 const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>> &key_origins,
726 const bool add_keypool, const bool internal, const int64_t timestamp)
728 bool ImportScriptPubKeys(const std::string &label,
729 const std::set<CScript> &script_pub_keys,
730 const bool have_solving_data,
731 const bool apply_label, const int64_t timestamp)
733
738 // Override with -mintxfee
755 std::optional<OutputType> m_default_change_type{};
761
763 bool TopUpKeyPool(unsigned int kpSize = 0);
764
765 int64_t GetOldestKeyPoolTime() const;
766
767 std::set<CTxDestination> GetLabelAddresses(const std::string &label) const
769
774 void MarkDestinationsDirty(const std::set<CTxDestination> &destinations)
776
777 bool GetNewDestination(const OutputType type, const std::string label,
778 CTxDestination &dest, std::string &error);
780 std::string &error);
781
782 isminetype IsMine(const CTxDestination &dest) const
784 isminetype IsMine(const CScript &script) const
790 Amount GetDebit(const CTxIn &txin, const isminefilter &filter) const;
791 isminetype IsMine(const CTxOut &txout) const
793 ;
794 bool IsMine(const CTransaction &tx) const
797 bool IsFromMe(const CTransaction &tx) const;
798 Amount GetDebit(const CTransaction &tx, const isminefilter &filter) const;
799 void chainStateFlushed(const CBlockLocator &loc) override;
800
802 DBErrors ZapSelectTx(std::vector<TxId> &txIdsIn,
803 std::vector<TxId> &txIdsOut)
805
806 bool SetAddressBook(const CTxDestination &address,
807 const std::string &strName, const std::string &purpose);
808
809 bool DelAddressBook(const CTxDestination &address);
810
812
815 void SetMinVersion(enum WalletFeature, WalletBatch *batch_in = nullptr,
816 bool fExplicit = false) override;
817
820 bool SetMaxVersion(int nVersion);
821
824 int GetVersion() const {
826 return nWalletVersion;
827 }
828
831 std::set<TxId> GetConflicts(const TxId &txid) const
833
836 bool HasWalletSpend(const TxId &txid) const
838
840 void Flush();
841
843 void Close();
844
846 boost::signals2::signal<void()> NotifyUnload;
847
852 boost::signals2::signal<void(CWallet *wallet, const CTxDestination &address,
853 const std::string &label, bool isMine,
854 const std::string &purpose, ChangeType status)>
856
861 boost::signals2::signal<void(CWallet *wallet, const TxId &txid,
862 ChangeType status)>
864
866 boost::signals2::signal<void(const std::string &title, int nProgress)>
868
870 boost::signals2::signal<void(bool fHaveWatchOnly)> NotifyWatchonlyChanged;
871
873 boost::signals2::signal<void()> NotifyCanGetAddressesChanged;
874
879 boost::signals2::signal<void(CWallet *wallet)> NotifyStatusChanged;
880
884 void SetBroadcastTransactions(bool broadcast) {
885 fBroadcastTransactions = broadcast;
886 }
887
889 bool TransactionCanBeAbandoned(const TxId &txid) const;
890
895 bool AbandonTransaction(const TxId &txid);
896
901 static std::shared_ptr<CWallet>
902 Create(interfaces::Chain *chain, const std::string &name,
903 std::unique_ptr<WalletDatabase> database,
904 uint64_t wallet_creation_flags, bilingual_str &error,
905 std::vector<bilingual_str> &warnings);
906
912 void postInitProcess();
913
914 bool BackupWallet(const std::string &strDest) const;
915
916 /* Returns true if HD is enabled */
917 bool IsHDEnabled() const;
918
923 bool CanGetAddresses(bool internal = false) const;
924
931 void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main)
933
937 void SetWalletFlag(uint64_t flags);
938
942 void UnsetWalletFlag(uint64_t flag);
943
947 bool IsWalletFlagSet(uint64_t flag) const override;
948
953 bool AddWalletFlags(uint64_t flags);
955 bool LoadWalletFlags(uint64_t flags);
956
958 bool IsLegacy() const;
959
964 const std::string GetDisplayName() const override {
965 std::string wallet_name =
966 GetName().length() == 0 ? "default wallet" : GetName();
967 return strprintf("[%s]", wallet_name);
968 };
969
974 template <typename... Params>
975 void WalletLogPrintf(std::string fmt, Params... parameters) const {
976 LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
977 };
978
979 template <typename... Params>
980 void WalletLogPrintfToBeContinued(std::string fmt,
981 Params... parameters) const {
982 LogPrintfToBeContinued(("%s " + fmt).c_str(), GetDisplayName(),
983 parameters...);
984 };
985
987 bool UpgradeWallet(int version, bilingual_str &error);
988
991 std::set<ScriptPubKeyMan *> GetActiveScriptPubKeyMans() const;
992
994 std::set<ScriptPubKeyMan *> GetAllScriptPubKeyMans() const;
995
999 bool internal) const;
1000
1002 ScriptPubKeyMan *GetScriptPubKeyMan(const CScript &script) const;
1004 ScriptPubKeyMan *GetScriptPubKeyMan(const uint256 &id) const;
1005
1008 std::set<ScriptPubKeyMan *>
1009 GetScriptPubKeyMans(const CScript &script, SignatureData &sigdata) const;
1010
1012 std::unique_ptr<SigningProvider>
1013 GetSolvingProvider(const CScript &script) const;
1014 std::unique_ptr<SigningProvider>
1015 GetSolvingProvider(const CScript &script, SignatureData &sigdata) const;
1016
1021
1025
1026 bool WithEncryptionKey(
1027 const std::function<bool(const CKeyingMaterial &)> &cb) const override;
1028
1029 bool HasEncryptionKeys() const override;
1030
1034 assert(m_last_block_processed_height >= 0);
1035 return m_last_block_processed_height;
1036 };
1039 assert(m_last_block_processed_height >= 0);
1040 return m_last_block_processed;
1041 }
1043 void SetLastBlockProcessed(int block_height, BlockHash block_hash)
1046 m_last_block_processed_height = block_height;
1047 m_last_block_processed = block_hash;
1048 };
1049
1052
1056
1064 void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1065
1073 void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
1074
1082 void DeactivateScriptPubKeyMan(const uint256 &id, OutputType type,
1083 bool internal);
1084
1087
1092
1097 const FlatSigningProvider &signing_provider,
1098 const std::string &label, bool internal)
1100};
1101
1108
1111private:
1114
1115public:
1117 : m_wallet(w), m_could_reserve(false) {}
1118
1119 bool reserve() {
1121 if (m_wallet.fScanningWallet.exchange(true)) {
1122 return false;
1123 }
1124 m_wallet.m_scanning_start = GetTimeMillis();
1125 m_wallet.m_scanning_progress = 0;
1126 m_could_reserve = true;
1127 return true;
1128 }
1129
1130 bool isReserved() const {
1131 return (m_could_reserve && m_wallet.fScanningWallet);
1132 }
1133
1135 if (m_could_reserve) {
1136 m_wallet.fScanningWallet = false;
1137 }
1138 }
1139};
1140
1142bool AddWalletSetting(interfaces::Chain &chain, const std::string &wallet_name);
1143
1147 const std::string &wallet_name);
1148
1149#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:541
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:19
Address book data.
Definition: wallet.h:199
StringMap destdata
Definition: wallet.h:210
std::map< std::string, std::string > StringMap
Definition: wallet.h:209
std::string m_label
Definition: wallet.h:202
const std::string & GetLabel() const
Definition: wallet.h:213
std::string purpose
Definition: wallet.h:205
bool IsChange() const
Definition: wallet.h:212
void SetLabel(const std::string &label)
Definition: wallet.h:214
Definition: block.h:60
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:85
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:19
CScript()
Definition: script.h:438
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:213
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:254
std::unique_ptr< SigningProvider > GetSolvingProvider(const CScript &script) const
Get the SigningProvider for a script.
Definition: wallet.cpp:3292
std::atomic< int64_t > m_best_block_time
Definition: wallet.h:280
bool Lock()
Definition: wallet.cpp:3192
BlockHash GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:1037
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:572
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:3263
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
Definition: wallet.h:846
std::map< unsigned int, CMasterKey > MasterKeyMap
Definition: wallet.h:412
bool HaveChain() const
Interface to assert chain access.
Definition: wallet.h:434
int GetTxBlocksToMaturity(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3161
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:529
bool DummySignTx(CMutableTransaction &txNew, const std::set< CTxOut > &txouts, bool use_max_sig=false) const
Definition: wallet.h:705
uint64_t nAccountingEntryNumber
Definition: wallet.h:442
void ConnectScriptPubKeyManNotifiers()
Connect the signals from ScriptPubKeyMans to the signals in CWallet.
Definition: wallet.cpp:3352
void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Adds the active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3405
void SetupLegacyScriptPubKeyMan()
Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
Definition: wallet.cpp:3327
Mutex m_unlock_mutex
Definition: wallet.h:575
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:2615
boost::signals2::signal< void()> NotifyCanGetAddressesChanged
Keypool has new keys.
Definition: wallet.h:873
const 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:964
MasterKeyMap mapMasterKeys
Definition: wallet.h:413
std::string m_name
Wallet name: relative directory name or "" for default wallet.
Definition: wallet.h:354
TxItems wtxOrdered
Definition: wallet.h:439
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:3151
bool IsTxImmatureCoinBase(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3173
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:867
RecursiveMutex cs_wallet
Definition: wallet.h:398
static std::shared_ptr< CWallet > Create(interfaces::Chain *chain, 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:2703
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
Definition: wallet.cpp:3211
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:286
bool GetBroadcastTransactions() const
Inquire whether this wallet broadcasts transactions.
Definition: wallet.h:882
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:975
bool IsAbortingRescan() const
Definition: wallet.h:524
interfaces::Chain & chain() const
Interface for accessing chain state.
Definition: wallet.h:457
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Create new DescriptorScriptPubKeyMans and add them to the wallet.
Definition: wallet.cpp:3367
std::atomic< int64_t > m_scanning_start
Definition: wallet.h:264
WalletDatabase & GetDatabase() override
Definition: wallet.h:405
interfaces::Chain * m_chain
Interface for accessing chain state.
Definition: wallet.h:351
bool WithEncryptionKey(const std::function< bool(const CKeyingMaterial &)> &cb) const override
Pass the encryption key to cb().
Definition: wallet.cpp:3342
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
Definition: wallet.cpp:3322
std::map< OutputType, ScriptPubKeyMan * > m_external_spk_managers
Definition: wallet.h:376
void DeactivateScriptPubKeyMan(const uint256 &id, OutputType type, bool internal)
Remove specified ScriptPubKeyMan from set of active SPK managers.
Definition: wallet.cpp:3443
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:2639
CFeeRate m_fallback_fee
If fee estimation does not have enough data to provide estimates, use this fee instead.
Definition: wallet.h:745
bool IsLegacy() const
Determine if we are a legacy wallet.
Definition: wallet.cpp:3466
std::atomic< bool > fAbortRescan
Definition: wallet.h:261
std::map< uint256, std::unique_ptr< ScriptPubKeyMan > > m_spk_managers
Definition: wallet.h:382
void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
Loads an active ScriptPubKeyMan for the specified type and internal.
Definition: wallet.cpp:3416
std::unique_ptr< interfaces::Handler > m_chain_notifications_handler
Registered interfaces::Chain::Notifications handler.
Definition: wallet.h:454
void SetBroadcastTransactions(bool broadcast)
Set whether this wallet broadcasts transactions.
Definition: wallet.h:884
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:855
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
Definition: wallet.h:1032
boost::signals2::signal< void(CWallet *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: wallet.h:879
OutputType m_default_address_type
Definition: wallet.h:748
DescriptorScriptPubKeyMan * GetDescriptorScriptPubKeyMan(const WalletDescriptor &desc) const
Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet.
Definition: wallet.cpp:3476
int64_t ScanningDuration() const
Definition: wallet.h:526
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:2943
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor &desc)
Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it.
Definition: wallet.cpp:3360
LegacyScriptPubKeyMan * GetLegacyScriptPubKeyMan() const
Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
Definition: wallet.cpp:3308
std::atomic< uint64_t > m_wallet_flags
Definition: wallet.h:338
Amount m_max_aps_fee
note: this is absolute fee, not fee rate
Definition: wallet.h:747
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
Definition: wallet.h:410
CFeeRate m_pay_tx_fee
Definition: wallet.h:734
int64_t nNextResend
Definition: wallet.h:276
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:495
bool BackupWallet(const std::string &strDest) const
Definition: wallet.cpp:3134
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:476
unsigned int ComputeTimeSmart(const CWalletTx &wtx) const
Compute smart timestamp for a transaction being added to the wallet.
Definition: wallet.cpp:2573
CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet)
bool IsScanning() const
Definition: wallet.h:525
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:980
std::unique_ptr< WalletDatabase > database
Internal database handle.
Definition: wallet.h:357
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:3492
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:3226
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.h:537
CFeeRate m_min_fee
Definition: wallet.h:739
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:2658
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:870
bool IsLocked() const override
Definition: wallet.cpp:3184
bool m_allow_fallback_fee
will be false if -fallbackfee=0
Definition: wallet.h:737
std::map< OutputType, ScriptPubKeyMan * > m_internal_spk_managers
Definition: wallet.h:377
std::atomic< double > m_scanning_progress
Definition: wallet.h:265
~CWallet()
Definition: wallet.h:421
int GetVersion() const
get the current wallet format (the oldest client version guaranteed to understand this wallet)
Definition: wallet.h:824
WalletDatabase & GetDBHandle()
Get database handle used by this wallet.
Definition: wallet.h:404
void GetKeyBirthTimes(std::map< CKeyID, int64_t > &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2481
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:2625
boost::signals2::signal< void(CWallet *wallet, const TxId &txid, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:863
bool HasEncryptionKeys() const override
Definition: wallet.cpp:3348
bool m_spend_zero_conf_change
Definition: wallet.h:735
CWallet(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > _database)
Construct wallet with specified name and database implementation.
Definition: wallet.h:417
Amount m_default_max_tx_fee
Absolute maximum transaction fee (in satoshis) used by default for the wallet.
Definition: wallet.h:760
bool UpgradeWallet(int version, bilingual_str &error)
Upgrade the wallet.
Definition: wallet.cpp:3080
bool fBroadcastTransactions
Definition: wallet.h:277
ScriptPubKeyMan * GetScriptPubKeyMan(const OutputType &type, bool internal) const
Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
Definition: wallet.cpp:3247
bool IsCrypted() const
Definition: wallet.cpp:3180
std::atomic< bool > fScanningWallet
Definition: wallet.h:263
std::set< ScriptPubKeyMan * > GetAllScriptPubKeyMans() const
Returns all unique ScriptPubKeyMans.
Definition: wallet.cpp:3239
std::multimap< int64_t, CWalletTx * > TxItems
Definition: wallet.h:438
int nWalletMaxVersion GUARDED_BY(cs_wallet)
the maximum wallet format version: memory-only variable that specifies to what version this wallet ma...
std::optional< OutputType > m_default_change_type
Default output type for change outputs.
Definition: wallet.h:755
void AbortRescan()
Definition: wallet.h:523
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:2634
unsigned int nMasterKeyMaxID
Definition: wallet.h:414
std::function< bool(CWalletTx &wtx, bool new_tx)> UpdateWalletTxFn
Callback for updating transaction metadata in mapWallet.
Definition: wallet.h:604
void postInitProcess()
Wallet post-init setup Gives the wallet a chance to register repetitive tasks and complete post-init ...
Definition: wallet.cpp:3123
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:1043
const CAddressBookData * FindAddressBookEntry(const CTxDestination &, bool allow_change=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:3068
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:65
A UTXO entry.
Definition: coins.h:28
A wrapper to reserve an address from a wallet.
Definition: wallet.h:161
bool fInternal
Whether this is from the internal (change output) keypool.
Definition: wallet.h:174
ReserveDestination & operator=(const ReserveDestination &)=delete
OutputType const type
Definition: wallet.h:168
~ReserveDestination()
Destructor.
Definition: wallet.h:187
ReserveDestination(CWallet *_pwallet, OutputType _type)
Construct a ReserveDestination object.
Definition: wallet.h:179
ScriptPubKeyMan * m_spk_man
The ScriptPubKeyMan to reserve from.
Definition: wallet.h:167
int64_t nIndex
The index of the address's key in the keypool.
Definition: wallet.h:170
CTxDestination address
The destination.
Definition: wallet.h:172
ReserveDestination(const ReserveDestination &)=delete
const CWallet *const pwallet
The wallet to reserve from.
Definition: wallet.h:164
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:175
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:1110
bool isReserved() const
Definition: wallet.h:1130
CWallet & m_wallet
Definition: wallet.h:1112
WalletRescanReserver(CWallet &w)
Definition: wallet.h:1116
Chain notifications.
Definition: chain.h:241
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:123
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:2451
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:2374
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2297
void KeepDestination()
Keep the address.
Definition: wallet.cpp:2434
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2472
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2308
std::set< CTxDestination > GetLabelAddresses(const std::string &label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2395
bool IsLockedCoin(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2466
SigningResult SignMessage(const std::string &message, const PKHash &pkhash, std::string &str_sig) const
Definition: wallet.cpp:2096
void UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2456
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:2256
DBErrors LoadWallet()
Definition: wallet.cpp:2173
OutputType TransactionChangeType(const std::optional< OutputType > &change_type, const std::vector< CRecipient > &vecSend) const
Definition: wallet.cpp:2110
bool SignTransaction(CMutableTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2005
void ReturnDestination()
Return reserved address.
Definition: wallet.cpp:2443
bool GetNewChangeDestination(const OutputType type, CTxDestination &dest, std::string &error)
Definition: wallet.cpp:2347
void UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2461
bool TopUpKeyPool(unsigned int kpSize=0)
Definition: wallet.cpp:2318
bool SetAddressBookWithDB(WalletBatch &batch, const CTxDestination &address, const std::string &strName, const std::string &strPurpose)
Definition: wallet.cpp:2229
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:2052
bool GetReservedDestination(CTxDestination &pubkey, bool internal)
Reserve an address.
Definition: wallet.cpp:2413
int64_t GetOldestKeyPoolTime() const
Definition: wallet.cpp:2364
bool DelAddressBook(const CTxDestination &address)
Definition: wallet.cpp:2263
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination &dest, std::string &error)
Definition: wallet.cpp:2327
DBErrors ZapSelectTx(std::vector< TxId > &txIdsIn, std::vector< TxId > &txIdsOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:2197
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:2126
bool AddWalletFlags(uint64_t flags)
Overwrite all flags by the given uint64_t.
Definition: wallet.cpp:1534
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:1609
void blockConnected(const CBlock &block, int height) override
Definition: wallet.cpp:1356
bool LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1048
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:1231
void Flush()
Flush wallet (bitdb flush)
Definition: wallet.cpp:606
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo.
Definition: wallet.cpp:404
bool SetMaxVersion(int nVersion)
change which version we're allowed to upgrade to (note that this does not immediately imply upgrading...
Definition: wallet.cpp:558
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:571
void MarkDirty()
Definition: wallet.cpp:896
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:1883
void AddToSpends(const COutPoint &outpoint, const TxId &wtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:684
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:1288
bool ImportScripts(const std::set< CScript > scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1589
CWalletTx * AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation &confirm, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true)
Definition: wallet.cpp:954
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:600
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:448
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:1492
bool IsFromMe(const CTransaction &tx) const
should probably be renamed to IsRelevantToMe
Definition: wallet.cpp:1451
bool ImportPrivKeys(const std::map< CKeyID, CKey > &privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1599
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1426
bool LoadWalletFlags(uint64_t flags)
Loads the flags into the wallet.
Definition: wallet.cpp:1523
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:1623
bool CanGetAddresses(bool internal=false) const
Returns true if the wallet can give out new addresses.
Definition: wallet.cpp:1478
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:1709
bool IsSpentKey(const TxId &txid, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:927
bool TransactionCanBeAbandoned(const TxId &txid) const
Return whether transaction can be abandoned.
Definition: wallet.cpp:1156
const CChainParams & GetChainParams() const override
Definition: wallet.cpp:388
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:1405
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:1163
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:1099
bool IsSpent(const COutPoint &outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction, spends it:
Definition: wallet.cpp:663
void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1850
bool IsHDEnabled() const
Definition: wallet.cpp:1469
void UnsetWalletFlagWithDB(WalletBatch &batch, uint64_t flag)
Unsets a wallet flag and saves it to disk.
Definition: wallet.cpp:1506
void SyncMetaData(std::pair< TxSpends::iterator, TxSpends::iterator >) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:614
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:708
void updatedBlockTip() override
Definition: wallet.cpp:1388
void UnsetWalletFlag(uint64_t flag)
Unsets a single wallet flag.
Definition: wallet.cpp:1501
void transactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
Definition: wallet.cpp:1314
bool IsWalletFlagSet(uint64_t flag) const override
Check if a certain wallet flag is set.
Definition: wallet.cpp:1519
int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver &reserver, bool update)
Scan active chain for relevant transactions after importing keys.
Definition: wallet.cpp:1658
bool AbandonTransaction(const TxId &txid)
Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent.
Definition: wallet.cpp:1172
void UnsetBlankWalletFlag(WalletBatch &batch) override
Unset the blank wallet flag and saves it to disk.
Definition: wallet.cpp:1515
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:903
void transactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence) override
Definition: wallet.cpp:1301
DBErrors ReorderTransactions()
Definition: wallet.cpp:828
void blockDisconnected(const CBlock &block, int height) override
Definition: wallet.cpp:1371
void Close()
Close wallet database.
Definition: wallet.cpp:610
int64_t IncOrderPosNext(WalletBatch *batch=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Increment the next transaction order id.
Definition: wallet.cpp:884
const CWalletTx * GetWalletTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:394
void ResendWalletTransactions()
Definition: wallet.cpp:1944
void SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr, bool fExplicit=false) override
signify that a particular wallet feature is now used.
Definition: wallet.cpp:530
std::set< TxId > GetTxConflicts(const CWalletTx &wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Definition: wallet.cpp:1924
bool DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig=false) const
Definition: wallet.cpp:1548
void chainStateFlushed(const CBlockLocator &loc) override
Definition: wallet.cpp:525
uint8_t isminefilter
Definition: wallet.h:42
isminetype
IsMine() return codes.
Definition: ismine.h:18
bool error(const char *fmt, const Args &...args)
Definition: logging.h:263
#define LogPrintfToBeContinued
These are aliases used to explicitly state that the message should not end with a newline character.
Definition: logging.h:259
#define LogPrintf(...)
Definition: logging.h:227
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:817
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:105
CScript scriptPubKey
Definition: wallet.h:221
Amount nAmount
Definition: wallet.h:222
bool fSubtractFeeFromAmount
Definition: wallet.h:223
std::optional< int > last_scanned_height
Definition: wallet.h:627
BlockHash last_scanned_block
Hash and height of most recent block that was successfully scanned.
Definition: wallet.h:626
BlockHash last_failed_block
Hash of the most recent block that could not be scanned due to read errors or pruning.
Definition: wallet.h:633
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:233
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:236
size_t change_spend_size
Definition: wallet.h:229
size_t tx_noinputs_size
Definition: wallet.h:231
bool m_avoid_partial_spends
Definition: wallet.h:234
CFeeRate effective_fee
Definition: wallet.h:230
size_t change_output_size
Definition: wallet.h:228
A version of CTransaction with the PSBT format.
Definition: psbt.h:334
A TxId is the identifier of a transaction.
Definition: txid.h:14
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
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: time.cpp:101
#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:152
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())
DatabaseStatus
Definition: db.h:229
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:475
std::map< std::string, std::string > mapValue_t
Definition: transaction.h:21
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
Definition: wallet.cpp:167
constexpr Amount HIGH_TX_FEE_PER_KB
Discourage users to set fees higher than this amount (in satoshis) per kB.
Definition: wallet.h:110
constexpr Amount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:83
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:106
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
Definition: wallet.h:48
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:121
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:126
static constexpr uint64_t MUTABLE_WALLET_FLAGS
Definition: wallet.h:133
constexpr Amount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in satoshis)
Definition: wallet.h:113
const std::map< uint64_t, std::string > WALLET_FLAG_CAVEATS
Definition: wallet.cpp:44
static const std::map< std::string, WalletFlags > WALLET_FLAG_MAP
Definition: wallet.h:135
static constexpr size_t DUMMY_P2PKH_INPUT_SIZE
Pre-calculated constants for input size estimation.
Definition: wallet.h:115
void MaybeResendWalletTxs()
Called periodically by the schedule thread.
Definition: wallet.cpp:1993
static const Amount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:85
static const Amount DEFAULT_TRANSACTION_MINFEE_PER_KB
-mintxfee default
Definition: wallet.h:87
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Definition: wallet.cpp:2671
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Definition: wallet.cpp:202
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:104
static constexpr uint64_t KNOWN_WALLET_FLAGS
Definition: wallet.h:128
constexpr Amount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:108
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:98
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:55
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:70
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:105
constexpr Amount HIGH_APS_FEE
discourage APS fee higher than this amount
Definition: wallet.h:100
static const Amount WALLET_INCREMENTAL_RELAY_FEE(5000 *SATOSHI)
minimum recommended increment for BIP 125 replacement txs
std::shared_ptr< CWallet > GetWallet(const std::string &name)
Definition: wallet.cpp:156
std::vector< std::shared_ptr< CWallet > > GetWallets()
Definition: wallet.cpp:151
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:107
std::shared_ptr< CWallet > LoadWallet(interfaces::Chain &chain, const std::string &name, std::optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:266
std::shared_ptr< CWallet > CreateWallet(interfaces::Chain &chain, const std::string &name, std::optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:284
DBErrors
Error statuses for the wallet database.
Definition: walletdb.h:45
@ 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