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

Function AddAndGetDestinationForScript

src/outputtype.cpp:54–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, const CScript& script, OutputType type)
55{
56 // Add script to keystore
57 keystore.scripts.emplace(CScriptID(script), script);
58
59 switch (type) {
60 case OutputType::LEGACY:
61 return ScriptHash(script);
62 case OutputType::P2SH_SEGWIT:
63 case OutputType::BECH32: {
64 CTxDestination witdest = WitnessV0ScriptHash(script);
65 CScript witprog = GetScriptForDestination(witdest);
66 // Add the redeemscript, so that P2WSH and P2SH-P2WSH outputs are recognized as ours.
67 keystore.scripts.emplace(CScriptID(witprog), witprog);
68 if (type == OutputType::BECH32) {
69 return witdest;
70 } else {
71 return ScriptHash(witprog);
72 }
73 }
74 case OutputType::BECH32M:
75 case OutputType::UNKNOWN: {} // This function should not be used for BECH32M or UNKNOWN, so let it assert
76 } // no default case, so the compiler can warn about missing cases
77 assert(false);
78}
79
80std::optional<OutputType> OutputTypeFromDestination(const CTxDestination& dest) {
81 if (std::holds_alternative<PKHash>(dest) ||

Callers 1

Calls 5

CScriptIDClass · 0.85
ScriptHashClass · 0.85
WitnessV0ScriptHashClass · 0.85
GetScriptForDestinationFunction · 0.85
emplaceMethod · 0.80

Tested by

no test coverage detected