MCPcopy Create free account
hub / github.com/BitcoinUnlimited/BitcoinUnlimited / IsPayToScriptHash

Method IsPayToScriptHash

src/script/script.cpp:517–554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

515}
516
517bool CScript::IsPayToScriptHash(uint32_t flags, std::vector<uint8_t> *hash_out, bool *is_p2sh_32) const
518{
519 // If caller wants to know if it was p2sh_32, default the boolean to false (common case)
520 if (is_p2sh_32)
521 {
522 *is_p2sh_32 = false;
523 }
524 // Extra-fast test for pay-to-script-hash CScripts:
525 // - Legacy p2sh uses 160-bit hash (OP_HASH160)
526 // - Newer p2sh_32 uses 256-bit hash (OP_HASH256)
527 if (size() == 23 && (*this)[0] == OP_HASH160 && (*this)[1] == 0x14 && (*this)[22] == OP_EQUAL)
528 {
529 /* 160 bit */
530 if (hash_out)
531 {
532 hash_out->assign(&(*this)[2], &(*this)[22]);
533 }
534 return true;
535 }
536 else if ((flags & SCRIPT_ENABLE_P2SH_32) && size() == 35 && (*this)[0] == OP_HASH256 && (*this)[1] == 0x20 &&
537 (*this)[34] == OP_EQUAL)
538 {
539 /* 256 bit */
540 if (hash_out)
541 {
542 hash_out->assign(&(*this)[2], &(*this)[34]);
543 }
544 // Set is_p2sh_32 pointer if specified. Caller could deduce this from size of hash_out vector, however caller
545 // may not want the overhead of the vector but may just want this bool flag instead (such as in interpreter.cpp
546 // VerifyScript())
547 if (is_p2sh_32)
548 {
549 *is_p2sh_32 = true;
550 }
551 return true;
552 }
553 return false;
554}
555
556// A witness program is any valid CScript that consists of a 1-byte push opcode
557// followed by a data push between 2 and 40 bytes.

Callers 8

MutateTxSignFunction · 0.80
IsToScriptIDMethod · 0.80
listunspentFunction · 0.80
VerifyScriptFunction · 0.80
SolverFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
signrawtransactionFunction · 0.80
GetP2SHSigOpCountFunction · 0.80

Calls 2

sizeFunction · 0.85
assignMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64