@@ -357,7 +357,7 @@ bool LegacyScriptPubKeyMan::SetupGeneration(bool force)
357
357
358
358
bool LegacyScriptPubKeyMan::IsHDEnabled () const
359
359
{
360
- return !hdChain .seed_id .IsNull ();
360
+ return !m_hd_chain .seed_id .IsNull ();
361
361
}
362
362
363
363
bool LegacyScriptPubKeyMan::CanGetAddresses (bool internal) const
@@ -842,7 +842,7 @@ void LegacyScriptPubKeyMan::SetHDChain(const CHDChain& chain, bool memonly)
842
842
if (!memonly && !WalletBatch (m_storage.GetDatabase ()).WriteHDChain (chain))
843
843
throw std::runtime_error (std::string (__func__) + " : writing chain failed" );
844
844
845
- hdChain = chain;
845
+ m_hd_chain = chain;
846
846
}
847
847
848
848
bool LegacyScriptPubKeyMan::HaveKey (const CKeyID &address) const
@@ -921,7 +921,7 @@ bool LegacyScriptPubKeyMan::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyO
921
921
return GetWatchPubKey (address, vchPubKeyOut);
922
922
}
923
923
924
- CPubKey LegacyScriptPubKeyMan::GenerateNewKey (WalletBatch &batch, bool internal)
924
+ CPubKey LegacyScriptPubKeyMan::GenerateNewKey (WalletBatch &batch, CHDChain& hd_chain, bool internal)
925
925
{
926
926
assert (!m_storage.IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS));
927
927
assert (!m_storage.IsWalletFlagSet (WALLET_FLAG_BLANK_WALLET));
@@ -936,7 +936,7 @@ CPubKey LegacyScriptPubKeyMan::GenerateNewKey(WalletBatch &batch, bool internal)
936
936
937
937
// use HD key derivation if HD was enabled during wallet creation and a seed is present
938
938
if (IsHDEnabled ()) {
939
- DeriveNewChildKey (batch, metadata, secret, (m_storage.CanSupportFeature (FEATURE_HD_SPLIT) ? internal : false ));
939
+ DeriveNewChildKey (batch, metadata, secret, hd_chain, (m_storage.CanSupportFeature (FEATURE_HD_SPLIT) ? internal : false ));
940
940
} else {
941
941
secret.MakeNewKey (fCompressed );
942
942
}
@@ -960,7 +960,7 @@ CPubKey LegacyScriptPubKeyMan::GenerateNewKey(WalletBatch &batch, bool internal)
960
960
961
961
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000 ;
962
962
963
- void LegacyScriptPubKeyMan::DeriveNewChildKey (WalletBatch &batch, CKeyMetadata& metadata, CKey& secret, bool internal)
963
+ void LegacyScriptPubKeyMan::DeriveNewChildKey (WalletBatch &batch, CKeyMetadata& metadata, CKey& secret, CHDChain& hd_chain, bool internal)
964
964
{
965
965
// for now we use a fixed keypath scheme of m/0'/0'/k
966
966
CKey seed; // seed (256bit)
@@ -970,7 +970,7 @@ void LegacyScriptPubKeyMan::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata&
970
970
CExtKey childKey; // key at m/0'/0'/<n>'
971
971
972
972
// try to get the seed
973
- if (!GetKey (hdChain .seed_id , seed))
973
+ if (!GetKey (hd_chain .seed_id , seed))
974
974
throw std::runtime_error (std::string (__func__) + " : seed not found" );
975
975
976
976
masterKey.SetSeed (seed.begin (), seed.size ());
@@ -989,29 +989,29 @@ void LegacyScriptPubKeyMan::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata&
989
989
// childIndex | BIP32_HARDENED_KEY_LIMIT = derive childIndex in hardened child-index-range
990
990
// example: 1 | BIP32_HARDENED_KEY_LIMIT == 0x80000001 == 2147483649
991
991
if (internal) {
992
- chainChildKey.Derive (childKey, hdChain .nInternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
993
- metadata.hdKeypath = " m/0'/1'/" + ToString (hdChain .nInternalChainCounter ) + " '" ;
992
+ chainChildKey.Derive (childKey, hd_chain .nInternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
993
+ metadata.hdKeypath = " m/0'/1'/" + ToString (hd_chain .nInternalChainCounter ) + " '" ;
994
994
metadata.key_origin .path .push_back (0 | BIP32_HARDENED_KEY_LIMIT);
995
995
metadata.key_origin .path .push_back (1 | BIP32_HARDENED_KEY_LIMIT);
996
- metadata.key_origin .path .push_back (hdChain .nInternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
997
- hdChain .nInternalChainCounter ++;
996
+ metadata.key_origin .path .push_back (hd_chain .nInternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
997
+ hd_chain .nInternalChainCounter ++;
998
998
}
999
999
else {
1000
- chainChildKey.Derive (childKey, hdChain .nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
1001
- metadata.hdKeypath = " m/0'/0'/" + ToString (hdChain .nExternalChainCounter ) + " '" ;
1000
+ chainChildKey.Derive (childKey, hd_chain .nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
1001
+ metadata.hdKeypath = " m/0'/0'/" + ToString (hd_chain .nExternalChainCounter ) + " '" ;
1002
1002
metadata.key_origin .path .push_back (0 | BIP32_HARDENED_KEY_LIMIT);
1003
1003
metadata.key_origin .path .push_back (0 | BIP32_HARDENED_KEY_LIMIT);
1004
- metadata.key_origin .path .push_back (hdChain .nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
1005
- hdChain .nExternalChainCounter ++;
1004
+ metadata.key_origin .path .push_back (hd_chain .nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
1005
+ hd_chain .nExternalChainCounter ++;
1006
1006
}
1007
1007
} while (HaveKey (childKey.key .GetPubKey ().GetID ()));
1008
1008
secret = childKey.key ;
1009
- metadata.hd_seed_id = hdChain .seed_id ;
1009
+ metadata.hd_seed_id = hd_chain .seed_id ;
1010
1010
CKeyID master_id = masterKey.key .GetPubKey ().GetID ();
1011
1011
std::copy (master_id.begin (), master_id.begin () + 4 , metadata.key_origin .fingerprint );
1012
1012
metadata.has_key_origin = true ;
1013
1013
// update the chain model in the database
1014
- if (!batch.WriteHDChain (hdChain ))
1014
+ if (!batch.WriteHDChain (hd_chain ))
1015
1015
throw std::runtime_error (std::string (__func__) + " : Writing HD chain model failed" );
1016
1016
}
1017
1017
@@ -1167,7 +1167,7 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int kpSize)
1167
1167
internal = true ;
1168
1168
}
1169
1169
1170
- CPubKey pubkey (GenerateNewKey (batch, internal));
1170
+ CPubKey pubkey (GenerateNewKey (batch, m_hd_chain, internal));
1171
1171
AddKeypoolPubkeyWithDB (pubkey, internal, batch);
1172
1172
}
1173
1173
if (missingInternal + missingExternal > 0 ) {
@@ -1240,7 +1240,7 @@ bool LegacyScriptPubKeyMan::GetKeyFromPool(CPubKey& result, const OutputType typ
1240
1240
if (!ReserveKeyFromKeyPool (nIndex, keypool, internal) && !m_storage.IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
1241
1241
if (m_storage.IsLocked ()) return false ;
1242
1242
WalletBatch batch (m_storage.GetDatabase ());
1243
- result = GenerateNewKey (batch, internal);
1243
+ result = GenerateNewKey (batch, m_hd_chain, internal);
1244
1244
return true ;
1245
1245
}
1246
1246
KeepDestination (nIndex, type);
0 commit comments