Skip to content

Commit

Permalink
Fix scripts CLI args
Browse files Browse the repository at this point in the history
CLI args changed in IntersectMBO/cardano-node#2547
  • Loading branch information
mkoura committed Apr 19, 2021
1 parent 0312d71 commit 30262a2
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions cardano_clusterlib/clusterlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,23 @@ class TxOut(NamedTuple):
OptionalUTXOData = Union[List[UTXOData], Tuple[()]]


class ScriptFiles(NamedTuple):
txin_scripts: OptionalFiles = ()
minting_scripts: OptionalFiles = ()
certificate_scripts: OptionalFiles = ()
withdrawal_scripts: OptionalFiles = ()
auxiliary_scripts: OptionalFiles = ()


OptionalScriptFiles = Union[ScriptFiles, Tuple[()]]


class TxFiles(NamedTuple):
certificate_files: OptionalFiles = ()
proposal_files: OptionalFiles = ()
metadata_json_files: OptionalFiles = ()
metadata_cbor_files: OptionalFiles = ()
script_files: OptionalFiles = ()
script_files: OptionalScriptFiles = ()
signing_key_files: OptionalFiles = ()


Expand Down Expand Up @@ -178,7 +189,7 @@ class ClusterLib:
Attributes:
state_dir: A directory with cluster state files (keys, config files, logs, ...).
protocol: A cluster protocol - full cardano mode by default.
tx_era: An era used for transactions, by default same as `era`.
tx_era: An era used for transactions, by default same as network Era.
slots_offset: Difference in slots between cluster's start era and current era
(e.g. Byron->Mary)
"""
Expand Down Expand Up @@ -1398,7 +1409,7 @@ def _balance_txouts(
deposit: Optional[int],
withdrawals: OptionalTxOuts,
) -> List[TxOut]:
"""Ballance the transaction by adding change output for each coin."""
"""Balance the transaction by adding change output for each coin."""
txouts_result: List[TxOut] = []

# iterate over coins both in txins and txouts
Expand Down Expand Up @@ -1631,6 +1642,22 @@ def build_raw_tx_bare(
mint_records = [f"{m.amount} {m.coin}" for m in mint]
mint_args = ["--mint", "+".join(mint_records)] if mint_records else []

script_args = []
if tx_files.script_files:
script_args = [
*self._prepend_flag("--txin-script-file", tx_files.script_files.txin_scripts),
*self._prepend_flag("--minting-script-file", tx_files.script_files.minting_scripts),
*self._prepend_flag(
"--certificate-script-file", tx_files.script_files.certificate_scripts
),
*self._prepend_flag(
"--withdrawal-script-file", tx_files.script_files.withdrawal_scripts
),
*self._prepend_flag(
"--auxiliary-script-file", tx_files.script_files.auxiliary_scripts
),
]

self.cli(
[
"transaction",
Expand All @@ -1645,10 +1672,10 @@ def build_raw_tx_bare(
*self._prepend_flag("--update-proposal-file", tx_files.proposal_files),
*self._prepend_flag("--metadata-json-file", tx_files.metadata_json_files),
*self._prepend_flag("--metadata-cbor-file", tx_files.metadata_cbor_files),
*self._prepend_flag("--script-file", tx_files.script_files),
*self._prepend_flag("--withdrawal", withdrawals_combined),
*bound_args,
*mint_args,
*script_args,
*self.tx_era_arg,
]
)
Expand Down Expand Up @@ -1859,7 +1886,6 @@ def sign_tx(
tx_body_file: FileType,
signing_key_files: OptionalFiles,
tx_name: str,
script_files: OptionalFiles = (),
destination_dir: FileType = ".",
) -> Path:
"""Sign a transaction.
Expand All @@ -1868,7 +1894,6 @@ def sign_tx(
tx_body_file: A path to file with transaction body.
signing_key_files: A list of paths to signing key files.
tx_name: A name of the transaction.
script_files: A list of paths to script files (optional).
destination_dir: A path to directory for storing artifacts (optional).
Returns:
Expand All @@ -1887,7 +1912,6 @@ def sign_tx(
str(out_file),
*self.magic_args,
*self._prepend_flag("--signing-key-file", signing_key_files),
*self._prepend_flag("--script-file", script_files),
]
)

Expand All @@ -1899,7 +1923,6 @@ def witness_tx(
tx_body_file: FileType,
witness_name: str,
signing_key_files: OptionalFiles = (),
script_file: Optional[FileType] = None,
destination_dir: FileType = ".",
) -> Path:
"""Create a transaction witness.
Expand All @@ -1908,7 +1931,6 @@ def witness_tx(
tx_body_file: A path to file with transaction body.
witness_name: A name of the transaction witness.
signing_key_files: A list of paths to signing key files (optional).
script_file: A path to script file (optional).
destination_dir: A path to directory for storing artifacts (optional).
Returns:
Expand All @@ -1917,10 +1939,6 @@ def witness_tx(
destination_dir = Path(destination_dir).expanduser()
out_file = destination_dir / f"{witness_name}_tx.witness"

cli_args = []
if script_file:
cli_args = ["--script-file", str(script_file)]

self.cli(
[
"transaction",
Expand All @@ -1931,7 +1949,6 @@ def witness_tx(
str(out_file),
*self.magic_args,
*self._prepend_flag("--signing-key-file", signing_key_files),
*cli_args,
]
)

Expand Down Expand Up @@ -2004,7 +2021,6 @@ def send_tx(
deposit: Optional[int] = None,
invalid_hereafter: Optional[int] = None,
invalid_before: Optional[int] = None,
script_files: OptionalFiles = (),
join_txouts: bool = True,
destination_dir: FileType = ".",
) -> TxRawOutput:
Expand All @@ -2023,7 +2039,6 @@ def send_tx(
deposit: A deposit amount needed by the transaction (optional).
invalid_hereafter: A last block when the transaction is still valid (optional).
invalid_before: A first block when the transaction is valid (optional).
script_files: A list of paths to script files (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).
Expand All @@ -2036,9 +2051,10 @@ def send_tx(

if fee is None:
witness_count_add = 0
if script_files:
if tx_files and tx_files.script_files:
# TODO: workaround for https://github.com/input-output-hk/cardano-node/issues/1892
witness_count_add += 5 * len(script_files)
all_scripts = list(itertools.chain.from_iterable(tx_files.script_files))
witness_count_add += 5 * len(all_scripts)
fee = self.calculate_tx_fee(
src_address=src_address,
tx_name=tx_name,
Expand Down Expand Up @@ -2072,7 +2088,6 @@ def send_tx(
tx_body_file=tx_raw_output.out_file,
tx_name=tx_name,
signing_key_files=tx_files.signing_key_files,
script_files=script_files,
destination_dir=destination_dir,
)
self.submit_tx(tx_signed_file)
Expand Down

0 comments on commit 30262a2

Please sign in to comment.