bitcoin::transaction

Struct InputWeightPrediction

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

Source§

impl InputWeightPrediction

Source

pub const P2WPKH_MAX: Self = _

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.

Source

pub const P2PKH_COMPRESSED_MAX: Self = _

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.

Source

pub const P2PKH_UNCOMPRESSED_MAX: Self = _

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.

Source

pub const P2TR_KEY_DEFAULT_SIGHASH: Self = _

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.

Source

pub const P2TR_KEY_NON_DEFAULT_SIGHASH: Self = _

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.

Source

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

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.

Source

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

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.

Source

pub fn new<T>(input_script_len: usize, witness_element_lengths: T) -> Self
where T: IntoIterator, T::Item: Borrow<usize>,

Computes the prediction for a single input.

Source

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

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.

Source

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§

Source§

impl Clone for InputWeightPrediction

Source§

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

impl Debug for InputWeightPrediction

Source§

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

Formats the value using the given formatter. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

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