pub struct ScriptNumber {
pub val: BigInt,
pub after_genesis: bool,
}Expand description
A script number using big integer arithmetic for overflow safety.
Fields§
§val: BigIntThe numeric value stored as a big integer.
after_genesis: boolWhether post-genesis rules are active (affects serialization clamping).
Implementations§
Source§impl ScriptNumber
impl ScriptNumber
Sourcepub fn from_bytes(
bb: &[u8],
script_num_len: usize,
require_minimal: bool,
after_genesis: bool,
) -> Result<Self, InterpreterError>
pub fn from_bytes( bb: &[u8], script_num_len: usize, require_minimal: bool, after_genesis: bool, ) -> Result<Self, InterpreterError>
Parse a byte array into a ScriptNumber.
script_num_len is the max allowed byte length.
require_minimal enforces minimal encoding.
after_genesis enables post-genesis rules.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize the number to bytes in little-endian with sign bit.
Sourcepub fn add(&mut self, other: &ScriptNumber) -> &mut Self
pub fn add(&mut self, other: &ScriptNumber) -> &mut Self
Add another script number to this one and return self for chaining.
Sourcepub fn sub(&mut self, other: &ScriptNumber) -> &mut Self
pub fn sub(&mut self, other: &ScriptNumber) -> &mut Self
Subtract another script number from this one and return self for chaining.
Sourcepub fn mul(&mut self, other: &ScriptNumber) -> &mut Self
pub fn mul(&mut self, other: &ScriptNumber) -> &mut Self
Multiply this script number by another and return self for chaining.
Sourcepub fn div(&mut self, other: &ScriptNumber) -> &mut Self
pub fn div(&mut self, other: &ScriptNumber) -> &mut Self
Divide this script number by another (truncated toward zero) and return self for chaining.
Sourcepub fn modulo(&mut self, other: &ScriptNumber) -> &mut Self
pub fn modulo(&mut self, other: &ScriptNumber) -> &mut Self
Compute the truncated remainder of dividing by another and return self for chaining.
Sourcepub fn abs(&mut self) -> &mut Self
pub fn abs(&mut self) -> &mut Self
Replace this number with its absolute value and return self for chaining.
Sourcepub fn set(&mut self, i: i64) -> &mut Self
pub fn set(&mut self, i: i64) -> &mut Self
Set this number to the given i64 value and return self for chaining.
Sourcepub fn less_than(&self, other: &ScriptNumber) -> bool
pub fn less_than(&self, other: &ScriptNumber) -> bool
Return true if this number is less than other.
Sourcepub fn less_than_int(&self, i: i64) -> bool
pub fn less_than_int(&self, i: i64) -> bool
Return true if this number is less than the given i64 value.
Sourcepub fn less_than_or_equal(&self, other: &ScriptNumber) -> bool
pub fn less_than_or_equal(&self, other: &ScriptNumber) -> bool
Return true if this number is less than or equal to other.
Sourcepub fn greater_than(&self, other: &ScriptNumber) -> bool
pub fn greater_than(&self, other: &ScriptNumber) -> bool
Return true if this number is greater than other.
Sourcepub fn greater_than_int(&self, i: i64) -> bool
pub fn greater_than_int(&self, i: i64) -> bool
Return true if this number is greater than the given i64 value.
Sourcepub fn greater_than_or_equal(&self, other: &ScriptNumber) -> bool
pub fn greater_than_or_equal(&self, other: &ScriptNumber) -> bool
Return true if this number is greater than or equal to other.
Sourcepub fn equal(&self, other: &ScriptNumber) -> bool
pub fn equal(&self, other: &ScriptNumber) -> bool
Return true if this number is equal to other.
Trait Implementations§
Source§impl Clone for ScriptNumber
impl Clone for ScriptNumber
Source§fn clone(&self) -> ScriptNumber
fn clone(&self) -> ScriptNumber
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more