Skip to content

Commit 7461d0c

Browse files
committed
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.
1 parent 517e204 commit 7461d0c

File tree

4 files changed

+125
-86
lines changed

4 files changed

+125
-86
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bool PermitsUncompressed(IsMineSigVersion sigversion)
8080
return sigversion == IsMineSigVersion::TOP || sigversion == IsMineSigVersion::P2SH;
8181
}
8282

83-
bool HaveKeys(const std::vector<valtype>& pubkeys, const LegacyScriptPubKeyMan& keystore)
83+
bool HaveKeys(const std::vector<valtype>& pubkeys, const LegacyDataSPKM& keystore)
8484
{
8585
for (const valtype& pubkey : pubkeys) {
8686
CKeyID keyID = CPubKey(pubkey).GetID();
@@ -227,7 +227,7 @@ isminetype LegacyScriptPubKeyMan::IsMine(const CScript& script) const
227227
assert(false);
228228
}
229229

230-
bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key)
230+
bool LegacyDataSPKM::CheckDecryptionKey(const CKeyingMaterial& master_key)
231231
{
232232
{
233233
LOCK(cs_KeyStore);
@@ -581,7 +581,7 @@ int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
581581
return nTimeFirstKey;
582582
}
583583

584-
std::unique_ptr<SigningProvider> LegacyScriptPubKeyMan::GetSolvingProvider(const CScript& script) const
584+
std::unique_ptr<SigningProvider> LegacyDataSPKM::GetSolvingProvider(const CScript& script) const
585585
{
586586
return std::make_unique<LegacySigningProvider>(*this);
587587
}
@@ -717,7 +717,7 @@ void LegacyScriptPubKeyMan::UpdateTimeFirstKey(int64_t nCreateTime)
717717
NotifyFirstKeyTimeChanged(this, nTimeFirstKey);
718718
}
719719

720-
bool LegacyScriptPubKeyMan::LoadKey(const CKey& key, const CPubKey &pubkey)
720+
bool LegacyDataSPKM::LoadKey(const CKey& key, const CPubKey &pubkey)
721721
{
722722
return AddKeyPubKeyInner(key, pubkey);
723723
}
@@ -769,7 +769,7 @@ bool LegacyScriptPubKeyMan::AddKeyPubKeyWithDB(WalletBatch& batch, const CKey& s
769769
return true;
770770
}
771771

