pub struct TransactionBuilder { /* private fields */ }
Implementations
sourceimpl TransactionBuilder
impl TransactionBuilder
sourcepub fn add_inputs_from(
&mut self,
inputs: &TransactionUnspentOutputs,
strategy: CoinSelectionStrategyCIP2
) -> Result<(), JsError>
pub fn add_inputs_from(
&mut self,
inputs: &TransactionUnspentOutputs,
strategy: CoinSelectionStrategyCIP2
) -> Result<(), JsError>
This automatically selects and adds inputs from {inputs} consisting of just enough to cover the outputs that have already been added. This should be called after adding all certs/outputs/etc and will be an error otherwise. Uses CIP2: https://github.com/cardano-foundation/CIPs/blob/master/CIP-0002/CIP-0002.md Adding a change output must be called after via TransactionBuilder::add_change_if_needed() This function, diverging from CIP2, takes into account fees and will attempt to add additional inputs to cover the minimum fees. This does not, however, set the txbuilder’s fee.
sourcepub fn add_key_input(
&mut self,
hash: &Ed25519KeyHash,
input: &TransactionInput,
amount: &Value
)
pub fn add_key_input(
&mut self,
hash: &Ed25519KeyHash,
input: &TransactionInput,
amount: &Value
)
We have to know what kind of inputs these are to know what kind of mock witnesses to create since
- mock witnesses have different lengths depending on the type which changes the expecting fee
- Witnesses are a set so we need to get rid of duplicates to avoid over-estimating the fee
pub fn add_script_input(
&mut self,
hash: &ScriptHash,
input: &TransactionInput,
amount: &Value
)
pub fn add_bootstrap_input(
&mut self,
hash: &ByronAddress,
input: &TransactionInput,
amount: &Value
)
pub fn add_input(
&mut self,
address: &Address,
input: &TransactionInput,
amount: &Value
)
sourcepub fn fee_for_input(
&self,
address: &Address,
input: &TransactionInput,
amount: &Value
) -> Result<Coin, JsError>
pub fn fee_for_input(
&self,
address: &Address,
input: &TransactionInput,
amount: &Value
) -> Result<Coin, JsError>
calculates how much the fee would increase if you added a given output
sourcepub fn add_output(&mut self, output: &TransactionOutput) -> Result<(), JsError>
pub fn add_output(&mut self, output: &TransactionOutput) -> Result<(), JsError>
Add explicit output via a TransactionOutput object
sourcepub fn fee_for_output(
&self,
output: &TransactionOutput
) -> Result<Coin, JsError>
pub fn fee_for_output(
&self,
output: &TransactionOutput
) -> Result<Coin, JsError>
calculates how much the fee would increase if you added a given output
pub fn set_fee(&mut self, fee: &Coin)
pub fn set_ttl(&mut self, ttl: &BigNum)
pub fn set_validity_start_interval(&mut self, validity_start_interval: &BigNum)
pub fn set_certs(&mut self, certs: &Certificates)
pub fn set_withdrawals(&mut self, withdrawals: &Withdrawals)
pub fn get_auxiliary_data(&self) -> Option<AuxiliaryData>
sourcepub fn set_auxiliary_data(&mut self, auxiliary_data: &AuxiliaryData)
pub fn set_auxiliary_data(&mut self, auxiliary_data: &AuxiliaryData)
Set explicit auxiliary data via an AuxiliaryData object It might contain some metadata plus native or Plutus scripts
sourcepub fn set_native_scripts(&mut self, native_scripts: &NativeScripts)
pub fn set_native_scripts(&mut self, native_scripts: &NativeScripts)
Set explicit native scripts via a NativeScripts object
sourcepub fn set_metadata(&mut self, metadata: &GeneralTransactionMetadata)
pub fn set_metadata(&mut self, metadata: &GeneralTransactionMetadata)
Set metadata using a GeneralTransactionMetadata object It will be set to the existing or new auxiliary data in this builder
sourcepub fn add_metadatum(
&mut self,
key: &TransactionMetadatumLabel,
val: &TransactionMetadatum
)
pub fn add_metadatum(
&mut self,
key: &TransactionMetadatumLabel,
val: &TransactionMetadatum
)
Add a single metadatum using TransactionMetadatumLabel and TransactionMetadatum objects It will be securely added to existing or new metadata in this builder
sourcepub fn add_json_metadatum(
&mut self,
key: &TransactionMetadatumLabel,
val: String
) -> Result<(), JsError>
pub fn add_json_metadatum(
&mut self,
key: &TransactionMetadatumLabel,
val: String
) -> Result<(), JsError>
Add a single JSON metadatum using a TransactionMetadatumLabel and a String It will be securely added to existing or new metadata in this builder
sourcepub fn add_json_metadatum_with_schema(
&mut self,
key: &TransactionMetadatumLabel,
val: String,
schema: MetadataJsonSchema
) -> Result<(), JsError>
pub fn add_json_metadatum_with_schema(
&mut self,
key: &TransactionMetadatumLabel,
val: String,
schema: MetadataJsonSchema
) -> Result<(), JsError>
Add a single JSON metadatum using a TransactionMetadatumLabel, a String, and a MetadataJsonSchema object It will be securely added to existing or new metadata in this builder
sourcepub fn set_mint(
&mut self,
mint: &Mint,
mint_scripts: &NativeScripts
) -> Result<(), JsError>
pub fn set_mint(
&mut self,
mint: &Mint,
mint_scripts: &NativeScripts
) -> Result<(), JsError>
Set explicit Mint object and the required witnesses to this builder it will replace any previously existing mint and mint scripts NOTE! Error will be returned in case a mint policy does not have a matching script
sourcepub fn get_native_scripts(&self) -> Option<NativeScripts>
pub fn get_native_scripts(&self) -> Option<NativeScripts>
Returns a copy of the current witness native scripts in the builder
sourcepub fn set_mint_asset(
&mut self,
policy_script: &NativeScript,
mint_assets: &MintAssets
)
pub fn set_mint_asset(
&mut self,
policy_script: &NativeScript,
mint_assets: &MintAssets
)
Add a mint entry to this builder using a PolicyID and MintAssets object It will be securely added to existing or new Mint in this builder It will replace any existing mint assets with the same PolicyID
sourcepub fn add_mint_asset(
&mut self,
policy_script: &NativeScript,
asset_name: &AssetName,
amount: Int
)
pub fn add_mint_asset(
&mut self,
policy_script: &NativeScript,
asset_name: &AssetName,
amount: Int
)
Add a mint entry to this builder using a PolicyID, AssetName, and Int object for amount It will be securely added to existing or new Mint in this builder It will replace any previous existing amount same PolicyID and AssetName
sourcepub fn add_mint_asset_and_output(
&mut self,
policy_script: &NativeScript,
asset_name: &AssetName,
amount: Int,
output_builder: &TransactionOutputAmountBuilder,
output_coin: &Coin
) -> Result<(), JsError>
pub fn add_mint_asset_and_output(
&mut self,
policy_script: &NativeScript,
asset_name: &AssetName,
amount: Int,
output_builder: &TransactionOutputAmountBuilder,
output_coin: &Coin
) -> Result<(), JsError>
Add a mint entry together with an output to this builder Using a PolicyID, AssetName, Int for amount, Address, and Coin (BigNum) objects The asset will be securely added to existing or new Mint in this builder A new output will be added with the specified Address, the Coin value, and the minted asset
sourcepub fn add_mint_asset_and_output_min_required_coin(
&mut self,
policy_script: &NativeScript,
asset_name: &AssetName,
amount: Int,
output_builder: &TransactionOutputAmountBuilder
) -> Result<(), JsError>
pub fn add_mint_asset_and_output_min_required_coin(
&mut self,
policy_script: &NativeScript,
asset_name: &AssetName,
amount: Int,
output_builder: &TransactionOutputAmountBuilder
) -> Result<(), JsError>
Add a mint entry together with an output to this builder Using a PolicyID, AssetName, Int for amount, and Address objects The asset will be securely added to existing or new Mint in this builder A new output will be added with the specified Address and the minted asset The output will be set to contain the minimum required amount of Coin
pub fn new(cfg: &TransactionBuilderConfig) -> Self
pub fn set_script_data_hash(&mut self, script_data_hash: ScriptDataHash)
pub fn script_data_hash(&self) -> Option<ScriptDataHash>
pub fn set_collateral(&mut self, collateral: TransactionInputs)
pub fn collateral(&self) -> Option<TransactionInputs>
pub fn set_required_signers(&mut self, required_signers: RequiredSigners)
pub fn required_signers(&self) -> Option<RequiredSigners>
pub fn set_network_id(&mut self, network_id: NetworkId)
pub fn network_id(&self) -> Option<NetworkId>
sourcepub fn get_explicit_input(&self) -> Result<Value, JsError>
pub fn get_explicit_input(&self) -> Result<Value, JsError>
does not include refunds or withdrawals
sourcepub fn get_implicit_input(&self) -> Result<Value, JsError>
pub fn get_implicit_input(&self) -> Result<Value, JsError>
withdrawals and refunds
sourcepub fn get_total_input(&self) -> Result<Value, JsError>
pub fn get_total_input(&self) -> Result<Value, JsError>
Return explicit input plus implicit input plus mint minus burn
sourcepub fn get_explicit_output(&self) -> Result<Value, JsError>
pub fn get_explicit_output(&self) -> Result<Value, JsError>
does not include fee
pub fn get_deposit(&self) -> Result<Coin, JsError>
pub fn get_fee_if_set(&self) -> Option<Coin>
sourcepub fn add_change_if_needed(
&mut self,
address: &Address
) -> Result<bool, JsError>
pub fn add_change_if_needed(
&mut self,
address: &Address
) -> Result<bool, JsError>
Warning: this function will mutate the /fee/ field Make sure to call this function last after setting all other tx-body properties Editing inputs, outputs, mint, etc. after change been calculated might cause a mismatch in calculated fee versus the required fee
pub fn full_size(&self) -> Result<usize, JsError>
pub fn output_sizes(&self) -> Vec<usize>
sourcepub fn build(&self) -> Result<TransactionBody, JsError>
pub fn build(&self) -> Result<TransactionBody, JsError>
Returns object the body of the new transaction
Auxiliary data itself is not included
You can use get_auxiliary_data
or build_tx
sourcepub fn build_tx(&self) -> Result<Transaction, JsError>
pub fn build_tx(&self) -> Result<Transaction, JsError>
Returns full Transaction object with the body and the auxiliary data NOTE: witness_set will contain all mint_scripts if any been added or set NOTE: is_valid set to true
sourcepub fn min_fee(&self) -> Result<Coin, JsError>
pub fn min_fee(&self) -> Result<Coin, JsError>
warning: sum of all parts of a transaction must equal 0. You cannot just set the fee to the min value and forget about it warning: min_fee may be slightly larger than the actual minimum fee (ex: a few lovelaces) this is done to simplify the library code, but can be fixed later
Trait Implementations
sourceimpl Clone for TransactionBuilder
impl Clone for TransactionBuilder
sourcefn clone(&self) -> TransactionBuilder
fn clone(&self) -> TransactionBuilder
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl RefUnwindSafe for TransactionBuilder
impl Send for TransactionBuilder
impl Sync for TransactionBuilder
impl Unpin for TransactionBuilder
impl UnwindSafe for TransactionBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more