Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ext keys #3

Merged
merged 7 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/wallet/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2876,7 +2876,7 @@ util::Result<CTxDestination> SilentPaymentDescriptorScriptPubKeyMan::GetNewDesti
return dest;
}

CTxDestination SilentPaymentDescriptorScriptPubKeyMan::GetLabelledDestination(uint64_t index)
V0SilentPaymentDestination SilentPaymentDescriptorScriptPubKeyMan::GetLabelledDestination(uint64_t index)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in 817e931:

why the change to V0SilentPaymentDestination? Seems like this was fine as a CTxDestination?

Copy link
Author

@Eunovo Eunovo Aug 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reversed the change locally and it compiles successfully. I'm not sure why I changed it initially.

{
AssertLockHeld(cs_desc_man);

Expand All @@ -2892,18 +2892,17 @@ CTxDestination SilentPaymentDescriptorScriptPubKeyMan::GetLabelledDestination(ui
auto label_data = BIP352::CreateLabelTweak(sppubkey->scanKey, index);
m_map_label_tweaks.insert(label_data);
V0SilentPaymentDestination label_dest = BIP352::GenerateSilentPaymentLabelledAddress(main_dest, label_data.second);
CTxDestination dest{label_dest};
return dest;
return label_dest;
}

util::Result<CTxDestination> SilentPaymentDescriptorScriptPubKeyMan::GetNewLabelledDestination(uint64_t& index)
{
LOCK(cs_desc_man);
CTxDestination dest = GetLabelledDestination(m_wallet_descriptor.next_index);
auto dest = GetLabelledDestination(m_wallet_descriptor.next_index);
index = m_wallet_descriptor.next_index; // Return the index for this destination
m_wallet_descriptor.next_index++;
WalletBatch(m_storage.GetDatabase()).WriteDescriptor(GetID(), m_wallet_descriptor);
return dest;
return CTxDestination{dest};
}

isminetype SilentPaymentDescriptorScriptPubKeyMan::IsMine(const CScript& script) const
Expand Down Expand Up @@ -2950,7 +2949,7 @@ util::Result<CTxDestination> SilentPaymentDescriptorScriptPubKeyMan::GetReserved
LOCK(cs_desc_man);
// Destination at index 0 is the change destination
auto op_dest = GetLabelledDestination(0);
return op_dest;
return CTxDestination{op_dest};
}

bool SilentPaymentDescriptorScriptPubKeyMan::TopUp(const uint256& tweak)
Expand Down Expand Up @@ -3025,4 +3024,14 @@ void SilentPaymentDescriptorScriptPubKeyMan::AddTweak(const uint256& tweak)
m_map_spk_tweaks.emplace(spk, tweak);
}

std::vector<WalletDestination> SilentPaymentDescriptorScriptPubKeyMan::MarkUnusedAddresses(const CScript& script)
{
// The wallet normally maintains a cache of unused destinations/addresses
// MarkUnusedAddresses is supposed to return the destinations for the given scriptPubKey
// so the wallet can mark these destinations as used in it's AddresBook
// This concept does not apply Silent Payments as there is no cache of unused destinations/addresses
// Still, we must subclass this because the original method tries to expand the descriptor which will result in an error for SP descriptors
return {};
}

} // namespace wallet
4 changes: 3 additions & 1 deletion src/wallet/scriptpubkeyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ class SilentPaymentDescriptorScriptPubKeyMan : public DescriptorScriptPubKeyMan

util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
util::Result<CTxDestination> GetNewLabelledDestination(uint64_t& index);
CTxDestination GetLabelledDestination(uint64_t index) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
V0SilentPaymentDestination GetLabelledDestination(uint64_t index) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
util::Result<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) override;
bool CanGetAddresses(bool internal) const override { return true; }

Expand All @@ -744,6 +744,8 @@ class SilentPaymentDescriptorScriptPubKeyMan : public DescriptorScriptPubKeyMan

//! Add tweak into m_map_spk_tweaks without saving to DB
void AddTweak(const uint256& tweak);

std::vector<WalletDestination> MarkUnusedAddresses(const CScript& script) override;
};

/** struct containing information needed for migrating legacy wallets to descriptor wallets */
Expand Down