mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
BIP141: Witness program
This commit is contained in:
parent
7030d9eb47
commit
449f9b8deb
16 changed files with 201 additions and 37 deletions
|
|
@ -210,6 +210,24 @@ bool CScript::IsPayToScriptHash() const
|
|||
(*this)[22] == OP_EQUAL);
|
||||
}
|
||||
|
||||
// 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.
|
||||
bool CScript::IsWitnessProgram(int& version, std::vector<unsigned char>& program) const
|
||||
{
|
||||
if (this->size() < 4 || this->size() > 42) {
|
||||
return false;
|
||||
}
|
||||
if ((*this)[0] != OP_0 && ((*this)[0] < OP_1 || (*this)[0] > OP_16)) {
|
||||
return false;
|
||||
}
|
||||
if ((size_t)((*this)[1] + 2) == this->size()) {
|
||||
version = DecodeOP_N((opcodetype)(*this)[0]);
|
||||
program = std::vector<unsigned char>(this->begin() + 2, this->end());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CScript::IsPushOnly(const_iterator pc) const
|
||||
{
|
||||
while (pc < end())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue