@@ -3443,20 +3443,8 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
3443
3443
internal = true ;
3444
3444
}
3445
3445
3446
- assert (m_max_keypool_index < std::numeric_limits<int64_t >::max ()); // How in the hell did you use so many keys?
3447
- int64_t index = ++m_max_keypool_index;
3448
-
3449
3446
CPubKey pubkey (GenerateNewKey (batch, internal));
3450
- if (!batch.WritePool (index, CKeyPool (pubkey, internal))) {
3451
- throw std::runtime_error (std::string (__func__) + " : writing generated key failed" );
3452
- }
3453
-
3454
- if (internal) {
3455
- setInternalKeyPool.insert (index);
3456
- } else {
3457
- setExternalKeyPool.insert (index);
3458
- }
3459
- m_pool_key_to_index[pubkey.GetID ()] = index;
3447
+ AddKeypoolPubkeyWithDB (pubkey, internal, batch);
3460
3448
}
3461
3449
if (missingInternal + missingExternal > 0 ) {
3462
3450
WalletLogPrintf (" keypool added %d keys (%d internal), size=%u (%u internal)\n " , missingInternal + missingExternal, missingInternal, setInternalKeyPool.size () + setExternalKeyPool.size () + set_pre_split_keypool.size (), setInternalKeyPool.size ());
@@ -3466,6 +3454,29 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
3466
3454
return true ;
3467
3455
}
3468
3456
3457
+ void CWallet::AddKeypoolPubkey (const CPubKey& pubkey, const bool internal)
3458
+ {
3459
+ WalletBatch batch (*database);
3460
+ AddKeypoolPubkeyWithDB (pubkey, internal, batch);
3461
+ NotifyCanGetAddressesChanged ();
3462
+ }
3463
+
3464
+ void CWallet::AddKeypoolPubkeyWithDB (const CPubKey& pubkey, const bool internal, WalletBatch& batch)
3465
+ {
3466
+ LOCK (cs_wallet);
3467
+ assert (m_max_keypool_index < std::numeric_limits<int64_t >::max ()); // How in the hell did you use so many keys?
3468
+ int64_t index = ++m_max_keypool_index;
3469
+ if (!batch.WritePool (index, CKeyPool (pubkey, internal))) {
3470
+ throw std::runtime_error (std::string (__func__) + " : writing imported pubkey failed" );
3471
+ }
3472
+ if (internal) {
3473
+ setInternalKeyPool.insert (index);
3474
+ } else {
3475
+ setExternalKeyPool.insert (index);
3476
+ }
3477
+ m_pool_key_to_index[pubkey.GetID ()] = index;
3478
+ }
3479
+
3469
3480
bool CWallet::ReserveKeyFromKeyPool (int64_t & nIndex, CKeyPool& keypool, bool fRequestedInternal )
3470
3481
{
3471
3482
nIndex = -1 ;
0 commit comments