From 60e820860f2c720a283827fe7f67e0c3c10c81b6 Mon Sep 17 00:00:00 2001 From: femi Date: Tue, 11 Nov 2025 03:40:14 +0000 Subject: [PATCH 1/5] Get_ref_script_size --- cardano_clusterlib/query_group.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cardano_clusterlib/query_group.py b/cardano_clusterlib/query_group.py index eb41908..55e9a12 100644 --- a/cardano_clusterlib/query_group.py +++ b/cardano_clusterlib/query_group.py @@ -744,5 +744,24 @@ def get_ledger_peer_snapshot(self) -> dict[str, tp.Any]: out: dict[str, tp.Any] = json.loads(self.query_cli(["ledger-peer-snapshot"])) or {} return out + def get_ref_script_size(self, txins: str | list[str]) -> dict[str, tp.Any]: + """Get the reference input scripts size in bytes for provided transaction inputs. + + Args: + txins: One or more transaction inputs in the format 'TxId#TxIx'. + + Returns: + dict[str, Any]: JSON output from the CLI ( + typically contains 'refScriptSize' or similar key). + """ + if isinstance(txins, str): + txins = [txins] + + cli_args = ["ref-script-size", "--output-json"] + cli_args.extend(helpers._prepend_flag("--tx-in", txins)) + + out: dict[str, tp.Any] = json.loads(self.query_cli(cli_args)) + return out + def __repr__(self) -> str: return f"<{self.__class__.__name__}: clusterlib_obj={id(self._clusterlib_obj)}>" From 9bf2f88fb4ff631dc3b51eda39d0a5853b339701 Mon Sep 17 00:00:00 2001 From: femi Date: Wed, 12 Nov 2025 01:00:46 +0000 Subject: [PATCH 2/5] Get_ref_script_size --- cardano_clusterlib/query_group.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/cardano_clusterlib/query_group.py b/cardano_clusterlib/query_group.py index 55e9a12..94a755c 100644 --- a/cardano_clusterlib/query_group.py +++ b/cardano_clusterlib/query_group.py @@ -744,18 +744,34 @@ def get_ledger_peer_snapshot(self) -> dict[str, tp.Any]: out: dict[str, tp.Any] = json.loads(self.query_cli(["ledger-peer-snapshot"])) or {} return out - def get_ref_script_size(self, txins: str | list[str]) -> dict[str, tp.Any]: - """Get the reference input scripts size in bytes for provided transaction inputs. + def get_ref_script_size( + self, + txin: str | list[str] | None = None, + utxo: structs.UTXOData | None = None, + ) -> dict[str, tp.Any]: + """Get the reference input script size in bytes for one or more transaction inputs. Args: - txins: One or more transaction inputs in the format 'TxId#TxIx'. + txin: One or more transaction inputs in the format 'TxId#TxIx' + (string or list of strings). + utxo: A single UTxO record (alternative to `txin`). Returns: - dict[str, Any]: JSON output from the CLI ( - typically contains 'refScriptSize' or similar key). + dict[str, Any]: JSON output from the CLI, typically containing + keys like 'refScriptSize' or 'refScriptHash'. """ - if isinstance(txins, str): - txins = [txins] + if not txin and not utxo: + msg = "Either `txin` or `utxo` must be provided." + raise ValueError(msg) + if txin and utxo: + msg = "Provide only one of `txin` or `utxo`, not both." + raise ValueError(msg) + + if txin: + txins = [txin] if isinstance(txin, str) else txin + else: + assert utxo is not None # reassure static type checkers + txins = [f"{utxo.utxo_hash}#{utxo.utxo_ix}"] cli_args = ["ref-script-size", "--output-json"] cli_args.extend(helpers._prepend_flag("--tx-in", txins)) From eddd442bdd071f524bf21ce918f546aae69da0e9 Mon Sep 17 00:00:00 2001 From: femi Date: Thu, 13 Nov 2025 11:32:10 +0000 Subject: [PATCH 3/5] Get_ref_script_size --- cardano_clusterlib/query_group.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/cardano_clusterlib/query_group.py b/cardano_clusterlib/query_group.py index 94a755c..be235ba 100644 --- a/cardano_clusterlib/query_group.py +++ b/cardano_clusterlib/query_group.py @@ -746,35 +746,34 @@ def get_ledger_peer_snapshot(self) -> dict[str, tp.Any]: def get_ref_script_size( self, - txin: str | list[str] | None = None, - utxo: structs.UTXOData | None = None, + txin: str | list[str] = "", + utxo: structs.UTXOData | structs.OptionalUTXOData = (), ) -> dict[str, tp.Any]: """Get the reference input script size in bytes for one or more transaction inputs. Args: txin: One or more transaction inputs in the format 'TxId#TxIx' (string or list of strings). - utxo: A single UTxO record (alternative to `txin`). + utxo: One or more UTxO records (`structs.UTXOData`) or an empty tuple by default. Returns: dict[str, Any]: JSON output from the CLI, typically containing - keys like 'refScriptSize' or 'refScriptHash'. + keys like 'refScriptSize' or 'refInputScriptSize'. """ - if not txin and not utxo: - msg = "Either `txin` or `utxo` must be provided." - raise ValueError(msg) - if txin and utxo: - msg = "Provide only one of `txin` or `utxo`, not both." - raise ValueError(msg) + cli_args = ["ref-script-size", "--output-json"] if txin: - txins = [txin] if isinstance(txin, str) else txin + if isinstance(txin, str): + txin = [txin] + cli_args += [*helpers._prepend_flag("--tx-in", txin)] + elif utxo: + if isinstance(utxo, structs.UTXOData): + utxo = [utxo] + utxo_formatted = [f"{u.utxo_hash}#{u.utxo_ix}" for u in utxo] + cli_args += [*helpers._prepend_flag("--tx-in", utxo_formatted)] else: - assert utxo is not None # reassure static type checkers - txins = [f"{utxo.utxo_hash}#{utxo.utxo_ix}"] - - cli_args = ["ref-script-size", "--output-json"] - cli_args.extend(helpers._prepend_flag("--tx-in", txins)) + msg = "Either `txin` or `utxo` must be specified." + raise ValueError(msg) out: dict[str, tp.Any] = json.loads(self.query_cli(cli_args)) return out From deddda7cfd844ada33ff7928c96f97c8a70c5893 Mon Sep 17 00:00:00 2001 From: Martin Kourim Date: Thu, 13 Nov 2025 13:07:25 +0100 Subject: [PATCH 4/5] Review changes --- cardano_clusterlib/query_group.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/cardano_clusterlib/query_group.py b/cardano_clusterlib/query_group.py index be235ba..318f7f3 100644 --- a/cardano_clusterlib/query_group.py +++ b/cardano_clusterlib/query_group.py @@ -758,23 +758,18 @@ def get_ref_script_size( Returns: dict[str, Any]: JSON output from the CLI, typically containing - keys like 'refScriptSize' or 'refInputScriptSize'. + keys like 'refScriptSize' or 'refInputScriptSize'. """ - cli_args = ["ref-script-size", "--output-json"] - if txin: - if isinstance(txin, str): - txin = [txin] - cli_args += [*helpers._prepend_flag("--tx-in", txin)] + txins = [txin] if isinstance(txin, str) else txin elif utxo: - if isinstance(utxo, structs.UTXOData): - utxo = [utxo] - utxo_formatted = [f"{u.utxo_hash}#{u.utxo_ix}" for u in utxo] - cli_args += [*helpers._prepend_flag("--tx-in", utxo_formatted)] + utxos = [utxo] if isinstance(utxo, structs.UTXOData) else utxo + txins = [f"{u.utxo_hash}#{u.utxo_ix}" for u in utxos] else: msg = "Either `txin` or `utxo` must be specified." raise ValueError(msg) + cli_args = ["ref-script-size", "--output-json", *helpers._prepend_flag("--tx-in", txins)] out: dict[str, tp.Any] = json.loads(self.query_cli(cli_args)) return out From a2c25e724656d078c59de1a068765d3f06f66417 Mon Sep 17 00:00:00 2001 From: femi Date: Fri, 14 Nov 2025 10:18:29 +0000 Subject: [PATCH 5/5] Get_ref_script_size --- cardano_clusterlib/query_group.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cardano_clusterlib/query_group.py b/cardano_clusterlib/query_group.py index 318f7f3..7adc2bf 100644 --- a/cardano_clusterlib/query_group.py +++ b/cardano_clusterlib/query_group.py @@ -769,6 +769,10 @@ def get_ref_script_size( msg = "Either `txin` or `utxo` must be specified." raise ValueError(msg) + if not txins: + msg = "No transaction inputs provided for ref-script-size query." + raise ValueError(msg) + cli_args = ["ref-script-size", "--output-json", *helpers._prepend_flag("--tx-in", txins)] out: dict[str, tp.Any] = json.loads(self.query_cli(cli_args)) return out