pub struct FinalTransaction { /* private fields */ }Expand description
A struct representing a final (but not yet signed) transaction.
Implementations§
Source§impl FinalTransaction
impl FinalTransaction
Sourcepub fn new() -> FinalTransaction
pub fn new() -> FinalTransaction
Creates a new instance of the final transaction with default values.
Sourcepub fn set_sequence(&mut self, sequence: Sequence)
pub fn set_sequence(&mut self, sequence: Sequence)
Sets a specific Sequence for the transaction.
Injects this value into the inputs that don’t declare their own sequence.
Sourcepub fn set_locktime(&mut self, locktime: LockTime)
pub fn set_locktime(&mut self, locktime: LockTime)
Sets a specific LockTime for the transaction.
Injects this value into the inputs that don’t declare their own locktime.
Sourcepub fn add_change(&mut self, change: ChangeOutput)
pub fn add_change(&mut self, change: ChangeOutput)
Sets where this transaction’s change should go.
Left unset, the signer sends change to the single address it derives internally.
Sourcepub fn remove_change(&mut self)
pub fn remove_change(&mut self)
Drops the change target, returning to the signer’s own address.
Sourcepub fn add_input(
&mut self,
partial_input: PartialInput,
required_sig: RequiredSignature,
)
pub fn add_input( &mut self, partial_input: PartialInput, required_sig: RequiredSignature, )
Adds a new input to the transaction.
§Panics
Panics if the requested signature is not NativeEcdsa or None.
(i.e. if required_sig is RequiredSignature::Witness or RequiredSignature::WitnessWithPath)
Sourcepub fn add_program_input(
&mut self,
partial_input: PartialInput,
program_input: ProgramInput,
required_sig: RequiredSignature,
)
pub fn add_program_input( &mut self, partial_input: PartialInput, program_input: ProgramInput, required_sig: RequiredSignature, )
Adds a new program input to the transaction.
§Panics
The function will panic if the required_sig parameter is of type RequiredSignature::NativeEcdsa,
as this type of signature is not applicable for program inputs.
Sourcepub fn add_issuance_input(
&mut self,
partial_input: PartialInput,
issuance_input: IssuanceInput,
required_sig: RequiredSignature,
) -> IssuanceDetails
pub fn add_issuance_input( &mut self, partial_input: PartialInput, issuance_input: IssuanceInput, required_sig: RequiredSignature, ) -> IssuanceDetails
Adds an issuance (or reissuance) input to the transaction.
§Panics
This function panics if the required_sig is of type Witness or
WitnessWithPath, as these signature types are not allowed in the current context.
Sourcepub fn add_program_issuance_input(
&mut self,
partial_input: PartialInput,
program_input: ProgramInput,
issuance_input: IssuanceInput,
required_sig: RequiredSignature,
) -> IssuanceDetails
pub fn add_program_issuance_input( &mut self, partial_input: PartialInput, program_input: ProgramInput, issuance_input: IssuanceInput, required_sig: RequiredSignature, ) -> IssuanceDetails
Adds an issuance program input to the transaction with the specified parameters.
§Panics
Panics if the required_sig parameter is of type RequiredSignature::NativeEcdsa.
Also panics if the populated input fails to return valid issuance details.
Sourcepub fn remove_input(&mut self, index: usize) -> Option<FinalInput>
pub fn remove_input(&mut self, index: usize) -> Option<FinalInput>
Removes an input from the list of inputs at the specified index.
Sourcepub fn add_output(&mut self, partial_output: PartialOutput)
pub fn add_output(&mut self, partial_output: PartialOutput)
Adds a partial output to the list of outputs.
Sourcepub fn remove_output(&mut self, index: usize) -> Option<PartialOutput>
pub fn remove_output(&mut self, index: usize) -> Option<PartialOutput>
Removes an output from the outputs list at the specified index.
§Panics
This function does not panic. If the index is invalid, it will return None instead of causing a panic.
Sourcepub fn change(&self) -> Option<&ChangeOutput>
pub fn change(&self) -> Option<&ChangeOutput>
Where this transaction’s change should go, when the caller said.
Sourcepub fn change_mut(&mut self) -> Option<&mut ChangeOutput>
pub fn change_mut(&mut self) -> Option<&mut ChangeOutput>
Where this transaction’s change should go, for a caller that needs to amend it.
Sourcepub fn inputs(&self) -> &[FinalInput]
pub fn inputs(&self) -> &[FinalInput]
Provides a slice reference to the collection of FinalInput elements.
Sourcepub fn inputs_mut(&mut self) -> &mut [FinalInput]
pub fn inputs_mut(&mut self) -> &mut [FinalInput]
Provides mutable access to the inputs field.
This method returns a mutable slice of FinalInput elements,
allowing the caller to modify the elements in the inputs field.
Sourcepub fn outputs(&self) -> &[PartialOutput]
pub fn outputs(&self) -> &[PartialOutput]
Returns a reference to the slice of PartialOutput elements contained within the struct.
Sourcepub fn outputs_mut(&mut self) -> &mut [PartialOutput]
pub fn outputs_mut(&mut self) -> &mut [PartialOutput]
Provides mutable access to the outputs field of the current struct.
Sourcepub fn n_inputs(&self) -> usize
pub fn n_inputs(&self) -> usize
Returns the number of inputs associated with the current instance.
Sourcepub fn needs_blinding(&self) -> bool
pub fn needs_blinding(&self) -> bool
Checks if any of the outputs require blinding, determines if at least one of them has a blinding_key specified.
Sourcepub fn has_confidential_input(&self) -> bool
pub fn has_confidential_input(&self) -> bool
Checks whether any input being spent is confidential.
Blinding balances the inputs against the outputs, so a transaction spending a confidential input needs
at least one blinded output to balance against. Left without one it is rejected by the node as bad-txns-in-ne-out.
Sourcepub fn calculate_fee_delta(&self, network: &SimplicityNetwork) -> i64
pub fn calculate_fee_delta(&self, network: &SimplicityNetwork) -> i64
Calculates the fee delta for a transaction based on the inputs and outputs.
The fee delta represents the net difference between the available asset amount from the transaction’s inputs and the consumed asset amount by its outputs. The function considers the network’s policy asset to determine which inputs and outputs contribute to the calculation.
§Panics
Function will panic if the asset isn’t unblinded correctly, and if PST input asset and amount is confidential.
Sourcepub fn is_balanced(&self) -> bool
pub fn is_balanced(&self) -> bool
Checks if the transaction is balanced, meaning all inputs - all outputs = 0 for every asset.
Issued and reissued amounts are credited to the input that declares them, so a newly created
asset is balanced against its declared issuance_amount/inflation_amount.
§Panics
Function will panic if the assets aren’t unblinded correctly, and if PST input assets and amounts are confidential.
Sourcepub fn calculate_fee(&self, weight: usize, fee_rate: f32) -> u64
pub fn calculate_fee(&self, weight: usize, fee_rate: f32) -> u64
Computes the transaction fee based on the provided weight and fee rate.
Overall, the function calculates the virtual size (vsize) of the transaction as:
weight / WITNESS_SCALE_FACTOR, rounded up to the nearest whole number.
Then, the fee is computed as (vsize * fee_rate / 1000.0), also rounded up.
§Returns
The transaction fee in satoshis, rounded up to the nearest whole number.
Sourcepub fn extract_pst(
&self,
) -> (PartiallySignedTransaction, HashMap<usize, TxOutSecrets>)
pub fn extract_pst( &self, ) -> (PartiallySignedTransaction, HashMap<usize, TxOutSecrets>)
Extracts a partially signed transaction (PST) and a mapping of input secrets from the current state.
§Panics
Function will panic if the pst input is a confidential issuance.
Trait Implementations§
Source§impl Clone for FinalTransaction
impl Clone for FinalTransaction
Source§fn clone(&self) -> FinalTransaction
fn clone(&self) -> FinalTransaction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for FinalTransaction
impl !Send for FinalTransaction
impl !Sync for FinalTransaction
impl !UnwindSafe for FinalTransaction
impl Freeze for FinalTransaction
impl Unpin for FinalTransaction
impl UnsafeUnpin for FinalTransaction
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreimpl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);