| 81 | } |
| 82 | |
| 83 | CTxDestination 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 | |
| 110 | std::optional<OutputType> OutputTypeFromDestination(const CTxDestination& dest) { |
| 111 | if (std::holds_alternative<PKHash>(dest) || |
no test coverage detected