| 47 | } |
| 48 | |
| 49 | bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet) |
| 50 | { |
| 51 | std::vector<valtype> vSolutions; |
| 52 | TxoutType whichType = Solver(scriptPubKey, vSolutions); |
| 53 | |
| 54 | switch (whichType) { |
| 55 | case TxoutType::PUBKEY: { |
| 56 | CPubKey pubKey(vSolutions[0]); |
| 57 | if (!pubKey.IsValid()) { |
| 58 | addressRet = CNoDestination(scriptPubKey); |
| 59 | } else { |
| 60 | addressRet = PubKeyDestination(pubKey); |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | case TxoutType::PUBKEYHASH: { |
| 65 | addressRet = PKHash(uint160(vSolutions[0])); |
| 66 | return true; |
| 67 | } |
| 68 | case TxoutType::SCRIPTHASH: { |
| 69 | addressRet = ScriptHash(uint160(vSolutions[0])); |
| 70 | return true; |
| 71 | } |
| 72 | case TxoutType::WITNESS_V0_KEYHASH: { |
| 73 | WitnessV0KeyHash hash; |
| 74 | std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin()); |
| 75 | addressRet = hash; |
| 76 | return true; |
| 77 | } |
| 78 | case TxoutType::WITNESS_V0_SCRIPTHASH: { |
| 79 | WitnessV0ScriptHash hash; |
| 80 | std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin()); |
| 81 | addressRet = hash; |
| 82 | return true; |
| 83 | } |
| 84 | case TxoutType::WITNESS_V1_TAPROOT: { |
| 85 | WitnessV1Taproot tap; |
| 86 | std::copy(vSolutions[0].begin(), vSolutions[0].end(), tap.begin()); |
| 87 | addressRet = tap; |
| 88 | return true; |
| 89 | } |
| 90 | case TxoutType::ANCHOR: { |
| 91 | addressRet = PayToAnchor(); |
| 92 | return true; |
| 93 | } |
| 94 | case TxoutType::WITNESS_UNKNOWN: { |
| 95 | addressRet = WitnessUnknown{vSolutions[0][0], vSolutions[1]}; |
| 96 | return true; |
| 97 | } |
| 98 | case TxoutType::MULTISIG: |
| 99 | case TxoutType::NULL_DATA: |
| 100 | case TxoutType::NONSTANDARD: |
| 101 | addressRet = CNoDestination(scriptPubKey); |
| 102 | return false; |
| 103 | } // no default case, so the compiler can warn about missing cases |
| 104 | assert(false); |
| 105 | } |
| 106 | |