blvm_consensus/script/
stack.rs1use crate::types::*;
7
8#[cfg(feature = "production")]
9use smallvec::SmallVec;
10
11#[cfg(feature = "production")]
13pub type StackElement = SmallVec<[u8; 80]>;
14#[cfg(not(feature = "production"))]
15pub type StackElement = ByteString;
16
17#[inline]
19pub fn to_stack_element(data: &[u8]) -> StackElement {
20 #[cfg(feature = "production")]
21 return SmallVec::from_slice(data);
22 #[cfg(not(feature = "production"))]
23 return data.to_vec();
24}
25
26#[cfg(feature = "production")]
29#[inline(always)]
30pub fn cast_to_bool(v: &[u8]) -> bool {
31 for i in 0..v.len() {
32 if v[i] != 0 {
33 if i == v.len() - 1 && v[i] == 0x80 {
35 return false;
36 }
37 return true;
38 }
39 }
40 false
41}
42
43#[cfg(not(feature = "production"))]
44#[inline]
45pub fn cast_to_bool(v: &[u8]) -> bool {
46 for i in 0..v.len() {
47 if v[i] != 0 {
48 if i == v.len() - 1 && v[i] == 0x80 {
50 return false;
51 }
52 return true;
53 }
54 }
55 false
56}