| 234 | } |
| 235 | |
| 236 | bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet) |
| 237 | { |
| 238 | std::vector<valtype> vSolutions; |
| 239 | TxoutType whichType = Solver(scriptPubKey, vSolutions); |
| 240 | |
| 241 | switch (whichType) { |
| 242 | case TxoutType::PUBKEY: { |
| 243 | CPubKey pubKey(vSolutions[0]); |
| 244 | if (!pubKey.IsValid()) |
| 245 | return false; |
| 246 | |
| 247 | addressRet = PKHash(pubKey); |
| 248 | return true; |
| 249 | } |
| 250 | case TxoutType::PUBKEYHASH: { |
| 251 | addressRet = PKHash(uint160(vSolutions[0])); |
| 252 | return true; |
| 253 | } |
| 254 | case TxoutType::SCRIPTHASH: { |
| 255 | addressRet = ScriptHash(uint160(vSolutions[0])); |
| 256 | return true; |
| 257 | } |
| 258 | case TxoutType::WITNESS_V0_KEYHASH: { |
| 259 | WitnessV0KeyHash hash; |
| 260 | std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin()); |
| 261 | addressRet = hash; |
| 262 | return true; |
| 263 | } |
| 264 | case TxoutType::WITNESS_V0_SCRIPTHASH: { |
| 265 | WitnessV0ScriptHash hash; |
| 266 | std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin()); |
| 267 | addressRet = hash; |
| 268 | return true; |
| 269 | } |
| 270 | case TxoutType::WITNESS_V1_TAPROOT: { |
| 271 | WitnessV1Taproot tap; |
| 272 | std::copy(vSolutions[0].begin(), vSolutions[0].end(), tap.begin()); |
| 273 | addressRet = tap; |
| 274 | return true; |
| 275 | } |
| 276 | case TxoutType::WITNESS_UNKNOWN: { |
| 277 | WitnessUnknown unk; |
| 278 | unk.version = vSolutions[0][0]; |
| 279 | std::copy(vSolutions[1].begin(), vSolutions[1].end(), unk.program); |
| 280 | unk.length = vSolutions[1].size(); |
| 281 | addressRet = unk; |
| 282 | return true; |
| 283 | } |
| 284 | case TxoutType::MULTISIG: |
| 285 | case TxoutType::NULL_DATA: |
| 286 | case TxoutType::NONSTANDARD: |
| 287 | case TxoutType::OP_TRUE: // ELEMENTS (no address type) |
| 288 | case TxoutType::FEE: // ELEMENTS (no address type) |
| 289 | return false; |
| 290 | } // no default case, so the compiler can warn about missing cases |
| 291 | assert(false); |
| 292 | } |
| 293 | |