MCPcopy Create free account
hub / github.com/LUX-Core/lux / GetHashForDestination

Function GetHashForDestination

src/script/standard.cpp:448–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446}
447
448uint160 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
490CScript GetScriptForDestination(const CTxDestination& dest)
491{

Callers 8

addAddressIndexMethod · 0.85
addSpentIndexMethod · 0.85
validateaddressFunction · 0.85
getAddressesFromParamsFunction · 0.85
isForbiddenMethod · 0.85
DisconnectBlockFunction · 0.85
ConnectBlockFunction · 0.85
AddressToStringFunction · 0.85

Calls 11

CScriptVisitorClass · 0.85
ExtractDestinationFunction · 0.85
Hash160Function · 0.85
IsWitnessProgramMethod · 0.80
uint160Class · 0.50
typeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected