diff options
| author | Pieter Wuille <[email protected]> | 2015-11-08 01:16:45 +0100 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2016-06-22 15:42:59 +0200 |
| commit | 449f9b8debcceb61a92043bc7031528a53627c47 (patch) | |
| tree | c55434295cae8c338fe8ec128c325fa254303ecb /src/script/script.cpp | |
| parent | BIP144: Serialization, hashes, relay (sender side) (diff) | |
| download | discoin-449f9b8debcceb61a92043bc7031528a53627c47.tar.xz discoin-449f9b8debcceb61a92043bc7031528a53627c47.zip | |
BIP141: Witness program
Diffstat (limited to 'src/script/script.cpp')
| -rw-r--r-- | src/script/script.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/script/script.cpp b/src/script/script.cpp index 6b1eb52bb..73f5a61bf 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -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()) |