pub struct InputWeightPrediction { /* private fields */ }
Expand description

Weight prediction of an individual input.

This helper type collects information about an input to be used in predict_weight function. It can only be created using the new function or using other associated constants/methods.

Implementations§

§

impl InputWeightPrediction

pub const P2WPKH_MAX: InputWeightPrediction = _

Input weight prediction corresponding to spending of P2WPKH output with the largest possible DER-encoded signature.

If the input in your transaction uses P2WPKH you can use this instead of InputWeightPrediction::new.

This is useful when you do not use signature grinding and want to ensure you are not under-paying. See ground_p2wpkh if you do use signature grinding.

pub const P2PKH_COMPRESSED_MAX: InputWeightPrediction = _

Input weight prediction corresponding to spending of a P2PKH output with the largest possible DER-encoded signature, and a compressed public key.

If the input in your transaction uses P2PKH with a compressed key, you can use this instead of InputWeightPrediction::new.

This is useful when you do not use signature grinding and want to ensure you are not under-paying. See ground_p2pkh_compressed if you do use signature grinding.

pub const P2PKH_UNCOMPRESSED_MAX: InputWeightPrediction = _

Input weight prediction corresponding to spending of a P2PKH output with the largest possible DER-encoded signature, and an uncompressed public key.

If the input in your transaction uses P2PKH with an uncompressed key, you can use this instead of InputWeightPrediction::new.

pub const P2TR_KEY_DEFAULT_SIGHASH: InputWeightPrediction = _

Input weight prediction corresponding to spending of taproot output using the key and default sighash.

If the input in your transaction uses Taproot key spend you can use this instead of InputWeightPrediction::new.

pub const P2TR_KEY_NON_DEFAULT_SIGHASH: InputWeightPrediction = _

Input weight prediction corresponding to spending of taproot output using the key and non-default sighash.

If the input in your transaction uses Taproot key spend you can use this instead of InputWeightPrediction::new.

pub const fn ground_p2wpkh(bytes_to_grind: usize) -> InputWeightPrediction

Input weight prediction corresponding to spending of P2WPKH output using signature grinding.

If the input in your transaction uses P2WPKH and you use signature grinding you can use this instead of InputWeightPrediction::new. See P2WPKH_MAX if you don’t use signature grinding.

Note: bytes_to_grind is usually 1 because of exponential cost of higher values.

§Panics

The funcion panics in const context and debug builds if bytes_to_grind is higher than 62.

pub const fn ground_p2pkh_compressed( bytes_to_grind: usize ) -> InputWeightPrediction

Input weight prediction corresponding to spending of a P2PKH output using signature grinding, and a compressed public key.

If the input in your transaction uses compressed P2PKH and you use signature grinding you can use this instead of InputWeightPrediction::new. See P2PKH_COMPRESSED_MAX if you don’t use signature grinding.

Note: bytes_to_grind is usually 1 because of exponential cost of higher values.

§Panics

The funcion panics in const context and debug builds if bytes_to_grind is higher than 62.

pub fn new<T>( input_script_len: usize, witness_element_lengths: T ) -> InputWeightPrediction

Computes the prediction for a single input.

pub const fn from_slice( input_script_len: usize, witness_element_lengths: &[usize] ) -> InputWeightPrediction

Computes the prediction for a single input in const context.

This is a const version of new which only allows slices due to current Rust limitations around const fn. Because of these limitations it may be less efficient than new and thus is intended to be only used in const context.

pub const fn weight(&self) -> Weight

Tallies the total weight added to a transaction by an input with this weight prediction, not counting potential witness flag bytes or the witness count varint.

Trait Implementations§

§

impl Clone for InputWeightPrediction

§

fn clone(&self) -> InputWeightPrediction

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl Debug for InputWeightPrediction

§

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

Formats the value using the given formatter. Read more
§

impl Copy for InputWeightPrediction

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> 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.
§

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

§

fn vzip(self) -> V