772-
bool LegacyScriptPubKeyMan::LoadCScript(const CScript& redeemScript)
772+
bool LegacyDataSPKM::LoadCScript(const CScript& redeemScript)
773773
{
774774
/* A sanity check was added in pull #3843 to avoid adding redeemScripts
775775
* that never can be redeemed. However, old wallets may still contain
@@ -784,18 +784,36 @@ bool LegacyScriptPubKeyMan::LoadCScript(const CScript& redeemScript)
784784
return FillableSigningProvider::AddCScript(redeemScript);
785785
}
786786

787+
void LegacyDataSPKM::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata& meta)
788+
{
789+
LOCK(cs_KeyStore);
790+
mapKeyMetadata[keyID] = meta;
791+
}
792+
787793
void LegacyScriptPubKeyMan::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata& meta)
788794
{
789795
LOCK(cs_KeyStore);
796+
LegacyDataSPKM::LoadKeyMetadata(keyID, meta);
790797
UpdateTimeFirstKey(meta.nCreateTime);
791-
mapKeyMetadata[keyID] = meta;
798+
}
799+
800+
void LegacyDataSPKM::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata& meta)
801+
{
802+
LOCK(cs_KeyStore);
803+
m_script_metadata[script_id] = meta;
792804
}
793805

794806
void LegacyScriptPubKeyMan::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata& meta)
795807
{
796808
LOCK(cs_KeyStore);
809+
LegacyDataSPKM::LoadScriptMetadata(script_id, meta);
797810
UpdateTimeFirstKey(meta.nCreateTime);
798-
m_script_metadata[script_id] = meta;
811+
}
812+
813+
bool LegacyDataSPKM::AddKeyPubKeyInner(const CKey& key, const CPubKey& pubkey)
814+
{
815+
LOCK(cs_KeyStore);
816+
return FillableSigningProvider::AddKeyPubKey(key, pubkey);
799817
}
800818

801819
bool LegacyScriptPubKeyMan::AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey)
@@ -823,7 +841,7 @@ bool LegacyScriptPubKeyMan::AddKeyPubKeyInner(const CKey& key, const CPubKey &pu
823841
return true;
824842
}
825843

826-
bool LegacyScriptPubKeyMan::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret, bool checksum_valid)
844+
bool LegacyDataSPKM::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret, bool checksum_valid)
827845
{
828846
// Set fDecryptionThoroughlyChecked to false when the checksum is invalid
829847
if (!checksum_valid) {
@@ -833,7 +851,7 @@ bool LegacyScriptPubKeyMan::LoadCryptedKey(const CPubKey &vchPubKey, const std::
833851
return AddCryptedKeyInner(vchPubKey, vchCryptedSecret);
834852
}
835853

836-
bool LegacyScriptPubKeyMan::AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
854+
bool LegacyDataSPKM::AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
837855
{
838856
LOCK(cs_KeyStore);
839857
assert(mapKeys.empty());
@@ -861,13 +879,13 @@ bool LegacyScriptPubKeyMan::AddCryptedKey(const CPubKey &vchPubKey,
861879
}
862880
}
863881

864-
bool LegacyScriptPubKeyMan::HaveWatchOnly(const CScript &dest) const
882+
bool LegacyDataSPKM::HaveWatchOnly(const CScript &dest) const
865883
{
866884
LOCK(cs_KeyStore);
867885
return setWatchOnly.count(dest) > 0;
868886
}
869887

870-
bool LegacyScriptPubKeyMan::HaveWatchOnly() const
888+
bool LegacyDataSPKM::HaveWatchOnly() const
871889
{
872890
LOCK(cs_KeyStore);
873891
return (!setWatchOnly.empty());
@@ -901,12 +919,12 @@ bool LegacyScriptPubKeyMan::RemoveWatchOnly(const CScript &dest)
901919
return true;
902920
}
903921

904-
bool LegacyScriptPubKeyMan::LoadWatchOnly(const CScript &dest)
922+
bool LegacyDataSPKM::LoadWatchOnly(const CScript &dest)
905923
{
906924
return AddWatchOnlyInMem(dest);
907925
}
908926

909-
bool LegacyScriptPubKeyMan::AddWatchOnlyInMem(const CScript &dest)
927+
bool LegacyDataSPKM::AddWatchOnlyInMem(const CScript &dest)
910928
{
911929
LOCK(cs_KeyStore);
912930
setWatchOnly.insert(dest);
@@ -950,7 +968,7 @@ bool LegacyScriptPubKeyMan::AddWatchOnly(const CScript& dest, int64_t nCreateTim
950968
return AddWatchOnly(dest);
951969
}
952970

953-
void LegacyScriptPubKeyMan::LoadHDChain(const CHDChain& chain)
971+
void LegacyDataSPKM::LoadHDChain(const CHDChain& chain)
954972
{
955973
LOCK(cs_KeyStore);
956974
m_hd_chain = chain;
@@ -971,14 +989,14 @@ void LegacyScriptPubKeyMan::AddHDChain(const CHDChain& chain)
971989
m_hd_chain = chain;
972990
}
973991

974-
void LegacyScriptPubKeyMan::AddInactiveHDChain(const CHDChain& chain)
992+
void LegacyDataSPKM::AddInactiveHDChain(const CHDChain& chain)
975993
{
976994
LOCK(cs_KeyStore);
977995
assert(!chain.seed_id.IsNull());
978996
m_inactive_hd_chains[chain.seed_id] = chain;
979997
}
980998

981-
bool LegacyScriptPubKeyMan::HaveKey(const CKeyID &address) const
999+
bool LegacyDataSPKM::HaveKey(const CKeyID &address) const
9821000
{
9831001
LOCK(cs_KeyStore);
9841002
if (!m_storage.HasEncryptionKeys()) {
@@ -987,7 +1005,7 @@ bool LegacyScriptPubKeyMan::HaveKey(const CKeyID &address) const
9871005
return mapCryptedKeys.count(address) > 0;
9881006
}
9891007

990-
bool LegacyScriptPubKeyMan::GetKey(const CKeyID &address, CKey& keyOut) const
1008+
bool LegacyDataSPKM::GetKey(const CKeyID &address, CKey& keyOut) const
9911009
{
9921010
LOCK(cs_KeyStore);
9931011
if (!m_storage.HasEncryptionKeys()) {
@@ -1006,7 +1024,7 @@ bool LegacyScriptPubKeyMan::GetKey(const CKeyID &address, CKey& keyOut) const
10061024
return false;
10071025
}
10081026

1009-
bool LegacyScriptPubKeyMan::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& info) const
1027+
bool LegacyDataSPKM::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& info) const
10101028
{
10111029
CKeyMetadata meta;
10121030
{
@@ -1026,7 +1044,7 @@ bool LegacyScriptPubKeyMan::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& inf
10261044
return true;
10271045
}
10281046

1029-
bool LegacyScriptPubKeyMan::GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
1047+
bool LegacyDataSPKM::GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
10301048
{
10311049
LOCK(cs_KeyStore);
10321050
WatchKeyMap::const_iterator it = mapWatchKeys.find(address);
@@ -1037,7 +1055,7 @@ bool LegacyScriptPubKeyMan::GetWatchPubKey(const CKeyID &address, CPubKey &pubke
10371055
return false;
10381056
}
10391057

1040-
bool LegacyScriptPubKeyMan::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
1058+
bool LegacyDataSPKM::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
10411059
{
10421060
LOCK(cs_KeyStore);
10431061
if (!m_storage.HasEncryptionKeys()) {
@@ -1156,7 +1174,7 @@ void LegacyScriptPubKeyMan::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata&
11561174
throw std::runtime_error(std::string(__func__) + ": writing HD chain model failed");
11571175
}
11581176

1159-
void LegacyScriptPubKeyMan::LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
1177+
void LegacyDataSPKM::LoadKeyPool(int64_t nIndex, const CKeyPool &keypool)
11601178
{
11611179
LOCK(cs_KeyStore);
11621180
if (keypool.m_pre_split) {
@@ -1677,7 +1695,7 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
16771695
return set_address;
16781696
}
16791697

1680-
std::unordered_set<CScript, SaltedSipHasher> LegacyScriptPubKeyMan::GetScriptPubKeys() const
1698+
std::unordered_set<CScript, SaltedSipHasher> LegacyDataSPKM::GetScriptPubKeys() const
16811699
{
16821700
LOCK(cs_KeyStore);
16831701
std::unordered_set<CScript, SaltedSipHasher> spks;

0 commit comments

Comments
 (0)