@@ -87,7 +87,7 @@ const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const
87
87
return &(it->second );
88
88
}
89
89
90
- CPubKey CWallet::GenerateNewKey (bool internal)
90
+ CPubKey CWallet::GenerateNewKey (CWalletDB &walletdb, bool internal)
91
91
{
92
92
AssertLockHeld (cs_wallet); // mapKeyMetadata
93
93
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)
100
100
101
101
// use HD key derivation if HD was enabled during wallet creation
102
102
if (IsHDEnabled ()) {
103
- DeriveNewChildKey (metadata, secret, (CanSupportFeature (FEATURE_HD_SPLIT) ? internal : false ));
103
+ DeriveNewChildKey (walletdb, metadata, secret, (CanSupportFeature (FEATURE_HD_SPLIT) ? internal : false ));
104
104
} else {
105
105
secret.MakeNewKey (fCompressed );
106
106
}
@@ -120,7 +120,7 @@ CPubKey CWallet::GenerateNewKey(bool internal)
120
120
return pubkey;
121
121
}
122
122
123
- void CWallet::DeriveNewChildKey (CKeyMetadata& metadata, CKey& secret, bool internal)
123
+ void CWallet::DeriveNewChildKey (CWalletDB &walletdb, CKeyMetadata& metadata, CKey& secret, bool internal)
124
124
{
125
125
// for now we use a fixed keypath scheme of m/0'/0'/k
126
126
CKey key; // master key seed (256bit)
@@ -162,7 +162,7 @@ void CWallet::DeriveNewChildKey(CKeyMetadata& metadata, CKey& secret, bool inter
162
162
secret = childKey.key ;
163
163
metadata.hdMasterKeyID = hdChain.masterKeyID ;
164
164
// update the chain model in the database
165
- if (!CWalletDB (*dbw) .WriteHDChain (hdChain))
165
+ if (!walletdb .WriteHDChain (hdChain))
166
166
throw std::runtime_error (std::string (__func__) + " : Writing HD chain model failed" );
167
167
}
168
168
@@ -3183,8 +3183,9 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
3183
3183
nEnd = std::max (nEnd, *(setExternalKeyPool.rbegin ()) + 1 );
3184
3184
}
3185
3185
3186
- if (!walletdb.WritePool (nEnd, CKeyPool (GenerateNewKey (internal), internal)))
3186
+ if (!walletdb.WritePool (nEnd, CKeyPool (GenerateNewKey (walletdb, internal), internal))) {
3187
3187
throw std::runtime_error (std::string (__func__) + " : writing generated key failed" );
3188
+ }
3188
3189
3189
3190
if (internal) {
3190
3191
setInternalKeyPool.insert (nEnd);
@@ -3266,7 +3267,8 @@ bool CWallet::GetKeyFromPool(CPubKey& result, bool internal)
3266
3267
if (nIndex == -1 )
3267
3268
{
3268
3269
if (IsLocked ()) return false ;
3269
- result = GenerateNewKey (internal);
3270
+ CWalletDB walletdb (*dbw);
3271
+ result = GenerateNewKey (walletdb, internal);
3270
3272
return true ;
3271
3273
}
3272
3274
KeepKey (nIndex);
0 commit comments