bp

Struct SighashCache

Source
pub struct SighashCache<Prevout = TxOut, Tx = Tx>
where Prevout: Borrow<TxOut>, Tx: Borrow<Tx>,
{ /* private fields */ }
Expand description

Efficiently calculates signature hash message for legacy, segwit and taproot inputs.

Implementations§

Source§

impl<Prevout, Tx> SighashCache<Prevout, Tx>
where Prevout: Borrow<TxOut>, Tx: Borrow<Tx>,

Source

pub fn new( tx: Tx, prevouts: Vec<Prevout>, ) -> Result<SighashCache<Prevout, Tx>, PrevoutMismatch>

Constructs a new SighashCache from an unsigned transaction.

The sighash components are computed in a lazy manner when required. For the generated sighashes to be valid, no fields in the transaction may change except for script_sig and witness.

Source

pub fn tap_sighash_custom( &mut self, input_index: usize, annex: Option<Annex>, leaf_hash_code_separator: Option<(TapLeafHash, u32)>, sighash_type: Option<SighashType>, ) -> Result<TapSighash, SighashError>

Computes the BIP341 sighash for any type with a fine-grained control over annex and code separator.

Source

pub fn tap_sighash_key( &mut self, input_index: usize, sighash_type: Option<SighashType>, ) -> Result<TapSighash, SighashError>

Computes the BIP341 sighash for a key spend.

Source

pub fn tap_sighash_script( &mut self, input_index: usize, leaf_hash: impl Into<TapLeafHash>, sighash_type: Option<SighashType>, ) -> Result<TapSighash, SighashError>

Computes the BIP341 sighash for a script spend.

Assumes the default OP_CODESEPARATOR position of 0xFFFFFFFF.

Source

pub fn segwit_sighash( &mut self, input_index: usize, script_code: &ScriptCode, value: Sats, sighash_type: SighashType, ) -> Result<Sighash, SighashError>

Computes the BIP143 sighash for any flag type.

Source

pub fn legacy_sighash( &self, input_index: usize, script_pubkey: &ScriptPubkey, sighash_type: u32, ) -> Result<Sighash, SighashError>

Computes the legacy sighash for any sighash_type.

Trait Implementations§

Source§

impl<Prevout, Tx> Debug for SighashCache<Prevout, Tx>
where Prevout: Debug + Borrow<TxOut>, Tx: Debug + Borrow<Tx>,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Prevout, Tx> Freeze for SighashCache<Prevout, Tx>
where Tx: Freeze,

§

impl<Prevout, Tx> RefUnwindSafe for SighashCache<Prevout, Tx>
where Tx: RefUnwindSafe, Prevout: RefUnwindSafe,

§

impl<Prevout, Tx> Send for SighashCache<Prevout, Tx>
where Tx: Send, Prevout: Send,

§

impl<Prevout, Tx> Sync for SighashCache<Prevout, Tx>
where Tx: Sync, Prevout: Sync,

§

impl<Prevout, Tx> Unpin for SighashCache<Prevout, Tx>
where Tx: Unpin, Prevout: Unpin,

§

impl<Prevout, Tx> UnwindSafe for SighashCache<Prevout, Tx>
where Tx: UnwindSafe, Prevout: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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