Skip to content

Commit 092569e

Browse files
committed
descriptor: Try the other parity in ConstPubkeyProvider::GetPrivKey()
GetPrivKey() needs the same handling of all keyids for xonly keys that ToPrivateString() does. Refactor that into GetPrivKey() and reuse it in ToPrivateString() to resolve this.
1 parent 228aba2 commit 092569e

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/script/descriptor.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,7 @@ class ConstPubkeyProvider final : public PubkeyProvider
312312
bool ToPrivateString(const SigningProvider& arg, std::string& ret) const override
313313
{
314314
CKey key;
315-
if (m_xonly) {
316-
for (const auto& keyid : XOnlyPubKey(m_pubkey).GetKeyIDs()) {
317-
arg.GetKey(keyid, key);
318-
if (key.IsValid()) break;
319-
}
320-
} else {
321-
arg.GetKey(m_pubkey.GetID(), key);
322-
}
323-
if (!key.IsValid()) return false;
315+
if (!GetPrivKey(/*pos=*/0, arg, key)) return false;
324316
ret = EncodeSecret(key);
325317
return true;
326318
}
@@ -331,7 +323,8 @@ class ConstPubkeyProvider final : public PubkeyProvider
331323
}
332324
bool GetPrivKey(int pos, const SigningProvider& arg, CKey& key) const override
333325
{
334-
return arg.GetKey(m_pubkey.GetID(), key);
326+
return m_xonly ? arg.GetKeyByXOnly(XOnlyPubKey(m_pubkey), key) :
327+
arg.GetKey(m_pubkey.GetID(), key);
335328
}
336329
std::optional<CPubKey> GetRootPubKey() const override
337330
{

0 commit comments

Comments
 (0)