Skip to content

Commit

Permalink
Implement several simple functions in DescriptorScriptPubKeyMan
Browse files Browse the repository at this point in the history
Implements a bunch of one liners: UpgradeKeyMetadata, IsFirstRun, HavePrivateKeys,
KeypoolCountExternalKeys, GetKeypoolSize, GetTimeFirstKey, CanGetAddresses,
RewriteDB
  • Loading branch information
achow101 committed Apr 23, 2020
1 parent d1ec3e4 commit 4cb9b69
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/wallet/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,12 +1561,18 @@ bool DescriptorScriptPubKeyMan::IsHDEnabled() const

bool DescriptorScriptPubKeyMan::CanGetAddresses(bool internal) const
{
return false;
// We can only give out addresses from descriptors that are single type (not combo), ranged,
// and either have cached keys or can generate more keys (ignoring encryption)
LOCK(cs_desc_man);
return m_wallet_descriptor.descriptor->IsSingleType() &&
m_wallet_descriptor.descriptor->IsRange() &&
(HavePrivateKeys() || m_wallet_descriptor.next_index < m_wallet_descriptor.range_end);
}

bool DescriptorScriptPubKeyMan::HavePrivateKeys() const
{
return false;
LOCK(cs_desc_man);
return m_map_keys.size() > 0 || m_map_crypted_keys.size() > 0;
}

int64_t DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() const
Expand All @@ -1576,17 +1582,22 @@ int64_t DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() const

size_t DescriptorScriptPubKeyMan::KeypoolCountExternalKeys() const
{
return 0;
if (m_internal) {
return 0;
}
return GetKeyPoolSize();
}

unsigned int DescriptorScriptPubKeyMan::GetKeyPoolSize() const
{
return 0;
LOCK(cs_desc_man);
return m_wallet_descriptor.range_end - m_wallet_descriptor.next_index;
}

int64_t DescriptorScriptPubKeyMan::GetTimeFirstKey() const
{
return 0;
LOCK(cs_desc_man);
return m_wallet_descriptor.creation_time;
}

std::unique_ptr<SigningProvider> DescriptorScriptPubKeyMan::GetSolvingProvider(const CScript& script) const
Expand Down

0 comments on commit 4cb9b69

Please sign in to comment.