Skip to content

Commit 4868c9f

Browse files
committed
Extract Taproot internal keyid with GetKeyFromDestination
1 parent d8abbe1 commit 4868c9f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/script/signingprovider.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ bool FillableSigningProvider::GetCScript(const CScriptID &hash, CScript& redeemS
190190

191191
CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination& dest)
192192
{
193-
// Only supports destinations which map to single public keys, i.e. P2PKH,
194-
// P2WPKH, and P2SH-P2WPKH.
193+
// Only supports destinations which map to single public keys:
194+
// P2PKH, P2WPKH, P2SH-P2WPKH, P2TR
195195
if (auto id = std::get_if<PKHash>(&dest)) {
196196
return ToKeyID(*id);
197197
}
@@ -208,5 +208,15 @@ CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination&
208208
}
209209
}
210210
}
211+
if (auto output_key = std::get_if<WitnessV1Taproot>(&dest)) {
212+
TaprootSpendData spenddata;
213+
CPubKey pub;
214+
if (store.GetTaprootSpendData(*output_key, spenddata)
215+
&& !spenddata.internal_key.IsNull()
216+
&& spenddata.merkle_root.IsNull()
217+
&& store.GetPubKeyByXOnly(spenddata.internal_key, pub)) {
218+
return pub.GetID();
219+
}
220+
}
211221
return CKeyID();
212222
}

0 commit comments

Comments
 (0)