@@ -87,7 +87,7 @@ const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const
8787 return &(it->second );
8888}
8989
90- CPubKey CWallet::GenerateNewKey (bool internal)
90+ CPubKey CWallet::GenerateNewKey (CWalletDB &walletdb, bool internal)
9191{
9292 AssertLockHeld (cs_wallet); // mapKeyMetadata
9393 bool fCompressed = CanSupportFeature (FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets
@@ -100,7 +100,7 @@ CPubKey CWallet::GenerateNewKey(bool internal)
100100
101101 // use HD key derivation if HD was enabled during wallet creation
102102 if (IsHDEnabled ()) {
103- DeriveNewChildKey (metadata, secret, (CanSupportFeature (FEATURE_HD_SPLIT) ? internal : false ));
103+ DeriveNewChildKey (walletdb, metadata, secret, (CanSupportFeature (FEATURE_HD_SPLIT) ? internal : false ));
104104 } else {
105105 secret.MakeNewKey (fCompressed );
106106 }
@@ -120,7 +120,7 @@ CPubKey CWallet::GenerateNewKey(bool internal)
120120 return pubkey;
121121}
122122
123- void CWallet::DeriveNewChildKey (CKeyMetadata& metadata, CKey& secret, bool internal)
123+ void CWallet::DeriveNewChildKey (CWalletDB &walletdb, CKeyMetadata& metadata, CKey& secret, bool internal)
124124{
125125 // for now we use a fixed keypath scheme of m/0'/0'/k
126126 CKey key; // master key seed (256bit)
@@ -162,7 +162,7 @@ void CWallet::DeriveNewChildKey(CKeyMetadata& metadata, CKey& secret, bool inter
162162 secret = childKey.key ;
163163 metadata.hdMasterKeyID = hdChain.masterKeyID ;
164164 // update the chain model in the database
165- if (!CWalletDB (*dbw) .WriteHDChain (hdChain))
165+ if (!walletdb .WriteHDChain (hdChain))
166166 throw std::runtime_error (std::string (__func__) + " : Writing HD chain model failed" );
167167}
168168
@@ -3183,8 +3183,9 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
31833183 nEnd = std::max (nEnd, *(setExternalKeyPool.rbegin ()) + 1 );
31843184 }
31853185
3186- if (!walletdb.WritePool (nEnd, CKeyPool (GenerateNewKey (internal), internal)))
3186+ if (!walletdb.WritePool (nEnd, CKeyPool (GenerateNewKey (walletdb, internal), internal))) {
31873187 throw std::runtime_error (std::string (__func__) + " : writing generated key failed" );
3188+ }
31883189
31893190 if (internal) {
31903191 setInternalKeyPool.insert (nEnd);
@@ -3266,7 +3267,8 @@ bool CWallet::GetKeyFromPool(CPubKey& result, bool internal)
32663267 if (nIndex == -1 )
32673268 {
32683269 if (IsLocked ()) return false ;
3269- result = GenerateNewKey (internal);
3270+ CWalletDB walletdb (*dbw);
3271+ result = GenerateNewKey (walletdb, internal);
32703272 return true ;
32713273 }
32723274 KeepKey (nIndex);
0 commit comments