MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / IsWitnessProgram

Method IsWitnessProgram

src/script/script.cpp:381–395  ·  view source on GitHub ↗

A witness program is any valid CScript that consists of a 1-byte push opcode followed by a data push between 2 and 40 bytes.

Source from the content-addressed store, hash-verified

379// A witness program is any valid CScript that consists of a 1-byte push opcode
380// followed by a data push between 2 and 40 bytes.
381bool CScript::IsWitnessProgram(int &version,
382 std::vector<uint8_t> &program) const {
383 if (this->size() < 4 || this->size() > 42) {
384 return false;
385 }
386 if ((*this)[0] != OP_0 && ((*this)[0] < OP_1 || (*this)[0] > OP_16)) {
387 return false;
388 }
389 if (size_t((*this)[1] + 2) == this->size()) {
390 version = DecodeOP_N((opcodetype)(*this)[0]);
391 program = std::vector<uint8_t>(this->begin() + 2, this->end());
392 return true;
393 }
394 return false;
395}
396
397// Wrapper returning only the predicate
398bool CScript::IsWitnessProgram() const {

Callers 5

VerifyScriptFunction · 0.80
RunMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
FUZZ_TARGETFunction · 0.80
FUZZ_TARGET_INITFunction · 0.80

Calls 3

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.64
FUZZ_TARGETFunction · 0.64
FUZZ_TARGET_INITFunction · 0.64