| 74 | } |
| 75 | |
| 76 | CTxDestination AddAndGetDestinationForScript(CKeyStore& keystore, const CScript& script, OutputType type) |
| 77 | { |
| 78 | // Add script to keystore |
| 79 | keystore.AddCScript(script); |
| 80 | // Note that scripts over 520 bytes are not yet supported. |
| 81 | switch (type) { |
| 82 | case OutputType::LEGACY: |
| 83 | return CScriptID(script); |
| 84 | case OutputType::P2SH_SEGWIT: |
| 85 | case OutputType::BECH32: { |
| 86 | CTxDestination witdest = WitnessV0ScriptHash(script); |
| 87 | CScript witprog = GetScriptForDestination(witdest); |
| 88 | // Check if the resulting program is solvable (i.e. doesn't use an uncompressed key) |
| 89 | if (!IsSolvable(keystore, witprog)) return CScriptID(script); |
| 90 | // Add the redeemscript, so that P2WSH and P2SH-P2WSH outputs are recognized as ours. |
| 91 | keystore.AddCScript(witprog); |
| 92 | if (type == OutputType::BECH32) { |
| 93 | return witdest; |
| 94 | } else { |
| 95 | return CScriptID(witprog); |
| 96 | } |
| 97 | } |
| 98 | default: assert(false); |
| 99 | } |
| 100 | } |
| 101 |
no test coverage detected