wallet: Move LegacySPKM data storage and handling to LegacyDataSPKM
In order to load the necessary data for migrating a legacy wallet without the full LegacyScriptPubKeyMan, move the data storage and loading components to LegacyDataSPKM. LegacyScriptPubKeyMan now subclasses that.
This commit is contained in:
1 parent
517e204bac
commit
7461d0c006
4 files changed
+125
-86
No files matched your search
@@ -80,7 +80,7 @@ bool PermitsUncompressed(IsMineSigVersion sigversion)
|
|||||||
return sigversion == IsMineSigVersion::TOP || sigversion == IsMineSigVersion::P2SH;
|
return sigversion == IsMineSigVersion::TOP || sigversion == IsMineSigVersion::P2SH;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HaveKeys(const std::vector<valtype>& pubkeys, const LegacyScriptPubKeyMan& keystore)
|
bool HaveKeys(const std::vector<valtype>& pubkeys, const LegacyDataSPKM& keystore)
|
||||||
{
|
{
|
||||||
for (const valtype& pubkey : pubkeys) {
|
for (const valtype& pubkey : pubkeys) {
|
||||||
CKeyID keyID = CPubKey(pubkey).GetID();
|
CKeyID keyID = CPubKey(pubkey).GetID();
|
||||||
@@ -227,7 +227,7 @@ isminetype LegacyScriptPubKeyMan::IsMine(const CScript& script) const
|
|||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key)
|
bool LegacyDataSPKM::CheckDecryptionKey(const CKeyingMaterial& master_key)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
@@ -581,7 +581,7 @@ int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
|
|||||||
return nTimeFirstKey;
|
return nTimeFirstKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SigningProvider> LegacyScriptPubKeyMan::GetSolvingProvider(const CScript& script) const
|
std::unique_ptr<SigningProvider> LegacyDataSPKM::GetSolvingProvider(const CScript& script) const
|
||||||
{
|
{
|
||||||
return std::make_unique<LegacySigningProvider>(*this);
|
return std::make_unique<LegacySigningProvider>(*this);
|
||||||
}
|
}
|
||||||
@@ -717,7 +717,7 @@ void LegacyScriptPubKeyMan::UpdateTimeFirstKey(int64_t nCreateTime)
|
|||||||
NotifyFirstKeyTimeChanged(this, nTimeFirstKey);
|
NotifyFirstKeyTimeChanged(this, nTimeFirstKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::LoadKey(const CKey& key, const CPubKey &pubkey)
|
bool LegacyDataSPKM::LoadKey(const CKey& key, const CPubKey &pubkey)
|
||||||
{
|
{
|
||||||
return AddKeyPubKeyInner(key, pubkey);
|
return AddKeyPubKeyInner(key, pubkey);
|
||||||
}
|
}
|
||||||
@@ -769,7 +769,7 @@ bool LegacyScriptPubKeyMan::AddKeyPubKeyWithDB(WalletBatch& batch, const CKey& s
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::LoadCScript(const CScript& redeemScript)
|
bool LegacyDataSPKM::LoadCScript(const CScript& redeemScript)
|
||||||
{
|
{
|
||||||
/* A sanity check was added in pull #3843 to avoid adding redeemScripts
|
/* A sanity check was added in pull #3843 to avoid adding redeemScripts
|
||||||
* that never can be redeemed. However, old wallets may still contain
|
* that never can be redeemed. However, old wallets may still contain
|
||||||
@@ -784,18 +784,36 @@ bool LegacyScriptPubKeyMan::LoadCScript(const CScript& redeemScript)
|
|||||||
return FillableSigningProvider::AddCScript(redeemScript);
|
return FillableSigningProvider::AddCScript(redeemScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LegacyDataSPKM::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata& meta)
|
||||||
|
{
|
||||||
|
LOCK(cs_KeyStore);
|
||||||
|
mapKeyMetadata[keyID] = meta;
|
||||||
|
}
|
||||||
|
|
||||||
void LegacyScriptPubKeyMan::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata& meta)
|
void LegacyScriptPubKeyMan::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata& meta)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
|
LegacyDataSPKM::LoadKeyMetadata(keyID, meta);
|
||||||
UpdateTimeFirstKey(meta.nCreateTime);
|
UpdateTimeFirstKey(meta.nCreateTime);
|
||||||
mapKeyMetadata[keyID] = meta;
|
}
|
||||||
|
|
||||||
|
void LegacyDataSPKM::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata& meta)
|
||||||
|
{
|
||||||
|
LOCK(cs_KeyStore);
|
||||||
|
m_script_metadata[script_id] = meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LegacyScriptPubKeyMan::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata& meta)
|
void LegacyScriptPubKeyMan::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata& meta)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
|
LegacyDataSPKM::LoadScriptMetadata(script_id, meta);
|
||||||
UpdateTimeFirstKey(meta.nCreateTime);
|
UpdateTimeFirstKey(meta.nCreateTime);
|
||||||
m_script_metadata[script_id] = meta;
|
}
|
||||||
|
|
||||||
|
bool LegacyDataSPKM::AddKeyPubKeyInner(const CKey& key, const CPubKey& pubkey)
|
||||||
|
{
|
||||||
|
LOCK(cs_KeyStore);
|
||||||
|
return FillableSigningProvider::AddKeyPubKey(key, pubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey)
|
bool LegacyScriptPubKeyMan::AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey)
|
||||||
@@ -823,7 +841,7 @@ bool LegacyScriptPubKeyMan::AddKeyPubKeyInner(const CKey& key, const CPubKey &pu
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret, bool checksum_valid)
|
bool LegacyDataSPKM::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret, bool checksum_valid)
|
||||||
{
|
{
|
||||||
// Set fDecryptionThoroughlyChecked to false when the checksum is invalid
|
// Set fDecryptionThoroughlyChecked to false when the checksum is invalid
|
||||||
if (!checksum_valid) {
|
if (!checksum_valid) {
|
||||||
@@ -833,7 +851,7 @@ bool LegacyScriptPubKeyMan::LoadCryptedKey(const CPubKey &vchPubKey, const std::
|
|||||||
return AddCryptedKeyInner(vchPubKey, vchCryptedSecret);
|
return AddCryptedKeyInner(vchPubKey, vchCryptedSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
bool LegacyDataSPKM::AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
assert(mapKeys.empty());
|
assert(mapKeys.empty());
|
||||||
@@ -861,13 +879,13 @@ bool LegacyScriptPubKeyMan::AddCryptedKey(const CPubKey &vchPubKey,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::HaveWatchOnly(const CScript &dest) const
|
bool LegacyDataSPKM::HaveWatchOnly(const CScript &dest) const
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
return setWatchOnly.count(dest) > 0;
|
return setWatchOnly.count(dest) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::HaveWatchOnly() const
|
bool LegacyDataSPKM::HaveWatchOnly() const
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
return (!setWatchOnly.empty());
|
return (!setWatchOnly.empty());
|
||||||
@@ -901,12 +919,12 @@ bool LegacyScriptPubKeyMan::RemoveWatchOnly(const CScript &dest)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::LoadWatchOnly(const CScript &dest)
|
bool LegacyDataSPKM::LoadWatchOnly(const CScript &dest)
|
||||||
{
|
{
|
||||||
return AddWatchOnlyInMem(dest);
|
return AddWatchOnlyInMem(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::AddWatchOnlyInMem(const CScript &dest)
|
bool LegacyDataSPKM::AddWatchOnlyInMem(const CScript &dest)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
setWatchOnly.insert(dest);
|
setWatchOnly.insert(dest);
|
||||||
@@ -950,7 +968,7 @@ bool LegacyScriptPubKeyMan::AddWatchOnly(const CScript& dest, int64_t nCreateTim
|
|||||||
return AddWatchOnly(dest);
|
return AddWatchOnly(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LegacyScriptPubKeyMan::LoadHDChain(const CHDChain& chain)
|
void LegacyDataSPKM::LoadHDChain(const CHDChain& chain)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
m_hd_chain = chain;
|
m_hd_chain = chain;
|
||||||
@@ -971,14 +989,14 @@ void LegacyScriptPubKeyMan::AddHDChain(const CHDChain& chain)
|
|||||||
m_hd_chain = chain;
|
m_hd_chain = chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LegacyScriptPubKeyMan::AddInactiveHDChain(const CHDChain& chain)
|
void LegacyDataSPKM::AddInactiveHDChain(const CHDChain& chain)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
assert(!chain.seed_id.IsNull());
|
assert(!chain.seed_id.IsNull());
|
||||||
m_inactive_hd_chains[chain.seed_id] = chain;
|
m_inactive_hd_chains[chain.seed_id] = chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::HaveKey(const CKeyID &address) const
|
bool LegacyDataSPKM::HaveKey(const CKeyID &address) const
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
if (!m_storage.HasEncryptionKeys()) {
|
if (!m_storage.HasEncryptionKeys()) {
|
||||||
@@ -987,7 +1005,7 @@ bool LegacyScriptPubKeyMan::HaveKey(const CKeyID &address) const
|
|||||||
return mapCryptedKeys.count(address) > 0;
|
return mapCryptedKeys.count(address) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::GetKey(const CKeyID &address, CKey& keyOut) const
|
bool LegacyDataSPKM::GetKey(const CKeyID &address, CKey& keyOut) const
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
if (!m_storage.HasEncryptionKeys()) {
|
if (!m_storage.HasEncryptionKeys()) {
|
||||||
@@ -1006,7 +1024,7 @@ bool LegacyScriptPubKeyMan::GetKey(const CKeyID &address, CKey& keyOut) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& info) const
|
bool LegacyDataSPKM::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& info) const
|
||||||
{
|
{
|
||||||
CKeyMetadata meta;
|
CKeyMetadata meta;
|
||||||
{
|
{
|
||||||
@@ -1026,7 +1044,7 @@ bool LegacyScriptPubKeyMan::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& inf
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
|
bool LegacyDataSPKM::GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
WatchKeyMap::const_iterator it = mapWatchKeys.find(address);
|
WatchKeyMap::const_iterator it = mapWatchKeys.find(address);
|
||||||
@@ -1037,7 +1055,7 @@ bool LegacyScriptPubKeyMan::GetWatchPubKey(const CKeyID &address, CPubKey &pubke
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LegacyScriptPubKeyMan::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
|
bool LegacyDataSPKM::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
if (!m_storage.HasEncryptionKeys()) {
|
if (!m_storage.HasEncryptionKeys()) {
|
||||||
@@ -1156,7 +1174,7 @@ void LegacyScriptPubKeyMan::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata&
|
|||||||
throw std::runtime_error(std::string(__func__) + ": writing HD chain model failed");
|
throw std::runtime_error(std::string(__func__) + ": writing HD chain model failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LegacyScriptPubKeyMan::LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
|
void LegacyDataSPKM::LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
if (keypool.m_pre_split) {
|
if (keypool.m_pre_split) {
|
||||||
@@ -1677,7 +1695,7 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
|
|||||||
return set_address;
|
return set_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_set<CScript, SaltedSipHasher> LegacyScriptPubKeyMan::GetScriptPubKeys() const
|
std::unordered_set<CScript, SaltedSipHasher> LegacyDataSPKM::GetScriptPubKeys() const
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
std::unordered_set<CScript, SaltedSipHasher> spks;
|
std::unordered_set<CScript, SaltedSipHasher> spks;
|
||||||
|
|||||||
@@ -276,31 +276,97 @@ static const std::unordered_set<OutputType> LEGACY_OUTPUT_TYPES {
|
|||||||
|
|
||||||
class DescriptorScriptPubKeyMan;
|
class DescriptorScriptPubKeyMan;
|
||||||
|
|
||||||
class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProvider
|
// Manages the data for a LegacyScriptPubKeyMan.
|
||||||
|
// This is the minimum necessary to load a legacy wallet so that it can be migrated.
|
||||||
|
class LegacyDataSPKM : public ScriptPubKeyMan, public FillableSigningProvider
|
||||||
{
|
{
|
||||||
private:
|
protected:
|
||||||
//! keeps track of whether Unlock has run a thorough check before
|
|
||||||
bool fDecryptionThoroughlyChecked = true;
|
|
||||||
|
|
||||||
using WatchOnlySet = std::set<CScript>;
|
using WatchOnlySet = std::set<CScript>;
|
||||||
using WatchKeyMap = std::map<CKeyID, CPubKey>;
|
using WatchKeyMap = std::map<CKeyID, CPubKey>;
|
||||||
|
|
||||||
WalletBatch *encrypted_batch GUARDED_BY(cs_KeyStore) = nullptr;
|
|
||||||
|
|
||||||
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
|
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
|
||||||
|
|
||||||
CryptedKeyMap mapCryptedKeys GUARDED_BY(cs_KeyStore);
|
CryptedKeyMap mapCryptedKeys GUARDED_BY(cs_KeyStore);
|
||||||
WatchOnlySet setWatchOnly GUARDED_BY(cs_KeyStore);
|
WatchOnlySet setWatchOnly GUARDED_BY(cs_KeyStore);
|
||||||
WatchKeyMap mapWatchKeys GUARDED_BY(cs_KeyStore);
|
WatchKeyMap mapWatchKeys GUARDED_BY(cs_KeyStore);
|
||||||
|
|
||||||
|
/* the HD chain data model (external chain counters) */
|
||||||
|
CHDChain m_hd_chain;
|
||||||
|
std::unordered_map<CKeyID, CHDChain, SaltedSipHasher> m_inactive_hd_chains;
|
||||||
|
|
||||||
|
//! keeps track of whether Unlock has run a thorough check before
|
||||||
|
bool fDecryptionThoroughlyChecked = true;
|
||||||
|
|
||||||
|
bool AddWatchOnlyInMem(const CScript &dest);
|
||||||
|
virtual bool AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey);
|
||||||
|
bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
||||||
|
|
||||||
|
public:
|
||||||
|
using ScriptPubKeyMan::ScriptPubKeyMan;
|
||||||
|
|
||||||
|
// Map from Key ID to key metadata.
|
||||||
|
std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_KeyStore);
|
||||||
|
|
||||||
|
// Map from Script ID to key metadata (for watch-only keys).
|
||||||
|
std::map<CScriptID, CKeyMetadata> m_script_metadata GUARDED_BY(cs_KeyStore);
|
||||||
|
|
||||||
|
// ScriptPubKeyMan overrides
|
||||||
|
bool CheckDecryptionKey(const CKeyingMaterial& master_key) override;
|
||||||
|
std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const override;
|
||||||
|
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const override;
|
||||||
|
uint256 GetID() const override { return uint256::ONE; }
|
||||||
|
|
||||||
|
// FillableSigningProvider overrides
|
||||||
|
bool HaveKey(const CKeyID &address) const override;
|
||||||
|
bool GetKey(const CKeyID &address, CKey& keyOut) const override;
|
||||||
|
bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
|
||||||
|
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
|
||||||
|
|
||||||
|
std::set<int64_t> setInternalKeyPool GUARDED_BY(cs_KeyStore);
|
||||||
|
std::set<int64_t> setExternalKeyPool GUARDED_BY(cs_KeyStore);
|
||||||
|
std::set<int64_t> set_pre_split_keypool GUARDED_BY(cs_KeyStore);
|
||||||
|
int64_t m_max_keypool_index GUARDED_BY(cs_KeyStore) = 0;
|
||||||
|
std::map<CKeyID, int64_t> m_pool_key_to_index;
|
||||||
|
|
||||||
|
//! Load metadata (used by LoadWallet)
|
||||||
|
virtual void LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &metadata);
|
||||||
|
virtual void LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata);
|
||||||
|
|
||||||
|
//! Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
|
||||||
|
bool LoadWatchOnly(const CScript &dest);
|
||||||
|
//! Returns whether the watch-only script is in the wallet
|
||||||
|
bool HaveWatchOnly(const CScript &dest) const;
|
||||||
|
//! Returns whether there are any watch-only things in the wallet
|
||||||
|
bool HaveWatchOnly() const;
|
||||||
|
//! Adds a key to the store, without saving it to disk (used by LoadWallet)
|
||||||
|
bool LoadKey(const CKey& key, const CPubKey &pubkey);
|
||||||
|
//! Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
|
||||||
|
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret, bool checksum_valid);
|
||||||
|
//! Adds a CScript to the store
|
||||||
|
bool LoadCScript(const CScript& redeemScript);
|
||||||
|
//! Load a HD chain model (used by LoadWallet)
|
||||||
|
void LoadHDChain(const CHDChain& chain);
|
||||||
|
void AddInactiveHDChain(const CHDChain& chain);
|
||||||
|
const CHDChain& GetHDChain() const { return m_hd_chain; }
|
||||||
|
//! Load a keypool entry
|
||||||
|
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool);
|
||||||
|
|
||||||
|
//! Fetches a pubkey from mapWatchKeys if it exists there
|
||||||
|
bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Implements the full legacy wallet behavior
|
||||||
|
class LegacyScriptPubKeyMan : public LegacyDataSPKM
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
WalletBatch *encrypted_batch GUARDED_BY(cs_KeyStore) = nullptr;
|
||||||
|
|
||||||
// By default, do not scan any block until keys/scripts are generated/imported
|
// By default, do not scan any block until keys/scripts are generated/imported
|
||||||
int64_t nTimeFirstKey GUARDED_BY(cs_KeyStore) = UNKNOWN_TIME;
|
int64_t nTimeFirstKey GUARDED_BY(cs_KeyStore) = UNKNOWN_TIME;
|
||||||
|
|
||||||
//! Number of pre-generated keys/scripts (part of the look-ahead process, used to detect payments)
|
//! Number of pre-generated keys/scripts (part of the look-ahead process, used to detect payments)
|
||||||
int64_t m_keypool_size GUARDED_BY(cs_KeyStore){DEFAULT_KEYPOOL_SIZE};
|
int64_t m_keypool_size GUARDED_BY(cs_KeyStore){DEFAULT_KEYPOOL_SIZE};
|
||||||
|
|
||||||
bool AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey);
|
bool AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey) override;
|
||||||
bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private version of AddWatchOnly method which does not accept a
|
* Private version of AddWatchOnly method which does not accept a
|
||||||
@@ -313,7 +379,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool AddWatchOnly(const CScript& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
bool AddWatchOnly(const CScript& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
||||||
bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
||||||
bool AddWatchOnlyInMem(const CScript &dest);
|
|
||||||
//! Adds a watch-only address to the store, and saves it to disk.
|
//! Adds a watch-only address to the store, and saves it to disk.
|
||||||
bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript& dest, int64_t create_time) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
bool AddWatchOnlyWithDB(WalletBatch &batch, const CScript& dest, int64_t create_time) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
||||||
|
|
||||||
@@ -328,18 +393,9 @@ private:
|
|||||||
/** Add a KeyOriginInfo to the wallet */
|
/** Add a KeyOriginInfo to the wallet */
|
||||||
bool AddKeyOriginWithDB(WalletBatch& batch, const CPubKey& pubkey, const KeyOriginInfo& info);
|
bool AddKeyOriginWithDB(WalletBatch& batch, const CPubKey& pubkey, const KeyOriginInfo& info);
|
||||||
|
|
||||||
/* the HD chain data model (external chain counters) */
|
|
||||||
CHDChain m_hd_chain;
|
|
||||||
std::unordered_map<CKeyID, CHDChain, SaltedSipHasher> m_inactive_hd_chains;
|
|
||||||
|
|
||||||
/* HD derive new child key (on internal or external chain) */
|
/* HD derive new child key (on internal or external chain) */
|
||||||
void DeriveNewChildKey(WalletBatch& batch, CKeyMetadata& metadata, CKey& secret, CHDChain& hd_chain, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
void DeriveNewChildKey(WalletBatch& batch, CKeyMetadata& metadata, CKey& secret, CHDChain& hd_chain, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
||||||
|
|
||||||
std::set<int64_t> setInternalKeyPool GUARDED_BY(cs_KeyStore);
|
|
||||||
std::set<int64_t> setExternalKeyPool GUARDED_BY(cs_KeyStore);
|
|
||||||
std::set<int64_t> set_pre_split_keypool GUARDED_BY(cs_KeyStore);
|
|
||||||
int64_t m_max_keypool_index GUARDED_BY(cs_KeyStore) = 0;
|
|
||||||
std::map<CKeyID, int64_t> m_pool_key_to_index;
|
|
||||||
// Tracks keypool indexes to CKeyIDs of keys that have been taken out of the keypool but may be returned to it
|
// Tracks keypool indexes to CKeyIDs of keys that have been taken out of the keypool but may be returned to it
|
||||||
std::map<int64_t, CKeyID> m_index_to_reserved_key;
|
std::map<int64_t, CKeyID> m_index_to_reserved_key;
|
||||||
|
|
||||||
@@ -376,12 +432,11 @@ private:
|
|||||||
|
|
||||||
bool TopUpChain(WalletBatch& batch, CHDChain& chain, unsigned int size);
|
bool TopUpChain(WalletBatch& batch, CHDChain& chain, unsigned int size);
|
||||||
public:
|
public:
|
||||||
LegacyScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) : ScriptPubKeyMan(storage), m_keypool_size(keypool_size) {}
|
LegacyScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) : LegacyDataSPKM(storage), m_keypool_size(keypool_size) {}
|
||||||
|
|
||||||
util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
|
util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
|
||||||
isminetype IsMine(const CScript& script) const override;
|
isminetype IsMine(const CScript& script) const override;
|
||||||
|
|
||||||
bool CheckDecryptionKey(const CKeyingMaterial& master_key) override;
|
|
||||||
bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override;
|
bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) override;
|
||||||
|
|
||||||
util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override;
|
util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override;
|
||||||
@@ -415,8 +470,6 @@ public:
|
|||||||
|
|
||||||
bool CanGetAddresses(bool internal = false) const override;
|
bool CanGetAddresses(bool internal = false) const override;
|
||||||
|
|
||||||
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const override;
|
|
||||||
|
|
||||||
bool CanProvide(const CScript& script, SignatureData& sigdata) override;
|
bool CanProvide(const CScript& script, SignatureData& sigdata) override;
|
||||||
|
|
||||||
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const override;
|
bool SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors) const override;
|
||||||
@@ -425,58 +478,27 @@ public:
|
|||||||
|
|
||||||
uint256 GetID() const override;
|
uint256 GetID() const override;
|
||||||
|
|
||||||
// Map from Key ID to key metadata.
|
|
||||||
std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_KeyStore);
|
|
||||||
|
|
||||||
// Map from Script ID to key metadata (for watch-only keys).
|
|
||||||
std::map<CScriptID, CKeyMetadata> m_script_metadata GUARDED_BY(cs_KeyStore);
|
|
||||||
|
|
||||||
//! Adds a key to the store, and saves it to disk.
|
//! Adds a key to the store, and saves it to disk.
|
||||||
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
|
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
|
||||||
//! Adds a key to the store, without saving it to disk (used by LoadWallet)
|
|
||||||
bool LoadKey(const CKey& key, const CPubKey &pubkey);
|
|
||||||
//! Adds an encrypted key to the store, and saves it to disk.
|
//! Adds an encrypted key to the store, and saves it to disk.
|
||||||
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
||||||
//! Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
|
|
||||||
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret, bool checksum_valid);
|
|
||||||
void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
||||||
//! Adds a CScript to the store
|
|
||||||
bool LoadCScript(const CScript& redeemScript);
|
|
||||||
//! 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) override;
|
||||||
void LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata);
|
void LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata) override;
|
||||||
//! Generate a new key
|
//! Generate a new key
|
||||||
CPubKey GenerateNewKey(WalletBatch& batch, CHDChain& hd_chain, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
CPubKey GenerateNewKey(WalletBatch& batch, CHDChain& hd_chain, bool internal = false) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
||||||
|
|
||||||
/* Set the HD chain model (chain child index counters) and writes it to the database */
|
/* Set the HD chain model (chain child index counters) and writes it to the database */
|
||||||
void AddHDChain(const CHDChain& chain);
|
void AddHDChain(const CHDChain& chain);
|
||||||
//! Load a HD chain model (used by LoadWallet)
|
|
||||||
void LoadHDChain(const CHDChain& chain);
|
|
||||||
const CHDChain& GetHDChain() const { return m_hd_chain; }
|
|
||||||
void AddInactiveHDChain(const CHDChain& chain);
|
|
||||||
|
|
||||||
//! Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
|
|
||||||
bool LoadWatchOnly(const CScript &dest);
|
|
||||||
//! Returns whether the watch-only script is in the wallet
|
|
||||||
bool HaveWatchOnly(const CScript &dest) const;
|
|
||||||
//! Returns whether there are any watch-only things in the wallet
|
|
||||||
bool HaveWatchOnly() const;
|
|
||||||
//! Remove a watch only script from the keystore
|
//! Remove a watch only script from the keystore
|
||||||
bool RemoveWatchOnly(const CScript &dest);
|
bool RemoveWatchOnly(const CScript &dest);
|
||||||
bool AddWatchOnly(const CScript& dest, int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
bool AddWatchOnly(const CScript& dest, int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
||||||
|
|
||||||
//! Fetches a pubkey from mapWatchKeys if it exists there
|
|
||||||
bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const;
|
|
||||||
|
|
||||||
/* SigningProvider overrides */
|
/* SigningProvider overrides */
|
||||||
bool HaveKey(const CKeyID &address) const override;
|
|
||||||
bool GetKey(const CKeyID &address, CKey& keyOut) const override;
|
|
||||||
bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
|
|
||||||
bool AddCScript(const CScript& redeemScript) override;
|
bool AddCScript(const CScript& redeemScript) override;
|
||||||
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
|
|
||||||
|
|
||||||
//! Load a keypool entry
|
|
||||||
void LoadKeyPool(int64_t nIndex, const CKeyPool &keypool);
|
|
||||||
bool NewKeyPool();
|
bool NewKeyPool();
|
||||||
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
|
||||||
|
|
||||||
@@ -525,7 +547,6 @@ public:
|
|||||||
const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
|
const std::map<CKeyID, int64_t>& GetAllReserveKeys() const { return m_pool_key_to_index; }
|
||||||
|
|
||||||
std::set<CKeyID> GetKeys() const override;
|
std::set<CKeyID> GetKeys() const override;
|
||||||
std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves scripts that were imported by bugs into the legacy spkm and are
|
* Retrieves scripts that were imported by bugs into the legacy spkm and are
|
||||||
@@ -544,9 +565,9 @@ public:
|
|||||||
class LegacySigningProvider : public SigningProvider
|
class LegacySigningProvider : public SigningProvider
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const LegacyScriptPubKeyMan& m_spk_man;
|
const LegacyDataSPKM& m_spk_man;
|
||||||
public:
|
public:
|
||||||
explicit LegacySigningProvider(const LegacyScriptPubKeyMan& spk_man) : m_spk_man(spk_man) {}
|
explicit LegacySigningProvider(const LegacyDataSPKM& spk_man) : m_spk_man(spk_man) {}
|
||||||
|
|
||||||
bool GetCScript(const CScriptID &scriptid, CScript& script) const override { return m_spk_man.GetCScript(scriptid, script); }
|
bool GetCScript(const CScriptID &scriptid, CScript& script) const override { return m_spk_man.GetCScript(scriptid, script); }
|
||||||
bool HaveCScript(const CScriptID &scriptid) const override { return m_spk_man.HaveCScript(scriptid); }
|
bool HaveCScript(const CScriptID &scriptid) const override { return m_spk_man.HaveCScript(scriptid); }
|
||||||
|
|||||||
+1
-1
@@ -962,7 +962,7 @@ public:
|
|||||||
LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const;
|
LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const;
|
||||||
LegacyScriptPubKeyMan* GetOrCreateLegacyScriptPubKeyMan();
|
LegacyScriptPubKeyMan* GetOrCreateLegacyScriptPubKeyMan();
|
||||||
|
|
||||||
//! Make a LegacyScriptPubKeyMan and set it for all types, internal, and external.
|
//! Make a Legacy(Data)SPKM and set it for all types, internal, and external.
|
||||||
void SetupLegacyScriptPubKeyMan();
|
void SetupLegacyScriptPubKeyMan();
|
||||||
|
|
||||||
bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const override;
|
bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const override;
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ bool LoadKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::stri
|
|||||||
}
|
}
|
||||||
if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadKey(key, vchPubKey))
|
if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadKey(key, vchPubKey))
|
||||||
{
|
{
|
||||||
strErr = "Error reading wallet database: LegacyScriptPubKeyMan::LoadKey failed";
|
strErr = "Error reading wallet database: LegacyDataSPKM::LoadKey failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
@@ -395,7 +395,7 @@ bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, st
|
|||||||
|
|
||||||
if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCryptedKey(vchPubKey, vchPrivKey, checksum_valid))
|
if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCryptedKey(vchPubKey, vchPrivKey, checksum_valid))
|
||||||
{
|
{
|
||||||
strErr = "Error reading wallet database: LegacyScriptPubKeyMan::LoadCryptedKey failed";
|
strErr = "Error reading wallet database: LegacyDataSPKM::LoadCryptedKey failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
@@ -586,7 +586,7 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
|
|||||||
value >> script;
|
value >> script;
|
||||||
if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCScript(script))
|
if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCScript(script))
|
||||||
{
|
{
|
||||||
strErr = "Error reading wallet database: LegacyScriptPubKeyMan::LoadCScript failed";
|
strErr = "Error reading wallet database: LegacyDataSPKM::LoadCScript failed";
|
||||||
return DBErrors::NONCRITICAL_ERROR;
|
return DBErrors::NONCRITICAL_ERROR;
|
||||||
}
|
}
|
||||||
return DBErrors::LOAD_OK;
|
return DBErrors::LOAD_OK;
|
||||||
|
|||||||
Reference in new issue
Block a user