MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetKeyForDestination

Function GetKeyForDestination

src/script/signingprovider.cpp:191–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination& dest)
192{
193 // Only supports destinations which map to single public keys:
194 // P2PKH, P2WPKH, P2SH-P2WPKH, P2TR
195 if (auto id = std::get_if<PKHash>(&dest)) {
196 return ToKeyID(*id);
197 }
198 if (auto witness_id = std::get_if<WitnessV0KeyHash>(&dest)) {
199 return ToKeyID(*witness_id);
200 }
201 if (auto script_hash = std::get_if<ScriptHash>(&dest)) {
202 CScript script;
203 CScriptID script_id(*script_hash);
204 CTxDestination inner_dest;
205 if (store.GetCScript(script_id, script) && ExtractDestination(script, inner_dest)) {
206 if (auto inner_witness_id = std::get_if<WitnessV0KeyHash>(&inner_dest)) {
207 return ToKeyID(*inner_witness_id);
208 }
209 }
210 }
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 }
221 return CKeyID();
222}

Callers 5

GetMetadataMethod · 0.85
dumpprivkeyFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
AddrToPubKeyFunction · 0.85

Calls 8

ToKeyIDFunction · 0.85
ExtractDestinationFunction · 0.85
GetPubKeyByXOnlyMethod · 0.80
CKeyIDClass · 0.70
GetCScriptMethod · 0.45
GetTaprootSpendDataMethod · 0.45
IsNullMethod · 0.45
GetIDMethod · 0.45

Tested by 2

FUZZ_TARGET_INITFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68