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

Function AddAndGetDestinationForScript

src/outputtype.cpp:83–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore, const CScript& script, OutputType type)
84{
85 // Add script to keystore
86 keystore.AddCScript(script);
87 // Note that scripts over 520 bytes are not yet supported.
88 switch (type) {
89 case OutputType::LEGACY:
90 return ScriptHash(script);
91 case OutputType::P2SH_SEGWIT:
92 case OutputType::BECH32: {
93 CTxDestination witdest = WitnessV0ScriptHash(script);
94 CScript witprog = GetScriptForDestination(witdest);
95 // Check if the resulting program is solvable (i.e. doesn't use an uncompressed key)
96 if (!IsSolvable(keystore, witprog)) return ScriptHash(script);
97 // Add the redeemscript, so that P2WSH and P2SH-P2WSH outputs are recognized as ours.
98 keystore.AddCScript(witprog);
99 if (type == OutputType::BECH32) {
100 return witdest;
101 } else {
102 return ScriptHash(witprog);
103 }
104 }
105 case OutputType::BECH32M: {} // This function should not be used for BECH32M, so let it assert
106 } // no default case, so the compiler can warn about missing cases
107 assert(false);
108}
109
110std::optional<OutputType> OutputTypeFromDestination(const CTxDestination& dest) {
111 if (std::holds_alternative<PKHash>(dest) ||

Callers 1

Calls 5

ScriptHashClass · 0.85
WitnessV0ScriptHashClass · 0.85
GetScriptForDestinationFunction · 0.85
IsSolvableFunction · 0.85
AddCScriptMethod · 0.45

Tested by

no test coverage detected