Add CWallet::IsInternalScriptPubKeyMan

This commit is contained in:
S3RK committed 2021-10-06 08:23:53 +02:00
1 parent 456e350926
commit 03840c2064
3 files changed
+33 -5

No files matched your search

+4 -5
View File
@@ -1819,11 +1819,10 @@ RPCHelpMan listdescriptors()
} }
spk.pushKV("desc", descriptor); spk.pushKV("desc", descriptor);
spk.pushKV("timestamp", wallet_descriptor.creation_time); spk.pushKV("timestamp", wallet_descriptor.creation_time);
const bool active = active_spk_mans.count(desc_spk_man) != 0; spk.pushKV("active", active_spk_mans.count(desc_spk_man) != 0);
spk.pushKV("active", active); const auto internal = wallet->IsInternalScriptPubKeyMan(desc_spk_man);
const auto& type = wallet_descriptor.descriptor->GetOutputType(); if (internal.has_value()) {
if (active && type) { spk.pushKV("internal", *internal);
spk.pushKV("internal", wallet->GetScriptPubKeyMan(*type, true) == desc_spk_man);
} }
if (wallet_descriptor.descriptor->IsRange()) { if (wallet_descriptor.descriptor->IsRange()) {
UniValue range(UniValue::VARR); UniValue range(UniValue::VARR);
+24
View File
@@ -3265,6 +3265,30 @@ DescriptorScriptPubKeyMan* CWallet::GetDescriptorScriptPubKeyMan(const WalletDes
return nullptr; return nullptr;
} }
std::optional<bool> CWallet::IsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const
{
// Legacy script pubkey man can't be either external or internal
if (IsLegacy()) {
return std::nullopt;
}
// only active ScriptPubKeyMan can be internal
if (!GetActiveScriptPubKeyMans().count(spk_man)) {
return std::nullopt;
}
const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
if (!desc_spk_man) {
throw std::runtime_error(std::string(__func__) + ": unexpected ScriptPubKeyMan type.");
}
LOCK(desc_spk_man->cs_desc_man);
const auto& type = desc_spk_man->GetWalletDescriptor().descriptor->GetOutputType();
assert(type.has_value());
return GetScriptPubKeyMan(*type, /* internal= */ true) == desc_spk_man;
}
ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal)
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
+5
View File
@@ -875,6 +875,11 @@ public:
//! Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet //! Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet
DescriptorScriptPubKeyMan* GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const; DescriptorScriptPubKeyMan* GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const;
//! Returns whether the provided ScriptPubKeyMan is internal
//! @param[in] spk_man The ScriptPubKeyMan to test
//! @return contains value only for active DescriptorScriptPubKeyMan, otherwise undefined
std::optional<bool> IsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const;
//! Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type //! Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type
ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
}; };