diff --git a/cardano_clusterlib/transaction_group.py b/cardano_clusterlib/transaction_group.py index 5a7ef83..4542d5e 100644 --- a/cardano_clusterlib/transaction_group.py +++ b/cardano_clusterlib/transaction_group.py @@ -426,6 +426,7 @@ def build_raw_tx( treasury_donation: int | None = None, invalid_hereafter: int | None = None, invalid_before: int | None = None, + src_addr_utxos: list[structs.UTXOData] | None = None, join_txouts: bool = True, destination_dir: itp.FileType = ".", ) -> structs.TxRawOutput: @@ -466,6 +467,7 @@ def build_raw_tx( treasury_donation: A donation to the treasury to perform (optional). invalid_hereafter: A last block when the transaction is still valid (optional). invalid_before: A first block when the transaction is valid (optional). + src_addr_utxos: A list of UTxOs for the source address (optional). join_txouts: A bool indicating whether to aggregate transaction outputs by payment address (True by default). destination_dir: A path to directory for storing artifacts (optional). @@ -495,6 +497,7 @@ def build_raw_tx( script_withdrawals=script_withdrawals, deposit=deposit, treasury_donation=treasury_donation, + src_addr_utxos=src_addr_utxos, skip_asset_balancing=False, ) @@ -609,6 +612,7 @@ def calculate_tx_fee( treasury_donation: int | None = None, invalid_hereafter: int | None = None, invalid_before: int | None = None, + src_addr_utxos: list[structs.UTXOData] | None = None, witness_count_add: int = 0, join_txouts: bool = True, destination_dir: itp.FileType = ".", @@ -650,6 +654,7 @@ def calculate_tx_fee( treasury_donation: A donation to the treasury to perform (optional). invalid_hereafter: A last block when the transaction is still valid (optional). invalid_before: A first block when the transaction is valid (optional). + src_addr_utxos: A list of UTxOs for the source address (optional). witness_count_add: A number of witnesses to add - workaround to make the fee calculation more precise. join_txouts: A bool indicating whether to aggregate transaction outputs @@ -693,6 +698,7 @@ def calculate_tx_fee( script_votes=script_votes, invalid_hereafter=invalid_hereafter or ttl, invalid_before=invalid_before, + src_addr_utxos=src_addr_utxos, deposit=deposit, current_treasury_value=current_treasury_value, treasury_donation=treasury_donation, @@ -1309,6 +1315,15 @@ def send_tx( script_withdrawals=script_withdrawals, ) + # Get UTxOs for src address here so the records can be passed around, and it is + # not necessary to get them once for fee calculation and again for the final transaction + # building. + src_addr_utxos = ( + self._clusterlib_obj.g_query.get_utxo(address=src_address) + if fee is None and not txins + else None + ) + if fee is None: fee = self.calculate_tx_fee( src_address=src_address, @@ -1331,6 +1346,7 @@ def send_tx( current_treasury_value=current_treasury_value, treasury_donation=treasury_donation, invalid_hereafter=invalid_hereafter or ttl, + src_addr_utxos=src_addr_utxos, witness_count_add=witness_count_add, join_txouts=join_txouts, destination_dir=destination_dir, @@ -1364,6 +1380,7 @@ def send_tx( treasury_donation=treasury_donation, invalid_hereafter=invalid_hereafter or ttl, invalid_before=invalid_before, + src_addr_utxos=src_addr_utxos, join_txouts=join_txouts, destination_dir=destination_dir, ) diff --git a/cardano_clusterlib/txtools.py b/cardano_clusterlib/txtools.py index 1e77816..05c8dda 100644 --- a/cardano_clusterlib/txtools.py +++ b/cardano_clusterlib/txtools.py @@ -638,6 +638,7 @@ def _get_tx_ins_outs( treasury_donation: int | None = None, withdrawals: structs.OptionalTxOuts = (), mint_txouts: structs.OptionalTxOuts = (), + src_addr_utxos: list[structs.UTXOData] | None = None, skip_asset_balancing: bool = False, ) -> tuple[list[structs.UTXOData], list[structs.TxOut]]: """Return list of transaction's inputs and outputs. @@ -653,6 +654,7 @@ def _get_tx_ins_outs( treasury_donation: A donation to the treasury to perform (optional). withdrawals: A list (iterable) of `TxOuts`, specifying reward withdrawals (optional). mint_txouts: A list (iterable) of `TxOuts`, specifying minted tokens (optional). + src_addr_utxos: A list of UTxOs for the source address (optional). skip_asset_balancing: A bool indicating if assets balancing should be skipped (`build` command balance the assets automatically in newer versions). @@ -670,7 +672,7 @@ def _get_tx_ins_outs( txins_all = list(txins) if not txins_all: # No txins were provided, so we'll select them from the source address - address_utxos = clusterlib_obj.g_query.get_utxo(address=src_address) + address_utxos = src_addr_utxos or clusterlib_obj.g_query.get_utxo(address=src_address) if not address_utxos: msg = f"No UTxO returned for '{src_address}'." raise exceptions.CLIError(msg) @@ -760,6 +762,7 @@ def collect_data_for_build( script_withdrawals: structs.OptionalScriptWithdrawals = (), deposit: int | None = None, treasury_donation: int | None = None, + src_addr_utxos: list[structs.UTXOData] | None = None, skip_asset_balancing: bool = False, ) -> structs.DataForBuild: """Collect data (txins, txouts, withdrawals) needed for building a transaction. @@ -783,6 +786,7 @@ def collect_data_for_build( data (optional). deposit: A deposit amount needed by the transaction (optional). treasury_donation: A donation to the treasury to perform (optional). + src_addr_utxos: A list of UTxOs for the source address (optional). skip_asset_balancing: A bool indicating if assets balancing should be skipped (`build` command balance the assets automatically in newer versions). @@ -833,6 +837,7 @@ def collect_data_for_build( treasury_donation=treasury_donation, withdrawals=withdrawals_txouts, mint_txouts=mint_txouts, + src_addr_utxos=src_addr_utxos, skip_asset_balancing=skip_asset_balancing, )