Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1001AssertLockHeld(cs_wallet);1002assert(m_last_block_processed_height >= 0);1003return m_last_block_processed_height;1004};1005uint256 GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)1006{1007AssertLockHeld(cs_wallet);1008assert(m_last_block_processed_height >= 0);1009return m_last_block_processed;1010}1011/** Set last block processed height, and write to database */1012void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1013/** Write the current best block to database */1014void WriteBestBlock() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1016//! Connect the signals from ScriptPubKeyMans to the signals in CWallet1017void ConnectScriptPubKeyManNotifiers();1019//! Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it1020void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc, const KeyMap& keys, const CryptedKeyMap& ckeys);1022//! Adds the active ScriptPubKeyMan for the specified type and internal. Writes it to the wallet file1023//! @param[in] id The unique id for the ScriptPubKeyMan1024//! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for1025//! @param[in] internal Whether this ScriptPubKeyMan provides change addresses1026void AddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);1028//! Loads an active ScriptPubKeyMan for the specified type and internal. (used by LoadWallet)1029//! @param[in] id The unique id for the ScriptPubKeyMan1030//! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for1031//! @param[in] internal Whether this ScriptPubKeyMan provides change addresses1032void LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal);1034//! Remove specified ScriptPubKeyMan from set of active SPK managers. Writes the change to the wallet file.1035//! @param[in] id The unique id for the ScriptPubKeyMan1036//! @param[in] type The OutputType this ScriptPubKeyMan provides addresses for1037//! @param[in] internal Whether this ScriptPubKeyMan provides change addresses1038void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal);1040//! Create new DescriptorScriptPubKeyMan and add it to the wallet1041DescriptorScriptPubKeyMan& SetupDescriptorScriptPubKeyMan(WalletBatch& batch, const CExtKey& master_key, const OutputType& output_type, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1042//! Create new DescriptorScriptPubKeyMans and add them to the wallet1043void SetupDescriptorScriptPubKeyMans(WalletBatch& batch, const CExtKey& master_key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1044void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1046//! Create new seed and default DescriptorScriptPubKeyMans for this wallet1047void SetupOwnDescriptorScriptPubKeyMans(WalletBatch& batch) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1049//! Setup new descriptors or seed for new address generation1050void SetupWalletGeneration() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1052//! Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet1053DescriptorScriptPubKeyMan* GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const;1055//! Returns whether the provided ScriptPubKeyMan is internal1056//! @param[in] spk_man The ScriptPubKeyMan to test1057//! @return contains value only for active DescriptorScriptPubKeyMan, otherwise undefined1058std::optional<bool> IsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const;1060//! Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type1061util::Result<std::reference_wrapper<DescriptorScriptPubKeyMan>> AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1063/** Move all records from the BDB database to a new SQLite database for storage.1064* The original BDB file will be deleted and replaced with a new SQLite file.1065* A backup is not created.1066* May crash if something unexpected happens in the filesystem.1067*/1068bool MigrateToSQLite(bilingual_str& error) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1070//! Get all of the descriptors from a legacy wallet1071std::optional<MigrationData> GetDescriptorsForLegacy(bilingual_str& error) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1073//! Adds the ScriptPubKeyMans from MigrationData to this wallet, removes the LegacyDataSPKM,1074//! and moves transaction and address book entries to watchonly_wallet or solvable_wallet as needed.1075util::Result<void> ApplyMigrationData(WalletBatch& local_wallet_batch, MigrationData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1077//! Whether the (external) signer performs R-value signature grinding1078bool CanGrindR() const;1080//! Add scriptPubKeys for this ScriptPubKeyMan into the scriptPubKey cache1081void CacheNewScriptPubKeys(const std::set<CScript>& spks, ScriptPubKeyMan* spkm);1083void TopUpCallback(const std::set<CScript>& spks, ScriptPubKeyMan* spkm) override;1085//! Which descriptors GetHDPubKeys() should consider.1086enum class HDKeyFilter {1087Active, //!< Only active descriptors1088All, //!< All descriptors1089UnusedKey, //!< Only unused(KEY) descriptors1090};1091using HDPubKeyMap = std::map<CExtPubKey, std::set<DescriptorScriptPubKeyMan*>>;1092//! Retrieve descriptor xpubs matching the requested filter.1093HDPubKeyMap GetHDPubKeys(HDKeyFilter filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);1095//! Find the private key for the given key id from the wallet's descriptors, if available1096//! Returns nullopt when no descriptor has the key or if the wallet is locked.1097std::optional<CKey> GetKey(const CKeyID& keyid) const;1099//! Reconstruct the extended private key for an HD xpub. Returns nullopt when1100//! no descriptor has the private key, or the wallet is locked.1101std::optional<CExtKey> GetExtKey(const CExtPubKey& xpub) const;1103//! Disconnect chain notifications and wait for all notifications to be processed1104void DisconnectChainNotifications();1105};1107/**1108* Called periodically by the schedule thread. Prompts individual wallets to resend1109* their transactions. Actual rebroadcast schedule is managed by the wallets themselves.1110*/1111void MaybeResendWalletTxs(WalletContext& context);1113/** RAII object to check and reserve a wallet rescan */1114class WalletRescanReserver1115{1116private:1117using Clock = std::chrono::steady_clock;1118using NowFn = std::function<Clock::time_point()>;1119CWallet& m_wallet;1120bool m_could_reserve{false};1121NowFn m_now;1122public:1123explicit WalletRescanReserver(CWallet& w) : m_wallet(w) {}1125bool reserve(bool with_passphrase = false)1126{1127assert(!m_could_reserve);1128if (m_wallet.fScanningWallet.exchange(true)) {1129return false;1130}1131// Discard any abort request left over from previous reservation, so1132// that an abort requested while the reservation is held always applies1133// to abort this rescan, even if it arrives before the scan loop starts.1134m_wallet.fAbortRescan = false;1135m_wallet.m_scanning_with_passphrase.exchange(with_passphrase);1136m_wallet.m_scanning_start = SteadyClock::now();1137m_wallet.m_scanning_progress = 0;1138m_could_reserve = true;1139return true;1140}1142bool isReserved() const1143{1144return (m_could_reserve && m_wallet.fScanningWallet);1145}1147Clock::time_point now() const { return m_now ? m_now() : Clock::now(); };1149void setNow(NowFn now) { m_now = std::move(now); }1151~WalletRescanReserver()1152{1153if (m_could_reserve) {1154m_wallet.fScanningWallet = false;1155m_wallet.m_scanning_with_passphrase = false;1156}1157}1158};1160//! Add wallet name to persistent configuration so it will be loaded on startup.1161bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);1163//! Remove wallet name from persistent configuration so it will not be loaded on startup.1164bool RemoveWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);1166struct MigrationResult {1167std::string wallet_name;1168std::optional<std::string> watchonly_wallet_name;1169std::optional<std::string> solvables_wallet_name;1170std::shared_ptr<CWallet> wallet;1171std::shared_ptr<CWallet> watchonly_wallet;1172std::shared_ptr<CWallet> solvables_wallet;1173fs::path backup_path;1174};1176//! Do all steps to migrate a legacy wallet to a descriptor wallet1177[[nodiscard]] util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& wallet_name, const SecureString& passphrase, WalletContext& context, bool load_wallet = true);1178//! Requirement: The wallet provided to this function must be isolated, with no attachment to the node's context.1179[[nodiscard]] util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet> local_wallet, const SecureString& passphrase, WalletContext& context, bool load_wallet = true);1181//! Determine the path that the wallet is stored in1182util::Result<fs::path> GetWalletPath(const std::string& name);1183} // namespace wallet1185#endif // BITCOIN_WALLET_WALLET_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.