Updating Script::is_witness_program to use new WitnessVersion
This commit is contained in:
parent
64c1ec0b76
commit
ecc400826c
|
@ -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
|
||||
// special meaning. The value of the first push is called the "version byte". The following
|
||||
// byte vector pushed is called the "witness program".
|
||||
let min_vernum: u8 = opcodes::all::OP_PUSHNUM_1.into_u8();
|
||||
let max_vernum: u8 = opcodes::all::OP_PUSHNUM_16.into_u8();
|
||||
self.0.len() >= 4
|
||||
&& self.0.len() <= 42
|
||||
// Version 0 or PUSHNUM_1-PUSHNUM_16
|
||||
&& (self.0[0] == 0 || self.0[0] >= min_vernum && self.0[0] <= max_vernum)
|
||||
// Second byte push opcode 2-40 bytes
|
||||
&& self.0[1] >= opcodes::all::OP_PUSHBYTES_2.into_u8()
|
||||
&& self.0[1] <= opcodes::all::OP_PUSHBYTES_40.into_u8()
|
||||
let script_len = self.0.len();
|
||||
if script_len < 4 || script_len > 42 {
|
||||
return false
|
||||
}
|
||||
let ver_opcode = opcodes::All::from(self.0[0]); // Version 0 or PUSHNUM_1-PUSHNUM_16
|
||||
let push_opbyte = self.0[1]; // Second byte push opcode 2-40 bytes
|
||||
WitnessVersion::from_opcode(ver_opcode).is_ok()
|
||||
&& push_opbyte >= opcodes::all::OP_PUSHBYTES_2.into_u8()
|
||||
&& push_opbyte <= opcodes::all::OP_PUSHBYTES_40.into_u8()
|
||||
// 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
|
||||
|
|
Loading…
Reference in New Issue