Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cardano_clusterlib/query_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,5 +744,40 @@ 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,
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:
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 containing
keys like 'refScriptSize' or 'refScriptHash'.
"""
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))

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)}>"
Loading