MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetKeyForDestination

Function GetKeyForDestination

src/script/signingprovider.cpp:270–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268}
269
270CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination& dest)
271{
272 // Only supports destinations which map to single public keys:
273 // P2PKH, P2WPKH, P2SH-P2WPKH, P2TR
274 if (auto id = std::get_if<PKHash>(&dest)) {
275 return ToKeyID(*id);
276 }
277 if (auto witness_id = std::get_if<WitnessV0KeyHash>(&dest)) {
278 return ToKeyID(*witness_id);
279 }
280 if (auto script_hash = std::get_if<ScriptHash>(&dest)) {
281 CScript script;
282 CScriptID script_id = ToScriptID(*script_hash);
283 CTxDestination inner_dest;
284 if (store.GetCScript(script_id, script) && ExtractDestination(script, inner_dest)) {
285 if (auto inner_witness_id = std::get_if<WitnessV0KeyHash>(&inner_dest)) {
286 return ToKeyID(*inner_witness_id);
287 }
288 }
289 }
290 if (auto output_key = std::get_if<WitnessV1Taproot>(&dest)) {
291 TaprootSpendData spenddata;
292 CPubKey pub;
293 if (store.GetTaprootSpendData(*output_key, spenddata)
294 && !spenddata.internal_key.IsNull()
295 && spenddata.merkle_root.IsNull()
296 && store.GetPubKeyByXOnly(spenddata.internal_key, pub)) {
297 return pub.GetID();
298 }
299 }
300 return CKeyID();
301}
302
303void MultiSigningProvider::AddProvider(std::unique_ptr<SigningProvider> provider)
304{

Callers 3

GetMetadataMethod · 0.85
script.cppFile · 0.85
key.cppFile · 0.85

Calls 9

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

Tested by

no test coverage detected