Refactor: Add new ScriptPubKeyMan virtual methods

This commit does not change behavior.
This commit is contained in:
Andrew Chow committed 2019-11-01 22:56:37 -04:00
1 parent 533d8b364f
commit acedc5b823
3 files changed
+47 -11

No files matched your search

+25
View File
@@ -265,6 +265,31 @@ bool LegacyScriptPubKeyMan::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
return true; return true;
} }
bool LegacyScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool)
{
{
if (!ReserveKeyFromKeyPool(index, keypool, internal)) {
return false;
}
}
return true;
}
void LegacyScriptPubKeyMan::KeepDestination(int64_t index)
{
KeepKey(index);
}
void LegacyScriptPubKeyMan::ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey)
{
ReturnKey(index, internal, pubkey);
}
bool LegacyScriptPubKeyMan::TopUp(unsigned int size)
{
return TopUpKeyPool(size);
}
void LegacyScriptPubKeyMan::UpgradeKeyMetadata() void LegacyScriptPubKeyMan::UpgradeKeyMetadata()
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
+14 -3
View File
@@ -148,8 +148,11 @@ public:
virtual ~ScriptPubKeyMan() {}; virtual ~ScriptPubKeyMan() {};
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; } virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }
//! Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo virtual bool GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) { return false; }
virtual void UpgradeKeyMetadata() {} virtual void KeepDestination(int64_t index) {}
virtual void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) {}
virtual bool TopUp(unsigned int size = 0) { return false; }
/* Returns true if HD is enabled */ /* Returns true if HD is enabled */
virtual bool IsHDEnabled() const { return false; } virtual bool IsHDEnabled() const { return false; }
@@ -247,7 +250,15 @@ public:
//! will encrypt previously unencrypted keys //! will encrypt previously unencrypted keys
bool EncryptKeys(CKeyingMaterial& vMasterKeyIn); bool EncryptKeys(CKeyingMaterial& vMasterKeyIn);
void UpgradeKeyMetadata() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override;
void KeepDestination(int64_t index) override;
void ReturnDestination(int64_t index, bool internal, const CPubKey& pubkey) override;
bool TopUp(unsigned int size = 0) override;
//! Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo
void UpgradeKeyMetadata() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool IsHDEnabled() const override; bool IsHDEnabled() const override;
+8 -8
View File
@@ -878,7 +878,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, CWalletTx::St
WalletLogPrintf("%s: Detected a used keypool key, mark all keypool key up to this key as used\n", __func__); WalletLogPrintf("%s: Detected a used keypool key, mark all keypool key up to this key as used\n", __func__);
MarkReserveKeysAsUsed(mi->second); MarkReserveKeysAsUsed(mi->second);
if (!m_spk_man->TopUpKeyPool()) { if (!m_spk_man->TopUp()) {
WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", __func__); WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", __func__);
} }
} }
@@ -3027,7 +3027,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
{ {
bool res = true; bool res = true;
if (auto spk_man = m_spk_man.get()) { if (auto spk_man = m_spk_man.get()) {
res &= spk_man->TopUpKeyPool(kpSize); res &= spk_man->TopUp(kpSize);
} }
return res; return res;
} }
@@ -3047,7 +3047,7 @@ bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& des
{ {
error.clear(); error.clear();
m_spk_man->TopUpKeyPool(); m_spk_man->TopUp();
ReserveDestination reservedest(this); ReserveDestination reservedest(this);
if (!reservedest.GetReservedDestination(type, dest, true)) { if (!reservedest.GetReservedDestination(type, dest, true)) {
@@ -3229,7 +3229,7 @@ bool ReserveDestination::GetReservedDestination(const OutputType type, CTxDestin
if (nIndex == -1) if (nIndex == -1)
{ {
CKeyPool keypool; CKeyPool keypool;
if (!m_spk_man->ReserveKeyFromKeyPool(nIndex, keypool, internal)) { if (!m_spk_man->GetReservedDestination(type, internal, nIndex, keypool)) {
return false; return false;
} }
vchPubKey = keypool.vchPubKey; vchPubKey = keypool.vchPubKey;
@@ -3245,7 +3245,7 @@ bool ReserveDestination::GetReservedDestination(const OutputType type, CTxDestin
void ReserveDestination::KeepDestination() void ReserveDestination::KeepDestination()
{ {
if (nIndex != -1) if (nIndex != -1)
m_spk_man->KeepKey(nIndex); m_spk_man->KeepDestination(nIndex);
nIndex = -1; nIndex = -1;
vchPubKey = CPubKey(); vchPubKey = CPubKey();
address = CNoDestination(); address = CNoDestination();
@@ -3254,7 +3254,7 @@ void ReserveDestination::KeepDestination()
void ReserveDestination::ReturnDestination() void ReserveDestination::ReturnDestination()
{ {
if (nIndex != -1) { if (nIndex != -1) {
m_spk_man->ReturnKey(nIndex, fInternal, vchPubKey); m_spk_man->ReturnDestination(nIndex, fInternal, vchPubKey);
} }
nIndex = -1; nIndex = -1;
vchPubKey = CPubKey(); vchPubKey = CPubKey();
@@ -3623,7 +3623,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
} }
// Regenerate the keypool if upgraded to HD // Regenerate the keypool if upgraded to HD
if (hd_upgrade) { if (hd_upgrade) {
if (!walletInstance->m_spk_man->TopUpKeyPool()) { if (!walletInstance->m_spk_man->TopUp()) {
error = _("Unable to generate keys").translated; error = _("Unable to generate keys").translated;
return nullptr; return nullptr;
} }
@@ -3643,7 +3643,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
} }
// Top up the keypool // Top up the keypool
if (walletInstance->m_spk_man->CanGenerateKeys() && !walletInstance->m_spk_man->TopUpKeyPool()) { if (walletInstance->m_spk_man->CanGenerateKeys() && !walletInstance->m_spk_man->TopUp()) {
error = _("Unable to generate initial keys").translated; error = _("Unable to generate initial keys").translated;
return nullptr; return nullptr;
} }