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.
| 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) { |
no test coverage detected