Simplify read_scriptbool
Refactor and simplify the logical operators in `read_scriptbool`. Refactor only, no logic changes.
This commit is contained in:
parent
654b2772b8
commit
373ea89a9a
|
@ -239,9 +239,12 @@ pub fn read_scriptint(v: &[u8]) -> Result<i64, Error> {
|
||||||
/// else as true", except that the overflow rules don't apply.
|
/// else as true", except that the overflow rules don't apply.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn read_scriptbool(v: &[u8]) -> bool {
|
pub fn read_scriptbool(v: &[u8]) -> bool {
|
||||||
!(v.is_empty() ||
|
let last = match v.last() {
|
||||||
((v[v.len() - 1] == 0 || v[v.len() - 1] == 0x80) &&
|
Some(last) => *last,
|
||||||
v.iter().rev().skip(1).all(|&w| w == 0)))
|
None => return false,
|
||||||
|
};
|
||||||
|
|
||||||
|
!((last == 0x00 || last == 0x80) && v.iter().rev().skip(1).all(|&b| b == 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read a script-encoded unsigned integer
|
/// Read a script-encoded unsigned integer
|
||||||
|
|
Loading…
Reference in New Issue