Branch data Line data Source code
# 1 : : // Copyright (c) 2009-2010 Satoshi Nakamoto
# 2 : : // Copyright (c) 2009-2021 The Bitcoin Core developers
# 3 : : // Distributed under the MIT software license, see the accompanying
# 4 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
# 5 : :
# 6 : : #ifndef BITCOIN_WALLET_WALLET_H
# 7 : : #define BITCOIN_WALLET_WALLET_H
# 8 : :
# 9 : : #include <consensus/amount.h>
# 10 : : #include <fs.h>
# 11 : : #include <interfaces/chain.h>
# 12 : : #include <interfaces/handler.h>
# 13 : : #include <outputtype.h>
# 14 : : #include <policy/feerate.h>
# 15 : : #include <psbt.h>
# 16 : : #include <tinyformat.h>
# 17 : : #include <util/message.h>
# 18 : : #include <util/strencodings.h>
# 19 : : #include <util/string.h>
# 20 : : #include <util/system.h>
# 21 : : #include <util/ui_change_type.h>
# 22 : : #include <validationinterface.h>
# 23 : : #include <wallet/crypter.h>
# 24 : : #include <wallet/scriptpubkeyman.h>
# 25 : : #include <wallet/transaction.h>
# 26 : : #include <wallet/walletdb.h>
# 27 : : #include <wallet/walletutil.h>
# 28 : :
# 29 : : #include <algorithm>
# 30 : : #include <atomic>
# 31 : : #include <map>
# 32 : : #include <memory>
# 33 : : #include <optional>
# 34 : : #include <set>
# 35 : : #include <stdexcept>
# 36 : : #include <stdint.h>
# 37 : : #include <string>
# 38 : : #include <utility>
# 39 : : #include <vector>
# 40 : :
# 41 : : #include <boost/signals2/signal.hpp>
# 42 : :
# 43 : :
# 44 : : using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
# 45 : :
# 46 : : class CScript;
# 47 : : enum class FeeEstimateMode;
# 48 : : struct FeeCalculation;
# 49 : : struct bilingual_str;
# 50 : :
# 51 : : namespace wallet {
# 52 : : struct WalletContext;
# 53 : :
# 54 : : //! Explicitly unload and delete the wallet.
# 55 : : //! Blocks the current thread after signaling the unload intent so that all
# 56 : : //! wallet pointer owners release the wallet.
# 57 : : //! Note that, when blocking is not required, the wallet is implicitly unloaded
# 58 : : //! by the shared pointer deleter.
# 59 : : void UnloadWallet(std::shared_ptr<CWallet>&& wallet);
# 60 : :
# 61 : : bool AddWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
# 62 : : bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start, std::vector<bilingual_str>& warnings);
# 63 : : bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet, std::optional<bool> load_on_start);
# 64 : : std::vector<std::shared_ptr<CWallet>> GetWallets(WalletContext& context);
# 65 : : std::shared_ptr<CWallet> GetWallet(WalletContext& context, const std::string& name);
# 66 : : 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);
# 67 : : 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);
# 68 : : 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);
# 69 : : std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, LoadWalletFn load_wallet);
# 70 : : void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
# 71 : : std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
# 72 : :
# 73 : : //! -paytxfee default
# 74 : : constexpr CAmount DEFAULT_PAY_TX_FEE = 0;
# 75 : : //! -fallbackfee default
# 76 : : static const CAmount DEFAULT_FALLBACK_FEE = 0;
# 77 : : //! -discardfee default
# 78 : : static const CAmount DEFAULT_DISCARD_FEE = 10000;
# 79 : : //! -mintxfee default
# 80 : : static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
# 81 : : //! -consolidatefeerate default
# 82 : : static const CAmount DEFAULT_CONSOLIDATE_FEERATE{10000}; // 10 sat/vbyte
# 83 : : /**
# 84 : : * maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled by default
# 85 : : *
# 86 : : * A value of -1 disables this feature completely.
# 87 : : * A value of 0 (current default) means to attempt to do partial spend avoidance, and use its results if the fees remain *unchanged*
# 88 : : * A value > 0 means to do partial spend avoidance if the fee difference against a regular coin selection instance is in the range [0..value].
# 89 : : */
# 90 : : static const CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE = 0;
# 91 : : //! discourage APS fee higher than this amount
# 92 : : constexpr CAmount HIGH_APS_FEE{COIN / 10000};
# 93 : : //! minimum recommended increment for BIP 125 replacement txs
# 94 : : static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
# 95 : : //! Default for -spendzeroconfchange
# 96 : : static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
# 97 : : //! Default for -walletrejectlongchains
# 98 : : static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS{true};
# 99 : : //! -txconfirmtarget default
# 100 : : static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
# 101 : : //! -walletrbf default
# 102 : : static const bool DEFAULT_WALLET_RBF = false;
# 103 : : static const bool DEFAULT_WALLETBROADCAST = true;
# 104 : : static const bool DEFAULT_DISABLE_WALLET = false;
# 105 : : //! -maxtxfee default
# 106 : : constexpr CAmount DEFAULT_TRANSACTION_MAXFEE{COIN / 10};
# 107 : : //! Discourage users to set fees higher than this amount (in satoshis) per kB
# 108 : : constexpr CAmount HIGH_TX_FEE_PER_KB{COIN / 100};
# 109 : : //! -maxtxfee will warn if called with a higher fee than this amount (in satoshis)
# 110 : : constexpr CAmount HIGH_MAX_TX_FEE{100 * HIGH_TX_FEE_PER_KB};
# 111 : : //! Pre-calculated constants for input size estimation in *virtual size*
# 112 : : static constexpr size_t DUMMY_NESTED_P2WPKH_INPUT_SIZE = 91;
# 113 : :
# 114 : : class CCoinControl;
# 115 : : class CWalletTx;
# 116 : : class ReserveDestination;
# 117 : :
# 118 : : //! Default for -addresstype
# 119 : : constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::BECH32};
# 120 : :
# 121 : : static constexpr uint64_t KNOWN_WALLET_FLAGS =
# 122 : : WALLET_FLAG_AVOID_REUSE
# 123 : : | WALLET_FLAG_BLANK_WALLET
# 124 : : | WALLET_FLAG_KEY_ORIGIN_METADATA
# 125 : : | WALLET_FLAG_LAST_HARDENED_XPUB_CACHED
# 126 : : | WALLET_FLAG_DISABLE_PRIVATE_KEYS
# 127 : : | WALLET_FLAG_DESCRIPTORS
# 128 : : | WALLET_FLAG_EXTERNAL_SIGNER;
# 129 : :
# 130 : : static constexpr uint64_t MUTABLE_WALLET_FLAGS =
# 131 : : WALLET_FLAG_AVOID_REUSE;
# 132 : :
# 133 : : static const std::map<std::string,WalletFlags> WALLET_FLAG_MAP{
# 134 : : {"avoid_reuse", WALLET_FLAG_AVOID_REUSE},
# 135 : : {"blank", WALLET_FLAG_BLANK_WALLET},
# 136 : : {"key_origin_metadata", WALLET_FLAG_KEY_ORIGIN_METADATA},
# 137 : : {"last_hardened_xpub_cached", WALLET_FLAG_LAST_HARDENED_XPUB_CACHED},
# 138 : : {"disable_private_keys", WALLET_FLAG_DISABLE_PRIVATE_KEYS},
# 139 : : {"descriptor_wallet", WALLET_FLAG_DESCRIPTORS},
# 140 : : {"external_signer", WALLET_FLAG_EXTERNAL_SIGNER}
# 141 : : };
# 142 : :
# 143 : : extern const std::map<uint64_t,std::string> WALLET_FLAG_CAVEATS;
# 144 : :
# 145 : : /** A wrapper to reserve an address from a wallet
# 146 : : *
# 147 : : * ReserveDestination is used to reserve an address.
# 148 : : * It is currently only used inside of CreateTransaction.
# 149 : : *
# 150 : : * Instantiating a ReserveDestination does not reserve an address. To do so,
# 151 : : * GetReservedDestination() needs to be called on the object. Once an address has been
# 152 : : * reserved, call KeepDestination() on the ReserveDestination object to make sure it is not
# 153 : : * returned. Call ReturnDestination() to return the address so it can be re-used (for
# 154 : : * example, if the address was used in a new transaction
# 155 : : * and that transaction was not completed and needed to be aborted).
# 156 : : *
# 157 : : * If an address is reserved and KeepDestination() is not called, then the address will be
# 158 : : * returned when the ReserveDestination goes out of scope.
# 159 : : */
# 160 : : class ReserveDestination
# 161 : : {
# 162 : : protected:
# 163 : : //! The wallet to reserve from
# 164 : : const CWallet* const pwallet;
# 165 : : //! The ScriptPubKeyMan to reserve from. Based on type when GetReservedDestination is called
# 166 : : ScriptPubKeyMan* m_spk_man{nullptr};
# 167 : : OutputType const type;
# 168 : : //! The index of the address's key in the keypool
# 169 : : int64_t nIndex{-1};
# 170 : : //! The destination
# 171 : : CTxDestination address;
# 172 : : //! Whether this is from the internal (change output) keypool
# 173 : : bool fInternal{false};
# 174 : :
# 175 : : public:
# 176 : : //! Construct a ReserveDestination object. This does NOT reserve an address yet
# 177 : : explicit ReserveDestination(CWallet* pwallet, OutputType type)
# 178 : : : pwallet(pwallet)
# 179 : 5680 : , type(type) { }
# 180 : :
# 181 : : ReserveDestination(const ReserveDestination&) = delete;
# 182 : : ReserveDestination& operator=(const ReserveDestination&) = delete;
# 183 : :
# 184 : : //! Destructor. If a key has been reserved and not KeepKey'ed, it will be returned to the keypool
# 185 : : ~ReserveDestination()
# 186 : 5680 : {
# 187 : 5680 : ReturnDestination();
# 188 : 5680 : }
# 189 : :
# 190 : : //! Reserve an address
# 191 : : bool GetReservedDestination(CTxDestination& pubkey, bool internal, bilingual_str& error);
# 192 : : //! Return reserved address
# 193 : : void ReturnDestination();
# 194 : : //! Keep the address. Do not return it's key to the keypool when this object goes out of scope
# 195 : : void KeepDestination();
# 196 : : };
# 197 : :
# 198 : : /** Address book data */
# 199 : : class CAddressBookData
# 200 : : {
# 201 : : private:
# 202 : : bool m_change{true};
# 203 : : std::string m_label;
# 204 : : public:
# 205 : : std::string purpose;
# 206 : :
# 207 : 19531 : CAddressBookData() : purpose("unknown") {}
# 208 : :
# 209 : : typedef std::map<std::string, std::string> StringMap;
# 210 : : StringMap destdata;
# 211 : :
# 212 : 43335 : bool IsChange() const { return m_change; }
# 213 : 41943 : const std::string& GetLabel() const { return m_label; }
# 214 : 19601 : void SetLabel(const std::string& label) {
# 215 : 19601 : m_change = false;
# 216 : 19601 : m_label = label;
# 217 : 19601 : }
# 218 : : };
# 219 : :
# 220 : : struct CRecipient
# 221 : : {
# 222 : : CScript scriptPubKey;
# 223 : : CAmount nAmount;
# 224 : : bool fSubtractFeeFromAmount;
# 225 : : };
# 226 : :
# 227 : : class WalletRescanReserver; //forward declarations for ScanForWalletTransactions/RescanFromTime
# 228 : : /**
# 229 : : * A CWallet maintains a set of transactions and balances, and provides the ability to create new transactions.
# 230 : : */
# 231 : : class CWallet final : public WalletStorage, public interfaces::Chain::Notifications
# 232 : : {
# 233 : : private:
# 234 : : CKeyingMaterial vMasterKey GUARDED_BY(cs_wallet);
# 235 : :
# 236 : : bool Unlock(const CKeyingMaterial& vMasterKeyIn, bool accept_no_keys = false);
# 237 : :
# 238 : : std::atomic<bool> fAbortRescan{false};
# 239 : : std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
# 240 : : std::atomic<int64_t> m_scanning_start{0};
# 241 : : std::atomic<double> m_scanning_progress{0};
# 242 : : friend class WalletRescanReserver;
# 243 : :
# 244 : : //! the current wallet version: clients below this version are not able to load the wallet
# 245 : : int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
# 246 : :
# 247 : : /** The next scheduled rebroadcast of wallet transactions. */
# 248 : : int64_t nNextResend = 0;
# 249 : : /** Whether this wallet will submit newly created transactions to the node's mempool and
# 250 : : * prompt rebroadcasts (see ResendWalletTransactions()). */
# 251 : : bool fBroadcastTransactions = false;
# 252 : : // Local time that the tip block was received. Used to schedule wallet rebroadcasts.
# 253 : : std::atomic<int64_t> m_best_block_time {0};
# 254 : :
# 255 : : /**
# 256 : : * Used to keep track of spent outpoints, and
# 257 : : * detect and report conflicts (double-spends or
# 258 : : * mutated transactions where the mutant gets mined).
# 259 : : */
# 260 : : typedef std::multimap<COutPoint, uint256> TxSpends;
# 261 : : TxSpends mapTxSpends GUARDED_BY(cs_wallet);
# 262 : : void AddToSpends(const COutPoint& outpoint, const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 263 : : void AddToSpends(const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 264 : :
# 265 : : /**
# 266 : : * Add a transaction to the wallet, or update it. confirm.block_* should
# 267 : : * be set when the transaction was known to be included in a block. When
# 268 : : * block_hash.IsNull(), then wallet state is not updated in AddToWallet, but
# 269 : : * notifications happen and cached balances are marked dirty.
# 270 : : *
# 271 : : * If fUpdate is true, existing transactions will be updated.
# 272 : : * TODO: One exception to this is that the abandoned state is cleared under the
# 273 : : * assumption that any further notification of a transaction that was considered
# 274 : : * abandoned is an indication that it is not safe to be considered abandoned.
# 275 : : * Abandoned state should probably be more carefully tracked via different
# 276 : : * chain notifications or by checking mempool presence when necessary.
# 277 : : *
# 278 : : * Should be called with rescanning_old_block set to true, if the transaction is
# 279 : : * not discovered in real time, but during a rescan of old blocks.
# 280 : : */
# 281 : : bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const SyncTxState& state, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 282 : :
# 283 : : /** Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
# 284 : : void MarkConflicted(const uint256& hashBlock, int conflicting_height, const uint256& hashTx);
# 285 : :
# 286 : : /** Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed */
# 287 : : void MarkInputsDirty(const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 288 : :
# 289 : : void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 290 : :
# 291 : : void SyncTransaction(const CTransactionRef& tx, const SyncTxState& state, bool update_tx = true, bool rescanning_old_block = false) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 292 : :
# 293 : : /** WalletFlags set on this wallet. */
# 294 : : std::atomic<uint64_t> m_wallet_flags{0};
# 295 : :
# 296 : : bool SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const std::string& strName, const std::string& strPurpose);
# 297 : :
# 298 : : //! Unsets a wallet flag and saves it to disk
# 299 : : void UnsetWalletFlagWithDB(WalletBatch& batch, uint64_t flag);
# 300 : :
# 301 : : //! Unset the blank wallet flag and saves it to disk
# 302 : : void UnsetBlankWalletFlag(WalletBatch& batch) override;
# 303 : :
# 304 : : /** Provider of aplication-wide arguments. */
# 305 : : const ArgsManager& m_args;
# 306 : :
# 307 : : /** Interface for accessing chain state. */
# 308 : : interfaces::Chain* m_chain;
# 309 : :
# 310 : : /** Wallet name: relative directory name or "" for default wallet. */
# 311 : : std::string m_name;
# 312 : :
# 313 : : /** Internal database handle. */
# 314 : : std::unique_ptr<WalletDatabase> const m_database;
# 315 : :
# 316 : : /**
# 317 : : * The following is used to keep track of how far behind the wallet is
# 318 : : * from the chain sync, and to allow clients to block on us being caught up.
# 319 : : *
# 320 : : * Processed hash is a pointer on node's tip and doesn't imply that the wallet
# 321 : : * has scanned sequentially all blocks up to this one.
# 322 : : */
# 323 : : uint256 m_last_block_processed GUARDED_BY(cs_wallet);
# 324 : :
# 325 : : /** Height of last block processed is used by wallet to know depth of transactions
# 326 : : * without relying on Chain interface beyond asynchronous updates. For safety, we
# 327 : : * initialize it to -1. Height is a pointer on node's tip and doesn't imply
# 328 : : * that the wallet has scanned sequentially all blocks up to this one.
# 329 : : */
# 330 : : int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
# 331 : :
# 332 : : std::map<OutputType, ScriptPubKeyMan*> m_external_spk_managers;
# 333 : : std::map<OutputType, ScriptPubKeyMan*> m_internal_spk_managers;
# 334 : :
# 335 : : // Indexed by a unique identifier produced by each ScriptPubKeyMan using
# 336 : : // ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal structure
# 337 : : std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
# 338 : :
# 339 : : /**
# 340 : : * Catch wallet up to current chain, scanning new blocks, updating the best
# 341 : : * block locator and m_last_block_processed, and registering for
# 342 : : * notifications about new blocks and transactions.
# 343 : : */
# 344 : : static bool AttachChain(const std::shared_ptr<CWallet>& wallet, interfaces::Chain& chain, const bool rescan_required, bilingual_str& error, std::vector<bilingual_str>& warnings);
# 345 : :
# 346 : : public:
# 347 : : /**
# 348 : : * Main wallet lock.
# 349 : : * This lock protects all the fields added by CWallet.
# 350 : : */
# 351 : : mutable RecursiveMutex cs_wallet;
# 352 : :
# 353 : : WalletDatabase& GetDatabase() const override
# 354 : 218453 : {
# 355 : 218453 : assert(static_cast<bool>(m_database));
# 356 : 0 : return *m_database;
# 357 : 218453 : }
# 358 : :
# 359 : : /** Get a name for this wallet for logging/debugging purposes.
# 360 : : */
# 361 : 192368 : const std::string& GetName() const { return m_name; }
# 362 : :
# 363 : : typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
# 364 : : MasterKeyMap mapMasterKeys;
# 365 : : unsigned int nMasterKeyMaxID = 0;
# 366 : :
# 367 : : /** Construct wallet with specified name and database implementation. */
# 368 : : CWallet(interfaces::Chain* chain, const std::string& name, const ArgsManager& args, std::unique_ptr<WalletDatabase> database)
# 369 : : : m_args(args),
# 370 : : m_chain(chain),
# 371 : : m_name(name),
# 372 : : m_database(std::move(database))
# 373 : 876 : {
# 374 : 876 : }
# 375 : :
# 376 : : ~CWallet()
# 377 : 876 : {
# 378 : : // Should not have slots connected at this point.
# 379 : 876 : assert(NotifyUnload.empty());
# 380 : 876 : }
# 381 : :
# 382 : : bool IsCrypted() const;
# 383 : : bool IsLocked() const override;
# 384 : : bool Lock();
# 385 : :
# 386 : : /** Interface to assert chain access */
# 387 [ + + ]: 10201 : bool HaveChain() const { return m_chain ? true : false; }
# 388 : :
# 389 : : /** Map from txid to CWalletTx for all transactions this wallet is
# 390 : : * interested in, including received and sent transactions. */
# 391 : : std::map<uint256, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
# 392 : :
# 393 : : typedef std::multimap<int64_t, CWalletTx*> TxItems;
# 394 : : TxItems wtxOrdered;
# 395 : :
# 396 : : int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
# 397 : : uint64_t nAccountingEntryNumber = 0;
# 398 : :
# 399 : : std::map<CTxDestination, CAddressBookData> m_address_book GUARDED_BY(cs_wallet);
# 400 : : const CAddressBookData* FindAddressBookEntry(const CTxDestination&, bool allow_change = false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 401 : :
# 402 : : /** Set of Coins owned by this wallet that we won't try to spend from. A
# 403 : : * Coin may be locked if it has already been used to fund a transaction
# 404 : : * that hasn't confirmed yet. We wouldn't consider the Coin spent already,
# 405 : : * but also shouldn't try to use it again. */
# 406 : : std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);
# 407 : :
# 408 : : /** Registered interfaces::Chain::Notifications handler. */
# 409 : : std::unique_ptr<interfaces::Handler> m_chain_notifications_handler;
# 410 : :
# 411 : : /** Interface for accessing chain state. */
# 412 : 1988604 : interfaces::Chain& chain() const { assert(m_chain); return *m_chain; }
# 413 : :
# 414 : : const CWalletTx* GetWalletTx(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 415 : :
# 416 : : // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
# 417 : : // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation
# 418 : : // "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to
# 419 : : // resolve the issue of member access into incomplete type CWallet. Note
# 420 : : // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
# 421 : : // in place.
# 422 : : std::set<uint256> GetTxConflicts(const CWalletTx& wtx) const NO_THREAD_SAFETY_ANALYSIS;
# 423 : :
# 424 : : /**
# 425 : : * Return depth of transaction in blockchain:
# 426 : : * <0 : conflicts with a transaction this deep in the blockchain
# 427 : : * 0 : in memory pool, waiting to be included in a block
# 428 : : * >=1 : this many blocks deep in the main chain
# 429 : : */
# 430 : : // TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
# 431 : : // annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The annotation
# 432 : : // "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having to
# 433 : : // resolve the issue of member access into incomplete type CWallet. Note
# 434 : : // that we still have the runtime check "AssertLockHeld(pwallet->cs_wallet)"
# 435 : : // in place.
# 436 : : int GetTxDepthInMainChain(const CWalletTx& wtx) const NO_THREAD_SAFETY_ANALYSIS;
# 437 : 94980 : bool IsTxInMainChain(const CWalletTx& wtx) const { return GetTxDepthInMainChain(wtx) > 0; }
# 438 : :
# 439 : : /**
# 440 : : * @return number of blocks to maturity for this transaction:
# 441 : : * 0 : is not a coinbase transaction, or is a mature coinbase transaction
# 442 : : * >0 : is a coinbase transaction which matures in this many blocks
# 443 : : */
# 444 : : int GetTxBlocksToMaturity(const CWalletTx& wtx) const;
# 445 : : bool IsTxImmatureCoinBase(const CWalletTx& wtx) const;
# 446 : :
# 447 : : //! check whether we support the named feature
# 448 : 76937 : bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return IsFeatureSupported(nWalletVersion, wf); }
# 449 : :
# 450 : : bool IsSpent(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 451 : :
# 452 : : // Whether this or any known UTXO with the same single key has been spent.
# 453 : : bool IsSpentKey(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 454 : : void SetSpentKeyState(WalletBatch& batch, const uint256& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 455 : :
# 456 : : /** Display address on an external signer. Returns false if external signer support is not compiled */
# 457 : : bool DisplayAddress(const CTxDestination& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 458 : :
# 459 : : bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 460 : : bool LockCoin(const COutPoint& output, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 461 : : bool UnlockCoin(const COutPoint& output, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 462 : : bool UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 463 : : void ListLockedCoins(std::vector<COutPoint>& vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 464 : :
# 465 : : /*
# 466 : : * Rescan abort properties
# 467 : : */
# 468 : 0 : void AbortRescan() { fAbortRescan = true; }
# 469 : 727 : bool IsAbortingRescan() const { return fAbortRescan; }
# 470 : 991 : bool IsScanning() const { return fScanningWallet; }
# 471 [ # # ]: 0 : int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; }
# 472 [ # # ]: 0 : double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }
# 473 : :
# 474 : : //! Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo
# 475 : : void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 476 : :
# 477 : : //! Upgrade DescriptorCaches
# 478 : : void UpgradeDescriptorCache() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 479 : :
# 480 : 343 : bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; return true; }
# 481 : :
# 482 : : //! Adds a destination data tuple to the store, without saving it to disk
# 483 : : void LoadDestData(const CTxDestination& dest, const std::string& key, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 484 : :
# 485 : : //! Holds a timestamp at which point the wallet is scheduled (externally) to be relocked. Caller must arrange for actual relocking to occur via Lock().
# 486 : : int64_t nRelockTime GUARDED_BY(cs_wallet){0};
# 487 : :
# 488 : : // Used to prevent concurrent calls to walletpassphrase RPC.
# 489 : : Mutex m_unlock_mutex;
# 490 : : bool Unlock(const SecureString& strWalletPassphrase, bool accept_no_keys = false);
# 491 : : bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
# 492 : : bool EncryptWallet(const SecureString& strWalletPassphrase);
# 493 : :
# 494 : : void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 495 : : unsigned int ComputeTimeSmart(const CWalletTx& wtx, bool rescanning_old_block) const;
# 496 : :
# 497 : : /**
# 498 : : * Increment the next transaction order id
# 499 : : * @return next transaction order id
# 500 : : */
# 501 : : int64_t IncOrderPosNext(WalletBatch *batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 502 : : DBErrors ReorderTransactions();
# 503 : :
# 504 : : void MarkDirty();
# 505 : :
# 506 : : //! Callback for updating transaction metadata in mapWallet.
# 507 : : //!
# 508 : : //! @param wtx - reference to mapWallet transaction to update
# 509 : : //! @param new_tx - true if wtx is newly inserted, false if it previously existed
# 510 : : //!
# 511 : : //! @return true if wtx is changed and needs to be saved to disk, otherwise false
# 512 : : using UpdateWalletTxFn = std::function<bool(CWalletTx& wtx, bool new_tx)>;
# 513 : :
# 514 : : CWalletTx* AddToWallet(CTransactionRef tx, const TxState& state, const UpdateWalletTxFn& update_wtx=nullptr, bool fFlushOnClose=true, bool rescanning_old_block = false);
# 515 : : bool LoadToWallet(const uint256& hash, const UpdateWalletTxFn& fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 516 : : void transactionAddedToMempool(const CTransactionRef& tx, uint64_t mempool_sequence) override;
# 517 : : void blockConnected(const CBlock& block, int height) override;
# 518 : : void blockDisconnected(const CBlock& block, int height) override;
# 519 : : void updatedBlockTip() override;
# 520 : : int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update);
# 521 : :
# 522 : : struct ScanResult {
# 523 : : enum { SUCCESS, FAILURE, USER_ABORT } status = SUCCESS;
# 524 : :
# 525 : : //! Hash and height of most recent block that was successfully scanned.
# 526 : : //! Unset if no blocks were scanned due to read errors or the chain
# 527 : : //! being empty.
# 528 : : uint256 last_scanned_block;
# 529 : : std::optional<int> last_scanned_height;
# 530 : :
# 531 : : //! Height of the most recent block that could not be scanned due to
# 532 : : //! read errors or pruning. Will be set if status is FAILURE, unset if
# 533 : : //! status is SUCCESS, and may or may not be set if status is
# 534 : : //! USER_ABORT.
# 535 : : uint256 last_failed_block;
# 536 : : };
# 537 : : ScanResult ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate);
# 538 : : void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
# 539 : : void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 540 : : void ResendWalletTransactions();
# 541 : :
# 542 : : OutputType TransactionChangeType(const std::optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const;
# 543 : :
# 544 : : /** Fetch the inputs and sign with SIGHASH_ALL. */
# 545 : : bool SignTransaction(CMutableTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 546 : : /** Sign the tx given the input coins and sighash. */
# 547 : : bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const;
# 548 : : SigningResult SignMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) const;
# 549 : :
# 550 : : /**
# 551 : : * Fills out a PSBT with information from the wallet. Fills in UTXOs if we have
# 552 : : * them. Tries to sign if sign=true. Sets `complete` if the PSBT is now complete
# 553 : : * (i.e. has all required signatures or signature-parts, and is ready to
# 554 : : * finalize.) Sets `error` and returns false if something goes wrong.
# 555 : : *
# 556 : : * @param[in] psbtx PartiallySignedTransaction to fill in
# 557 : : * @param[out] complete indicates whether the PSBT is now complete
# 558 : : * @param[in] sighash_type the sighash type to use when signing (if PSBT does not specify)
# 559 : : * @param[in] sign whether to sign or not
# 560 : : * @param[in] bip32derivs whether to fill in bip32 derivation information if available
# 561 : : * @param[out] n_signed the number of inputs signed by this wallet
# 562 : : * @param[in] finalize whether to create the final scriptSig or scriptWitness if possible
# 563 : : * return error
# 564 : : */
# 565 : : TransactionError FillPSBT(PartiallySignedTransaction& psbtx,
# 566 : : bool& complete,
# 567 : : int sighash_type = SIGHASH_DEFAULT,
# 568 : : bool sign = true,
# 569 : : bool bip32derivs = true,
# 570 : : size_t* n_signed = nullptr,
# 571 : : bool finalize = true) const;
# 572 : :
# 573 : : /**
# 574 : : * Submit the transaction to the node's mempool and then relay to peers.
# 575 : : * Should be called after CreateTransaction unless you want to abort
# 576 : : * broadcasting the transaction.
# 577 : : *
# 578 : : * @param[in] tx The transaction to be broadcast.
# 579 : : * @param[in] mapValue key-values to be set on the transaction.
# 580 : : * @param[in] orderForm BIP 70 / BIP 21 order form details to be set on the transaction.
# 581 : : */
# 582 : : void CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm);
# 583 : :
# 584 : : /** Pass this transaction to node for mempool insertion and relay to peers if flag set to true */
# 585 : : bool SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string, bool relay) const;
# 586 : :
# 587 : : bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts, const CCoinControl* coin_control = nullptr) const
# 588 : 0 : {
# 589 : 0 : std::vector<CTxOut> v_txouts(txouts.size());
# 590 : 0 : std::copy(txouts.begin(), txouts.end(), v_txouts.begin());
# 591 : 0 : return DummySignTx(txNew, v_txouts, coin_control);
# 592 : 0 : }
# 593 : : bool DummySignTx(CMutableTransaction &txNew, const std::vector<CTxOut> &txouts, const CCoinControl* coin_control = nullptr) const;
# 594 : :
# 595 : : bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 596 : : bool ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 597 : : 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);
# 598 : : 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);
# 599 : :
# 600 : : CFeeRate m_pay_tx_fee{DEFAULT_PAY_TX_FEE};
# 601 : : unsigned int m_confirm_target{DEFAULT_TX_CONFIRM_TARGET};
# 602 : : /** Allow Coin Selection to pick unconfirmed UTXOs that were sent from our own wallet if it
# 603 : : * cannot fund the transaction otherwise. */
# 604 : : bool m_spend_zero_conf_change{DEFAULT_SPEND_ZEROCONF_CHANGE};
# 605 : : bool m_signal_rbf{DEFAULT_WALLET_RBF};
# 606 : : bool m_allow_fallback_fee{true}; //!< will be false if -fallbackfee=0
# 607 : : CFeeRate m_min_fee{DEFAULT_TRANSACTION_MINFEE}; //!< Override with -mintxfee
# 608 : : /**
# 609 : : * If fee estimation does not have enough data to provide estimates, use this fee instead.
# 610 : : * Has no effect if not using fee estimation
# 611 : : * Override with -fallbackfee
# 612 : : */
# 613 : : CFeeRate m_fallback_fee{DEFAULT_FALLBACK_FEE};
# 614 : :
# 615 : : /** If the cost to spend a change output at this feerate is greater than the value of the
# 616 : : * output itself, just drop it to fees. */
# 617 : : CFeeRate m_discard_rate{DEFAULT_DISCARD_FEE};
# 618 : :
# 619 : : /** When the actual feerate is less than the consolidate feerate, we will tend to make transactions which
# 620 : : * consolidate inputs. When the actual feerate is greater than the consolidate feerate, we will tend to make
# 621 : : * transactions which have the lowest fees.
# 622 : : */
# 623 : : CFeeRate m_consolidate_feerate{DEFAULT_CONSOLIDATE_FEERATE};
# 624 : :
# 625 : : /** The maximum fee amount we're willing to pay to prioritize partial spend avoidance. */
# 626 : : CAmount m_max_aps_fee{DEFAULT_MAX_AVOIDPARTIALSPEND_FEE}; //!< note: this is absolute fee, not fee rate
# 627 : : OutputType m_default_address_type{DEFAULT_ADDRESS_TYPE};
# 628 : : /**
# 629 : : * Default output type for change outputs. When unset, automatically choose type
# 630 : : * based on address type setting and the types other of non-change outputs
# 631 : : * (see -changetype option documentation and implementation in
# 632 : : * CWallet::TransactionChangeType for details).
# 633 : : */
# 634 : : std::optional<OutputType> m_default_change_type{};
# 635 : : /** Absolute maximum transaction fee (in satoshis) used by default for the wallet */
# 636 : : CAmount m_default_max_tx_fee{DEFAULT_TRANSACTION_MAXFEE};
# 637 : :
# 638 : : size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 639 : : bool TopUpKeyPool(unsigned int kpSize = 0);
# 640 : :
# 641 : : std::optional<int64_t> GetOldestKeyPoolTime() const;
# 642 : :
# 643 : : std::set<CTxDestination> GetLabelAddresses(const std::string& label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 644 : :
# 645 : : /**
# 646 : : * Marks all outputs in each one of the destinations dirty, so their cache is
# 647 : : * reset and does not return outdated information.
# 648 : : */
# 649 : : void MarkDestinationsDirty(const std::set<CTxDestination>& destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 650 : :
# 651 : : bool GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, bilingual_str& error);
# 652 : : bool GetNewChangeDestination(const OutputType type, CTxDestination& dest, bilingual_str& error);
# 653 : :
# 654 : : isminetype IsMine(const CTxDestination& dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 655 : : isminetype IsMine(const CScript& script) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 656 : : /**
# 657 : : * Returns amount of debit if the input matches the
# 658 : : * filter, otherwise returns 0
# 659 : : */
# 660 : : CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
# 661 : : isminetype IsMine(const CTxOut& txout) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 662 : : bool IsMine(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 663 : : /** should probably be renamed to IsRelevantToMe */
# 664 : : bool IsFromMe(const CTransaction& tx) const;
# 665 : : CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
# 666 : : void chainStateFlushed(const CBlockLocator& loc) override;
# 667 : :
# 668 : : DBErrors LoadWallet();
# 669 : : DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 670 : :
# 671 : : bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
# 672 : :
# 673 : : bool DelAddressBook(const CTxDestination& address);
# 674 : :
# 675 : : bool IsAddressUsed(const CTxDestination& dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 676 : : bool SetAddressUsed(WalletBatch& batch, const CTxDestination& dest, bool used) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 677 : :
# 678 : : std::vector<std::string> GetAddressReceiveRequests() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 679 : : bool SetAddressReceiveRequest(WalletBatch& batch, const CTxDestination& dest, const std::string& id, const std::string& value) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 680 : :
# 681 : : unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 682 : :
# 683 : : //! signify that a particular wallet feature is now used.
# 684 : : void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr) override;
# 685 : :
# 686 : : //! get the current wallet format (the oldest client version guaranteed to understand this wallet)
# 687 : 1829 : int GetVersion() const { LOCK(cs_wallet); return nWalletVersion; }
# 688 : :
# 689 : : //! Get wallet transactions that conflict with given transaction (spend same outputs)
# 690 : : std::set<uint256> GetConflicts(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 691 : :
# 692 : : //! Check if a given transaction has any of its outputs spent by another transaction in the wallet
# 693 : : bool HasWalletSpend(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 694 : :
# 695 : : //! Flush wallet (bitdb flush)
# 696 : : void Flush();
# 697 : :
# 698 : : //! Close wallet database
# 699 : : void Close();
# 700 : :
# 701 : : /** Wallet is about to be unloaded */
# 702 : : boost::signals2::signal<void ()> NotifyUnload;
# 703 : :
# 704 : : /**
# 705 : : * Address book entry changed.
# 706 : : * @note called without lock cs_wallet held.
# 707 : : */
# 708 : : boost::signals2::signal<void(const CTxDestination& address,
# 709 : : const std::string& label, bool isMine,
# 710 : : const std::string& purpose, ChangeType status)>
# 711 : : NotifyAddressBookChanged;
# 712 : :
# 713 : : /**
# 714 : : * Wallet transaction added, removed or updated.
# 715 : : * @note called with lock cs_wallet held.
# 716 : : */
# 717 : : boost::signals2::signal<void(const uint256& hashTx, ChangeType status)> NotifyTransactionChanged;
# 718 : :
# 719 : : /** Show progress e.g. for rescan */
# 720 : : boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
# 721 : :
# 722 : : /** Watch-only address added */
# 723 : : boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
# 724 : :
# 725 : : /** Keypool has new keys */
# 726 : : boost::signals2::signal<void ()> NotifyCanGetAddressesChanged;
# 727 : :
# 728 : : /**
# 729 : : * Wallet status (encrypted, locked) changed.
# 730 : : * Note: Called without locks held.
# 731 : : */
# 732 : : boost::signals2::signal<void (CWallet* wallet)> NotifyStatusChanged;
# 733 : :
# 734 : : /** Inquire whether this wallet broadcasts transactions. */
# 735 : 5163 : bool GetBroadcastTransactions() const { return fBroadcastTransactions; }
# 736 : : /** Set whether this wallet broadcasts transactions. */
# 737 : 786 : void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
# 738 : :
# 739 : : /** Return whether transaction can be abandoned */
# 740 : : bool TransactionCanBeAbandoned(const uint256& hashTx) const;
# 741 : :
# 742 : : /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
# 743 : : bool AbandonTransaction(const uint256& hashTx);
# 744 : :
# 745 : : /** Mark a transaction as replaced by another transaction (e.g., BIP 125). */
# 746 : : bool MarkReplaced(const uint256& originalHash, const uint256& newHash);
# 747 : :
# 748 : : /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
# 749 : : 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);
# 750 : :
# 751 : : /**
# 752 : : * Wallet post-init setup
# 753 : : * Gives the wallet a chance to register repetitive tasks and complete post-init tasks
# 754 : : */
# 755 : : void postInitProcess();
# 756 : :
# 757 : : bool BackupWallet(const std::string& strDest) const;
# 758 : :
# 759 : : /* Returns true if HD is enabled */
# 760 : : bool IsHDEnabled() const;
# 761 : :
# 762 : : /* Returns true if the wallet can give out new addresses. This means it has keys in the keypool or can generate new keys */
# 763 : : bool CanGetAddresses(bool internal = false) const;
# 764 : :
# 765 : : /**
# 766 : : * Blocks until the wallet state is up-to-date to /at least/ the current
# 767 : : * chain at the time this function is entered
# 768 : : * Obviously holding cs_main/cs_wallet when going into this call may cause
# 769 : : * deadlock
# 770 : : */
# 771 : : void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main) EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet);
# 772 : :
# 773 : : /** set a single wallet flag */
# 774 : : void SetWalletFlag(uint64_t flags);
# 775 : :
# 776 : : /** Unsets a single wallet flag */
# 777 : : void UnsetWalletFlag(uint64_t flag);
# 778 : :
# 779 : : /** check if a certain wallet flag is set */
# 780 : : bool IsWalletFlagSet(uint64_t flag) const override;
# 781 : :
# 782 : : /** overwrite all flags by the given uint64_t
# 783 : : returns false if unknown, non-tolerable flags are present */
# 784 : : bool AddWalletFlags(uint64_t flags);
# 785 : : /** Loads the flags into the wallet. (used by LoadWallet) */
# 786 : : bool LoadWalletFlags(uint64_t flags);
# 787 : :
# 788 : : /** Determine if we are a legacy wallet */
# 789 : : bool IsLegacy() const;
# 790 : :
# 791 : : /** Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet has no name */
# 792 : 120463 : const std::string GetDisplayName() const override {
# 793 [ + + ]: 120463 : std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
# 794 : 120463 : return strprintf("[%s]", wallet_name);
# 795 : 120463 : };
# 796 : :
# 797 : : /** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
# 798 : : template<typename... Params>
# 799 : 80618 : void WalletLogPrintf(std::string fmt, Params... parameters) const {
# 800 : 80618 : LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
# 801 : 80618 : };
# 802 : :
# 803 : : /** Upgrade the wallet */
# 804 : : bool UpgradeWallet(int version, bilingual_str& error);
# 805 : :
# 806 : : //! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers
# 807 : : std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
# 808 : :
# 809 : : //! Returns all unique ScriptPubKeyMans
# 810 : : std::set<ScriptPubKeyMan*> GetAllScriptPubKeyMans() const;
# 811 : :
# 812 : : //! Get the ScriptPubKeyMan for the given OutputType and internal/external chain.
# 813 : : ScriptPubKeyMan* GetScriptPubKeyMan(const OutputType& type, bool internal) const;
# 814 : :
# 815 : : //! Get all the ScriptPubKeyMans for a script
# 816 : : std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script) const;
# 817 : : //! Get the ScriptPubKeyMan by id
# 818 : : ScriptPubKeyMan* GetScriptPubKeyMan(const uint256& id) const;
# 819 : :
# 820 : : //! Get the SigningProvider for a script
# 821 : : std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
# 822 : : std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
# 823 : :
# 824 : : //! Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
# 825 : : LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const;
# 826 : : LegacyScriptPubKeyMan* GetOrCreateLegacyScriptPubKeyMan();
# 827 : :
# 828 : : //! Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
# 829 : : void SetupLegacyScriptPubKeyMan();
# 830 : :
# 831 : : const CKeyingMaterial& GetEncryptionKey() const override;
# 832 : : bool HasEncryptionKeys() const override;
# 833 : :
# 834 : : /** Get last block processed height */
# 835 : : int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
# 836 : 3904738 : {
# 837 : 3904738 : AssertLockHeld(cs_wallet);
# 838 : 3904738 : assert(m_last_block_processed_height >= 0);
# 839 : 0 : return m_last_block_processed_height;
# 840 : 3904738 : };
# 841 : : uint256 GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
# 842 : 104885 : {
# 843 : 104885 : AssertLockHeld(cs_wallet);
# 844 : 104885 : assert(m_last_block_processed_height >= 0);
# 845 : 0 : return m_last_block_processed;
# 846 : 104885 : }
# 847 : : /** Set last block processed height, currently only use in unit test */
# 848 : : void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
# 849 : 12 : {
# 850 : 12 : AssertLockHeld(cs_wallet);
# 851 : 12 : m_last_block_processed_height = block_height;
# 852 : 12 : m_last_block_processed = block_hash;
# 853 : 12 : };
# 854 : :
# 855 : : //! Connect the signals from ScriptPubKeyMans to the signals in CWallet
# 856 : : void ConnectScriptPubKeyManNotifiers();
# 857 : :
# 858 : : //! Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it
# 859 : : void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc);
# 860 : :
# 861 : : //! Adds the active ScriptPubKeyMan for the specified type and internal. Writes it to the wallet file
# 862 : : //! @param[in] id The unique id for the ScriptPubKeyMan
# 863 : : //! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for
# 864 : : //! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
# 865 : : void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
# 866 : :
# 867 : : //! Loads an active ScriptPubKeyMan for the specified type and internal. (used by LoadWallet)
# 868 : : //! @param[in] id The unique id for the ScriptPubKeyMan
# 869 : : //! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for
# 870 : : //! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
# 871 : : void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);
# 872 : :
# 873 : : //! Remove specified ScriptPubKeyMan from set of active SPK managers. Writes the change to the wallet file.
# 874 : : //! @param[in] id The unique id for the ScriptPubKeyMan
# 875 : : //! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for
# 876 : : //! @param[in] internal Whether this ScriptPubKeyMan provides change addresses
# 877 : : void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal);
# 878 : :
# 879 : : //! Create new DescriptorScriptPubKeyMans and add them to the wallet
# 880 : : void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 881 : :
# 882 : : //! Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet
# 883 : : DescriptorScriptPubKeyMan* GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const;
# 884 : :
# 885 : : //! Returns whether the provided ScriptPubKeyMan is internal
# 886 : : //! @param[in] spk_man The ScriptPubKeyMan to test
# 887 : : //! @return contains value only for active DescriptorScriptPubKeyMan, otherwise undefined
# 888 : : std::optional<bool> IsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const;
# 889 : :
# 890 : : //! Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type
# 891 : : ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
# 892 : : };
# 893 : :
# 894 : : /**
# 895 : : * Called periodically by the schedule thread. Prompts individual wallets to resend
# 896 : : * their transactions. Actual rebroadcast schedule is managed by the wallets themselves.
# 897 : : */
# 898 : : void MaybeResendWalletTxs(WalletContext& context);
# 899 : :
# 900 : : /** RAII object to check and reserve a wallet rescan */
# 901 : : class WalletRescanReserver
# 902 : : {
# 903 : : private:
# 904 : : CWallet& m_wallet;
# 905 : : bool m_could_reserve;
# 906 : : public:
# 907 : 1006 : explicit WalletRescanReserver(CWallet& w) : m_wallet(w), m_could_reserve(false) {}
# 908 : :
# 909 : : bool reserve()
# 910 : 884 : {
# 911 : 884 : assert(!m_could_reserve);
# 912 [ - + ]: 884 : if (m_wallet.fScanningWallet.exchange(true)) {
# 913 : 0 : return false;
# 914 : 0 : }
# 915 : 884 : m_wallet.m_scanning_start = GetTimeMillis();
# 916 : 884 : m_wallet.m_scanning_progress = 0;
# 917 : 884 : m_could_reserve = true;
# 918 : 884 : return true;
# 919 : 884 : }
# 920 : :
# 921 : : bool isReserved() const
# 922 : 835 : {
# 923 [ + - ][ + - ]: 835 : return (m_could_reserve && m_wallet.fScanningWallet);
# 924 : 835 : }
# 925 : :
# 926 : : ~WalletRescanReserver()
# 927 : 1006 : {
# 928 [ + + ]: 1006 : if (m_could_reserve) {
# 929 : 884 : m_wallet.fScanningWallet = false;
# 930 : 884 : }
# 931 : 1006 : }
# 932 : : };
# 933 : :
# 934 : : //! Add wallet name to persistent configuration so it will be loaded on startup.
# 935 : : bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
# 936 : :
# 937 : : //! Remove wallet name from persistent configuration so it will not be loaded on startup.
# 938 : : bool RemoveWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);
# 939 : :
# 940 : : bool DummySignInput(const SigningProvider& provider, CTxIn &tx_in, const CTxOut &txout, bool use_max_sig);
# 941 : :
# 942 : : bool FillInputToWeight(CTxIn& txin, int64_t target_weight);
# 943 : : } // namespace wallet
# 944 : :
# 945 : : #endif // BITCOIN_WALLET_WALLET_H
|