Skip to content

Commit 4cb9b69

Browse files
committed
Implement several simple functions in DescriptorScriptPubKeyMan
Implements a bunch of one liners: UpgradeKeyMetadata, IsFirstRun, HavePrivateKeys, KeypoolCountExternalKeys, GetKeypoolSize, GetTimeFirstKey, CanGetAddresses, RewriteDB
1 parent d1ec3e4 commit 4cb9b69

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,12 +1561,18 @@ bool DescriptorScriptPubKeyMan::IsHDEnabled() const
15611561

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

15671572
bool DescriptorScriptPubKeyMan::HavePrivateKeys() const
15681573
{
1569-
return false;
1574+
LOCK(cs_desc_man);
1575+
return m_map_keys.size() > 0 || m_map_crypted_keys.size() > 0;
15701576
}
15711577

15721578
int64_t DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() const
@@ -1576,17 +1582,22 @@ int64_t DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() const
15761582

15771583
size_t DescriptorScriptPubKeyMan::KeypoolCountExternalKeys() const
15781584
{
1579-
return 0;
1585+
if (m_internal) {
1586+
return 0;
1587+
}
1588+
return GetKeyPoolSize();
15801589
}
15811590

15821591
unsigned int DescriptorScriptPubKeyMan::GetKeyPoolSize() const
15831592
{
1584-
return 0;
1593+
LOCK(cs_desc_man);
1594+
return m_wallet_descriptor.range_end - m_wallet_descriptor.next_index;
15851595
}
15861596

15871597
int64_t DescriptorScriptPubKeyMan::GetTimeFirstKey() const
15881598
{
1589-
return 0;
1599+
LOCK(cs_desc_man);
1600+
return m_wallet_descriptor.creation_time;
15901601
}
15911602

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

0 commit comments

Comments
 (0)