MCPcopy Create free account
hub / github.com/citp/BlockSci / IsWitnessProgram

Method IsWitnessProgram

src/internal/script_view.cpp:83–96  ·  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

81 // A witness program is any valid CScript that consists of a 1-byte push opcode
82 // followed by a data push between 2 and 40 bytes.
83 bool CScriptView::IsWitnessProgram(uint8_t& version, ranges::subrange<const unsigned char *>& program) const {
84 if (this->size() < 4 || this->size() > 42) {
85 return false;
86 }
87 if ((*this)[0] != OP_0 && ((*this)[0] < OP_1 || (*this)[0] > OP_16)) {
88 return false;
89 }
90 if (static_cast<size_t>((*this)[1] + 2) == this->size()) {
91 version = CScript::DecodeOP_N(static_cast<opcodetype>((*this)[0]));
92 program = {this->begin() + 2, this->end()};
93 return true;
94 }
95 return false;
96 }
97
98 bool CScriptView::IsWitnessProgram() const {
99 if (this->size() < 4 || this->size() > 42) {

Callers 1

extractScriptDataFunction · 0.45

Calls 3

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected