pub struct TxHandler<T: State = Unsigned> { /* private fields */ }
Expand description
Handler for protocol transactions, wrapping inputs, outputs, and cached transaction data.
Implementations§
Source§impl<T: State> TxHandler<T>
impl<T: State> TxHandler<T>
Sourcepub fn get_spendable_output(
&self,
vout: UtxoVout,
) -> Result<SpendableTxIn, BridgeError>
pub fn get_spendable_output( &self, vout: UtxoVout, ) -> Result<SpendableTxIn, BridgeError>
Returns a spendable input for the specified output index in this transaction.
§Arguments
vout
- The protocol-specific output index.
§Returns
A SpendableTxIn
for the specified output, or a BridgeError
if not found.
Sourcepub fn get_merkle_root_of_txin(
&self,
idx: usize,
) -> Result<Option<TapNodeHash>, BridgeError>
pub fn get_merkle_root_of_txin( &self, idx: usize, ) -> Result<Option<TapNodeHash>, BridgeError>
Returns the Taproot merkle root of the specified input, if available.
§Arguments
idx
- The input index.
§Returns
The Taproot merkle root, or a BridgeError
if not found.
Sourcepub fn get_signature_id(&self, idx: usize) -> Result<SignatureId, BridgeError>
pub fn get_signature_id(&self, idx: usize) -> Result<SignatureId, BridgeError>
Returns the signature ID for the specified input.
§Arguments
idx
- The input index.
§Returns
The signature ID, or a BridgeError
if not found.
Sourcepub fn get_transaction_type(&self) -> TransactionType
pub fn get_transaction_type(&self) -> TransactionType
Returns the protocol transaction type for this handler.
Sourcepub fn get_cached_tx(&self) -> &Transaction
pub fn get_cached_tx(&self) -> &Transaction
Returns a reference to the cached Bitcoin transaction.
Sourcepub fn sign_txins(
&mut self,
signer: impl for<'a> FnMut(usize, &'a SpentTxIn, SighashCalculator<'a>) -> Result<Option<Witness>, BridgeError>,
) -> Result<(), BridgeError>
pub fn sign_txins( &mut self, signer: impl for<'a> FnMut(usize, &'a SpentTxIn, SighashCalculator<'a>) -> Result<Option<Witness>, BridgeError>, ) -> Result<(), BridgeError>
Signs all unsigned transaction inputs using the provided signer function.
This function will skip all transaction inputs that already have a witness.
§Arguments
signer
- A function that returns an optional witness for transaction inputs or returns an error if the signing fails. The function takes the input idx, input object, and a sighash calculator closure.
§Returns
Ok(())
if signing is successfulErr(BridgeError)
if signing fails
Sourcepub fn calculate_pubkey_spend_sighash(
&self,
txin_index: usize,
sighash_type: TapSighashType,
) -> Result<TapSighash, BridgeError>
pub fn calculate_pubkey_spend_sighash( &self, txin_index: usize, sighash_type: TapSighashType, ) -> Result<TapSighash, BridgeError>
Calculates the Taproot sighash for a key spend input for the given input and sighash type.
§Arguments
txin_index
- The input index.sighash_type
- The Taproot sighash type.
§Returns
The calculated Taproot sighash, or a BridgeError
if calculation fails.
Sourcepub fn calculate_script_spend_sighash_indexed(
&self,
txin_index: usize,
spend_script_idx: usize,
sighash_type: TapSighashType,
) -> Result<TapSighash, BridgeError>
pub fn calculate_script_spend_sighash_indexed( &self, txin_index: usize, spend_script_idx: usize, sighash_type: TapSighashType, ) -> Result<TapSighash, BridgeError>
Calculates the Taproot sighash for a script spend input by script index.
§Arguments
txin_index
- The input index.spend_script_idx
- The script index in the input’s script list.sighash_type
- The Taproot sighash type.
§Returns
The calculated Taproot sighash, or a BridgeError
if calculation fails.
Sourcepub fn calculate_script_spend_sighash(
&self,
txin_index: usize,
spend_script: &Script,
sighash_type: TapSighashType,
) -> Result<TapSighash, BridgeError>
pub fn calculate_script_spend_sighash( &self, txin_index: usize, spend_script: &Script, sighash_type: TapSighashType, ) -> Result<TapSighash, BridgeError>
Calculates the Taproot sighash for a script spend input by script.
§Arguments
txin_index
- The input index.spend_script
- The script being spent.sighash_type
- The Taproot sighash type.
§Returns
The calculated Taproot sighash, or a BridgeError
if calculation fails.
Sourcepub fn calculate_sighash_txin(
&self,
txin_index: usize,
sighash_type: TapSighashType,
) -> Result<TapSighash, BridgeError>
pub fn calculate_sighash_txin( &self, txin_index: usize, sighash_type: TapSighashType, ) -> Result<TapSighash, BridgeError>
Calculates the sighash for the specified input, based on its spend path stored inside SpentTxIn
.
§Arguments
txin_index
- The input index.sighash_type
- The Taproot sighash type.
§Returns
The calculated Taproot sighash, or a BridgeError
if calculation fails.
Calculates sighashes for all shared inputs for a given entity type.
§Arguments
needed_entity
- The entity type (operator, verifier, etc.).partial_signature_info
- Partial signature info for the entity.
§Returns
A vector of (sighash, signature info) pairs, or a BridgeError
if calculation fails.
Source§impl TxHandler<Signed>
impl TxHandler<Signed>
Sourcepub fn encode_tx(&self) -> RawSignedTx
pub fn encode_tx(&self) -> RawSignedTx
Encodes the signed transaction as a raw byte vector.
Source§impl TxHandler<Unsigned>
impl TxHandler<Unsigned>
Sourcepub fn promote(self) -> Result<TxHandler<Signed>, BridgeError>
pub fn promote(self) -> Result<TxHandler<Signed>, BridgeError>
Promotes an unsigned handler to a signed handler, checking that all witnesses are present.
§Returns
A TxHandler<Signed>
if all witnesses are present, or a BridgeError
if not.
Sourcepub fn set_p2tr_script_spend_witness<T: AsRef<[u8]>>(
&mut self,
script_inputs: &[T],
txin_index: usize,
script_index: usize,
) -> Result<(), BridgeError>
pub fn set_p2tr_script_spend_witness<T: AsRef<[u8]>>( &mut self, script_inputs: &[T], txin_index: usize, script_index: usize, ) -> Result<(), BridgeError>
Sets the witness for a script path spend input.
§Arguments
script_inputs
- The inputs to the tapscript.txin_index
- The input index.script_index
- The script index in the input’s script list.
§Returns
Ok(()) if successful, or a BridgeError
if not.
Sourcepub fn set_p2tr_key_spend_witness(
&mut self,
signature: &Signature,
txin_index: usize,
) -> Result<(), BridgeError>
pub fn set_p2tr_key_spend_witness( &mut self, signature: &Signature, txin_index: usize, ) -> Result<(), BridgeError>
Sets the witness for a key path spend input.
§Arguments
signature
- The Taproot signature.txin_index
- The input index.
§Returns
Ok(()) if successful, or a BridgeError
if not.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for TxHandler<T>
impl<T = Unsigned> !RefUnwindSafe for TxHandler<T>
impl<T> Send for TxHandler<T>where
T: Send,
impl<T> Sync for TxHandler<T>where
T: Sync,
impl<T> Unpin for TxHandler<T>where
T: Unpin,
impl<T = Unsigned> !UnwindSafe for TxHandler<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
fn exact_from(value: T) -> U
§impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
fn exact_into(self) -> U
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
fn overflowing_into(self) -> (U, bool)
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
fn rounding_into(self, rm: RoundingMode) -> (U, Ordering)
§impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
fn saturating_into(self) -> U
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.