Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.h
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | |||||
//! Default for -changetype | //! Default for -changetype | ||||
constexpr OutputType DEFAULT_CHANGE_TYPE{OutputType::CHANGE_AUTO}; | constexpr OutputType DEFAULT_CHANGE_TYPE{OutputType::CHANGE_AUTO}; | ||||
enum WalletFlags : uint64_t { | enum WalletFlags : uint64_t { | ||||
// Wallet flags in the upper section (> 1 << 31) will lead to not opening | // Wallet flags in the upper section (> 1 << 31) will lead to not opening | ||||
// the wallet if flag is unknown. | // the wallet if flag is unknown. | ||||
// Unknown wallet flags in the lower section <= (1 << 31) will be tolerated. | // Unknown wallet flags in the lower section <= (1 << 31) will be tolerated. | ||||
// Indicates that the metadata has already been upgraded to contain key | |||||
// origins | |||||
WALLET_FLAG_KEY_ORIGIN_METADATA = (1ULL << 1), | |||||
// Will enforce the rule that the wallet can't contain any private keys | // Will enforce the rule that the wallet can't contain any private keys | ||||
// (only watch-only/pubkeys). | // (only watch-only/pubkeys). | ||||
WALLET_FLAG_DISABLE_PRIVATE_KEYS = (1ULL << 32), | WALLET_FLAG_DISABLE_PRIVATE_KEYS = (1ULL << 32), | ||||
//! Flag set when a wallet contains no HD seed and no private keys, scripts, | //! Flag set when a wallet contains no HD seed and no private keys, scripts, | ||||
//! addresses, and other watch only things, and is therefore "blank." | //! addresses, and other watch only things, and is therefore "blank." | ||||
//! | //! | ||||
//! The only function this flag serves is to distinguish a blank wallet from | //! The only function this flag serves is to distinguish a blank wallet from | ||||
//! a newly created wallet when the wallet database is loaded, to avoid | //! a newly created wallet when the wallet database is loaded, to avoid | ||||
//! initialization that should only happen on first run. | //! initialization that should only happen on first run. | ||||
//! | //! | ||||
//! This flag is also a mandatory flag to prevent previous versions of | //! This flag is also a mandatory flag to prevent previous versions of | ||||
//! bitcoin from opening the wallet, thinking it was newly created, and | //! bitcoin from opening the wallet, thinking it was newly created, and | ||||
//! then improperly reinitializing it. | //! then improperly reinitializing it. | ||||
WALLET_FLAG_BLANK_WALLET = (1ULL << 33), | WALLET_FLAG_BLANK_WALLET = (1ULL << 33), | ||||
}; | }; | ||||
static constexpr uint64_t g_known_wallet_flags = | static constexpr uint64_t g_known_wallet_flags = | ||||
WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET; | WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET | | ||||
WALLET_FLAG_KEY_ORIGIN_METADATA; | |||||
/** A key pool entry */ | /** A key pool entry */ | ||||
class CKeyPool { | class CKeyPool { | ||||
public: | public: | ||||
int64_t nTime; | int64_t nTime; | ||||
CPubKey vchPubKey; | CPubKey vchPubKey; | ||||
// for change outputs | // for change outputs | ||||
bool fInternal; | bool fInternal; | ||||
▲ Show 20 Lines • Show All 678 Lines • ▼ Show 20 Lines | public: | ||||
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | ||||
// Map from Key ID to key metadata. | // Map from Key ID to key metadata. | ||||
std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_wallet); | std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_wallet); | ||||
// Map from Script ID to key metadata (for watch-only keys). | // Map from Script ID to key metadata (for watch-only keys). | ||||
std::map<CScriptID, CKeyMetadata> m_script_metadata GUARDED_BY(cs_wallet); | std::map<CScriptID, CKeyMetadata> m_script_metadata GUARDED_BY(cs_wallet); | ||||
bool WriteKeyMetadata(const CKeyMetadata &meta, const CPubKey &pubkey, | |||||
bool overwrite); | |||||
typedef std::map<unsigned int, CMasterKey> MasterKeyMap; | typedef std::map<unsigned int, CMasterKey> MasterKeyMap; | ||||
MasterKeyMap mapMasterKeys; | MasterKeyMap mapMasterKeys; | ||||
unsigned int nMasterKeyMaxID = 0; | unsigned int nMasterKeyMaxID = 0; | ||||
/** Construct wallet with specified name and database implementation. */ | /** Construct wallet with specified name and database implementation. */ | ||||
CWallet(const CChainParams &chainParamsIn, interfaces::Chain &chain, | CWallet(const CChainParams &chainParamsIn, interfaces::Chain &chain, | ||||
const WalletLocation &location, | const WalletLocation &location, | ||||
std::unique_ptr<WalletDatabase> databaseIn) | std::unique_ptr<WalletDatabase> databaseIn) | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
//! Load metadata (used by LoadWallet) | //! Load metadata (used by LoadWallet) | ||||
void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata) | void LoadKeyMetadata(const CKeyID &keyID, const CKeyMetadata &metadata) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | ||||
void LoadScriptMetadata(const CScriptID &script_id, | void LoadScriptMetadata(const CScriptID &script_id, | ||||
const CKeyMetadata &metadata) | const CKeyMetadata &metadata) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | ||||
//! Upgrade stored CKeyMetadata objects to store key origin info as | |||||
//! KeyOriginInfo | |||||
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); | |||||
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { | bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
nWalletVersion = nVersion; | nWalletVersion = nVersion; | ||||
nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); | nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); | ||||
return true; | return true; | ||||
} | } | ||||
void UpdateTimeFirstKey(int64_t nCreateTime) | void UpdateTimeFirstKey(int64_t nCreateTime) | ||||
▲ Show 20 Lines • Show All 442 Lines • ▼ Show 20 Lines | void WalletLogPrintfToBeContinued(std::string fmt, | ||||
parameters...); | parameters...); | ||||
}; | }; | ||||
/** | /** | ||||
* Implement lookup of key origin information through wallet key metadata. | * Implement lookup of key origin information through wallet key metadata. | ||||
*/ | */ | ||||
bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override; | bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const override; | ||||
/** | |||||
* Add a KeyOriginInfo to the wallet | |||||
*/ | |||||
bool AddKeyOrigin(const CPubKey &pubkey, const KeyOriginInfo &info); | |||||
friend struct WalletTestingSetup; | friend struct WalletTestingSetup; | ||||
}; | }; | ||||
/** | /** | ||||
* Called periodically by the schedule thread. Prompts individual wallets to | * Called periodically by the schedule thread. Prompts individual wallets to | ||||
* resend their transactions. Actual rebroadcast schedule is managed by the | * resend their transactions. Actual rebroadcast schedule is managed by the | ||||
* wallets themselves. | * wallets themselves. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |