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.
| 219 | // A witness program is any valid CScript that consists of a 1-byte push opcode |
| 220 | // followed by a data push between 2 and 40 bytes. |
| 221 | bool CScript::IsWitnessProgram(uint8_t& version, std::vector<unsigned char>& program) const |
| 222 | { |
| 223 | if (this->size() < 4 || this->size() > 42) { |
| 224 | return false; |
| 225 | } |
| 226 | if ((*this)[0] != OP_0 && ((*this)[0] < OP_1 || (*this)[0] > OP_16)) { |
| 227 | return false; |
| 228 | } |
| 229 | if (static_cast<size_t>((*this)[1] + 2) == this->size()) { |
| 230 | version = DecodeOP_N(static_cast<opcodetype>((*this)[0])); |
| 231 | program = std::vector<unsigned char>(this->begin() + 2, this->end()); |
| 232 | return true; |
| 233 | } |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | bool CScript::IsWitnessProgram() const |
| 238 | { |