Updating Script::is_witness_program to use new WitnessVersion

This commit is contained in:
Dr Maxim Orlovsky 2021-08-01 20:37:32 +02:00
parent 64c1ec0b76
commit ecc400826c
No known key found for this signature in database
GPG Key ID: FFC0250947E5C6F7
1 changed files with 10 additions and 10 deletions

View File

@ -367,17 +367,17 @@ impl Script {
// push opcode (for 0 to 16) followed by a data push between 2 and 40 bytes gets a new // push opcode (for 0 to 16) followed by a data push between 2 and 40 bytes gets a new
// special meaning. The value of the first push is called the "version byte". The following // special meaning. The value of the first push is called the "version byte". The following
// byte vector pushed is called the "witness program". // byte vector pushed is called the "witness program".
let min_vernum: u8 = opcodes::all::OP_PUSHNUM_1.into_u8(); let script_len = self.0.len();
let max_vernum: u8 = opcodes::all::OP_PUSHNUM_16.into_u8(); if script_len < 4 || script_len > 42 {
self.0.len() >= 4 return false
&& self.0.len() <= 42 }
// Version 0 or PUSHNUM_1-PUSHNUM_16 let ver_opcode = opcodes::All::from(self.0[0]); // Version 0 or PUSHNUM_1-PUSHNUM_16
&& (self.0[0] == 0 || self.0[0] >= min_vernum && self.0[0] <= max_vernum) let push_opbyte = self.0[1]; // Second byte push opcode 2-40 bytes
// Second byte push opcode 2-40 bytes WitnessVersion::from_opcode(ver_opcode).is_ok()
&& self.0[1] >= opcodes::all::OP_PUSHBYTES_2.into_u8() && push_opbyte >= opcodes::all::OP_PUSHBYTES_2.into_u8()
&& self.0[1] <= opcodes::all::OP_PUSHBYTES_40.into_u8() && push_opbyte <= opcodes::all::OP_PUSHBYTES_40.into_u8()
// Check that the rest of the script has the correct size // Check that the rest of the script has the correct size
&& self.0.len() - 2 == self.0[1] as usize && script_len - 2 == push_opbyte as usize
} }
/// Checks whether a script pubkey is a p2wsh output /// Checks whether a script pubkey is a p2wsh output