| 52 | } |
| 53 | |
| 54 | CTxDestination 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 | |
| 80 | std::optional<OutputType> OutputTypeFromDestination(const CTxDestination& dest) { |
| 81 | if (std::holds_alternative<PKHash>(dest) || |
no test coverage detected