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.
| 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. |
| 381 | bool 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 |
| 398 | bool CScript::IsWitnessProgram() const { |