Skip to main content

ScriptNumber

Struct ScriptNumber 

Source
pub struct ScriptNumber {
    pub val: BigInt,
    pub after_genesis: bool,
}
Expand description

A script number using big integer arithmetic for overflow safety.

Fields§

§val: BigInt

The numeric value stored as a big integer.

§after_genesis: bool

Whether post-genesis rules are active (affects serialization clamping).

Implementations§

Source§

impl ScriptNumber

Source

pub fn new(val: i64, after_genesis: bool) -> Self

Create a new ScriptNumber from an i64 value.

Source

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.

Source

pub fn to_bytes(&self) -> Vec<u8>

Serialize the number to bytes in little-endian with sign bit.

Source

pub fn add(&mut self, other: &ScriptNumber) -> &mut Self

Add another script number to this one and return self for chaining.

Source

pub fn sub(&mut self, other: &ScriptNumber) -> &mut Self

Subtract another script number from this one and return self for chaining.

Source

pub fn mul(&mut self, other: &ScriptNumber) -> &mut Self

Multiply this script number by another and return self for chaining.

Source

pub fn div(&mut self, other: &ScriptNumber) -> &mut Self

Divide this script number by another (truncated toward zero) and return self for chaining.

Source

pub fn modulo(&mut self, other: &ScriptNumber) -> &mut Self

Compute the truncated remainder of dividing by another and return self for chaining.

Source

pub fn incr(&mut self) -> &mut Self

Increment this number by one and return self for chaining.

Source

pub fn decr(&mut self) -> &mut Self

Decrement this number by one and return self for chaining.

Source

pub fn neg(&mut self) -> &mut Self

Negate this number and return self for chaining.

Source

pub fn abs(&mut self) -> &mut Self

Replace this number with its absolute value and return self for chaining.

Source

pub fn set(&mut self, i: i64) -> &mut Self

Set this number to the given i64 value and return self for chaining.

Source

pub fn is_zero(&self) -> bool

Return true if this number is zero.

Source

pub fn less_than(&self, other: &ScriptNumber) -> bool

Return true if this number is less than other.

Source

pub fn less_than_int(&self, i: i64) -> bool

Return true if this number is less than the given i64 value.

Source

pub fn less_than_or_equal(&self, other: &ScriptNumber) -> bool

Return true if this number is less than or equal to other.

Source

pub fn greater_than(&self, other: &ScriptNumber) -> bool

Return true if this number is greater than other.

Source

pub fn greater_than_int(&self, i: i64) -> bool

Return true if this number is greater than the given i64 value.

Source

pub fn greater_than_or_equal(&self, other: &ScriptNumber) -> bool

Return true if this number is greater than or equal to other.

Source

pub fn equal(&self, other: &ScriptNumber) -> bool

Return true if this number is equal to other.

Source

pub fn equal_int(&self, i: i64) -> bool

Return true if this number is equal to the given i64 value.

Source

pub fn to_i32(&self) -> i32

Convert to i32, clamping to [i32::MIN, i32::MAX] on overflow.

Source

pub fn to_i64(&self) -> i64

Convert to i64, clamping to [i64::MIN, i64::MAX] on overflow.

Source

pub fn to_int(&self) -> i64

Convert to i64, returning 0 if the value does not fit.

Trait Implementations§

Source§

impl Clone for ScriptNumber

Source§

fn clone(&self) -> ScriptNumber

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScriptNumber

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V