pub struct SighashCache<Prevout: Borrow<TxOut> = TxOut, Tx: Borrow<Tx> = Tx> { /* private fields */ }
Expand description
Efficiently calculates signature hash message for legacy, segwit and taproot inputs.
Implementations§
Source§impl<Prevout: Borrow<TxOut>, Tx: Borrow<Tx>> SighashCache<Prevout, Tx>
impl<Prevout: Borrow<TxOut>, Tx: Borrow<Tx>> SighashCache<Prevout, Tx>
Sourcepub fn new(tx: Tx, prevouts: Vec<Prevout>) -> Result<Self, PrevoutMismatch>
pub fn new(tx: Tx, prevouts: Vec<Prevout>) -> Result<Self, 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.
Sourcepub 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>
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.
Sourcepub fn tap_sighash_key(
&mut self,
input_index: usize,
sighash_type: Option<SighashType>,
) -> Result<TapSighash, SighashError>
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.
Sourcepub fn tap_sighash_script(
&mut self,
input_index: usize,
leaf_hash: impl Into<TapLeafHash>,
sighash_type: Option<SighashType>,
) -> Result<TapSighash, SighashError>
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
.
Sourcepub fn segwit_sighash(
&mut self,
input_index: usize,
script_code: &ScriptCode,
value: Sats,
sighash_type: SighashType,
) -> Result<Sighash, SighashError>
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.
Sourcepub fn legacy_sighash(
&self,
input_index: usize,
script_pubkey: &ScriptPubkey,
sighash_type: u32,
) -> Result<Sighash, SighashError>
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§
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>
impl<Prevout, Tx> Sync for SighashCache<Prevout, Tx>
impl<Prevout, Tx> Unpin for SighashCache<Prevout, Tx>
impl<Prevout, Tx> UnwindSafe for SighashCache<Prevout, Tx>where
Tx: UnwindSafe,
Prevout: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more