Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out duplicate collaterals #156

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Changes from all 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
24 changes: 12 additions & 12 deletions cardano_clusterlib/txtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ def _get_script_args( # noqa: C901
) -> List[str]:
# pylint: disable=too-many-statements,too-many-branches
grouped_args: List[str] = []
collaterals_all = set()

# spending
for tin in script_txins:
Expand All @@ -838,11 +839,7 @@ def _get_script_args( # noqa: C901
]
)
tin_collaterals = {f"{c.utxo_hash}#{c.utxo_ix}" for c in tin.collaterals}
grouped_args.extend(
[
*helpers._prepend_flag("--tx-in-collateral", tin_collaterals),
]
)
collaterals_all.update(tin_collaterals)

if tin.script_file:
grouped_args.extend(
Expand Down Expand Up @@ -933,11 +930,7 @@ def _get_script_args( # noqa: C901
# minting
for mrec in mint:
mrec_collaterals = {f"{c.utxo_hash}#{c.utxo_ix}" for c in mrec.collaterals}
grouped_args.extend(
[
*helpers._prepend_flag("--tx-in-collateral", mrec_collaterals),
]
)
collaterals_all.update(mrec_collaterals)

if mrec.script_file:
grouped_args.extend(
Expand Down Expand Up @@ -1011,9 +1004,9 @@ def _get_script_args( # noqa: C901
# certificates
for crec in complex_certs:
crec_collaterals = {f"{c.utxo_hash}#{c.utxo_ix}" for c in crec.collaterals}
collaterals_all.update(crec_collaterals)
grouped_args.extend(
[
*helpers._prepend_flag("--tx-in-collateral", crec_collaterals),
"--certificate-file",
str(crec.certificate_file),
]
Expand Down Expand Up @@ -1078,9 +1071,9 @@ def _get_script_args( # noqa: C901
# withdrawals
for wrec in script_withdrawals:
wrec_collaterals = {f"{c.utxo_hash}#{c.utxo_ix}" for c in wrec.collaterals}
collaterals_all.update(wrec_collaterals)
grouped_args.extend(
[
*helpers._prepend_flag("--tx-in-collateral", wrec_collaterals),
"--withdrawal",
f"{wrec.txout.address}+{wrec.txout.amount}",
]
Expand Down Expand Up @@ -1147,4 +1140,11 @@ def _get_script_args( # noqa: C901
["--withdrawal-reference-tx-in-redeemer-value", str(wrec.redeemer_value)]
)

# add unique collaterals
grouped_args.extend(
[
*helpers._prepend_flag("--tx-in-collateral", collaterals_all),
]
)

return grouped_args