| 446 | } |
| 447 | |
| 448 | uint160 GetHashForDestination(const CTxDestination& dest) |
| 449 | { |
| 450 | uint160 hashDest = uint160(); |
| 451 | CScript script; |
| 452 | boost::apply_visitor(CScriptVisitor(&script), dest); |
| 453 | txnouttype txType = TX_NONSTANDARD; |
| 454 | CTxDestination dummyDest; |
| 455 | if(ExtractDestination(script, dummyDest, &txType)) { |
| 456 | if ((txType == TX_PUBKEYHASH || txType == TX_PUBKEY) && dest.type() == typeid(CKeyID)) { |
| 457 | CKeyID addressKey(boost::get<CKeyID>(dest)); |
| 458 | std::vector<unsigned char> addrBytes(addressKey.begin(), addressKey.end()); |
| 459 | hashDest = uint160(addrBytes); |
| 460 | } |
| 461 | else if (txType == TX_SCRIPTHASH && dest.type() == typeid(CScriptID)){ |
| 462 | CScriptID scriptKey(boost::get<CScriptID>(dest)); |
| 463 | std::vector<unsigned char> hashBytes(scriptKey.begin(), scriptKey.end()); |
| 464 | hashDest = uint160(hashBytes); |
| 465 | } |
| 466 | else if (txType == TX_WITNESS_V0_KEYHASH && script.IsPayToWitnessPubkeyHash()) { |
| 467 | int witnessversion = 0; |
| 468 | std::vector<unsigned char> addrBytes; |
| 469 | if (script.IsWitnessProgram(witnessversion, addrBytes)) { |
| 470 | hashDest = addrBytes.size()==20 ? uint160(addrBytes) : Hash160(addrBytes); |
| 471 | } |
| 472 | } |
| 473 | else if (txType == TX_WITNESS_V0_SCRIPTHASH && script.IsPayToWitnessScriptHash()) { |
| 474 | int witnessversion = 0; |
| 475 | std::vector<unsigned char> addrBytes; |
| 476 | if (script.IsWitnessProgram(witnessversion, addrBytes)) { |
| 477 | hashDest = addrBytes.size()==20 ? uint160(addrBytes) : Hash160(addrBytes); |
| 478 | } |
| 479 | } |
| 480 | else if ((txType == TX_CALL || txType == TX_CREATE) && dest.type() == typeid(CKeyID)) { |
| 481 | CKeyID addressKey(boost::get<CKeyID>(dest)); |
| 482 | std::vector<unsigned char> addrBytes(addressKey.begin(), addressKey.end()); |
| 483 | hashDest = uint160(addrBytes); |
| 484 | } |
| 485 | // TODO: TX_COLDSTAKE if/when merged |
| 486 | } |
| 487 | return hashDest; |
| 488 | } |
| 489 | |
| 490 | CScript GetScriptForDestination(const CTxDestination& dest) |
| 491 | { |
no test coverage detected