Changeset View
Changeset View
Standalone View
Standalone View
src/script/script.cpp
Show First 20 Lines • Show All 432 Lines • ▼ Show 20 Lines | |||||
bool CScript::IsWitnessProgram(int &version, | bool CScript::IsWitnessProgram(int &version, | ||||
std::vector<uint8_t> &program) const { | std::vector<uint8_t> &program) const { | ||||
if (this->size() < 4 || this->size() > 42) { | if (this->size() < 4 || this->size() > 42) { | ||||
return false; | return false; | ||||
} | } | ||||
if ((*this)[0] != OP_0 && ((*this)[0] < OP_1 || (*this)[0] > OP_16)) { | if ((*this)[0] != OP_0 && ((*this)[0] < OP_1 || (*this)[0] > OP_16)) { | ||||
return false; | return false; | ||||
} | } | ||||
if ((size_t)((*this)[1] + 2) == this->size()) { | if (size_t((*this)[1] + 2) == this->size()) { | ||||
version = DecodeOP_N((opcodetype)(*this)[0]); | version = DecodeOP_N((opcodetype)(*this)[0]); | ||||
program = std::vector<uint8_t>(this->begin() + 2, this->end()); | program = std::vector<uint8_t>(this->begin() + 2, this->end()); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool CScript::IsPushOnly(const_iterator pc) const { | bool CScript::IsPushOnly(const_iterator pc) const { | ||||
while (pc < end()) { | while (pc < end()) { | ||||
opcodetype opcode; | opcodetype opcode; | ||||
if (!GetOp(pc, opcode)) return false; | if (!GetOp(pc, opcode)) { | ||||
return false; | |||||
} | |||||
// Note that IsPushOnly() *does* consider OP_RESERVED to be a push-type | // Note that IsPushOnly() *does* consider OP_RESERVED to be a push-type | ||||
// opcode, however execution of OP_RESERVED fails, so it's not relevant | // opcode, however execution of OP_RESERVED fails, so it's not relevant | ||||
// to P2SH/BIP62 as the scriptSig would fail prior to the P2SH special | // to P2SH/BIP62 as the scriptSig would fail prior to the P2SH special | ||||
// validation code being executed. | // validation code being executed. | ||||
if (opcode > OP_16) return false; | if (opcode > OP_16) { | ||||
return false; | |||||
} | |||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool CScript::IsPushOnly() const { | bool CScript::IsPushOnly() const { | ||||
return this->IsPushOnly(begin()); | return this->IsPushOnly(begin()); | ||||
} | } |