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

refactor: remove deprecated tx_era parameter #265

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ cluster.g_query.get_utxo(dst_addr.address)
from cardano_clusterlib import clusterlib

# instantiate `ClusterLib`
cluster = clusterlib.ClusterLib(state_dir="path/to/cluster/state_dir", tx_era="babbage")
cluster = clusterlib.ClusterLib(state_dir="path/to/cluster/state_dir")

# source address - for funding
src_address = "addr_test1vpst87uzwafqkxumyf446zr2jsyn44cfpu9fe8yqanyuh6glj2hkl"
Expand Down
15 changes: 5 additions & 10 deletions cardano_clusterlib/clusterlib_klass.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class ClusterLib:
socket_path: A path to socket file for communication with the node. This overrides the
`CARDANO_NODE_SOCKET_PATH` environment variable.
command_era: An era used for CLI commands, by default same as the latest network Era.
tx_era: An era used for transactions, by default same as network Era. Deprecated - use
`command_era` instead.
"""

# pylint: disable=too-many-instance-attributes
Expand All @@ -53,8 +51,7 @@ def __init__(
protocol: str = consts.Protocols.CARDANO,
slots_offset: int = 0,
socket_path: itp.FileType = "",
command_era: str = "",
tx_era: str = "", # deprecated - use `command_era` instead
command_era: str = "latest",
):
# pylint: disable=too-many-statements
self.cluster_id = 0 # can be used for identifying cluster instance
Expand All @@ -63,6 +60,9 @@ def __init__(
self._cli_log = ""
self.protocol = protocol
self.command_era = command_era.lower()
self.era_in_use = (
consts.Eras.__members__.get(command_era.upper()) or consts.Eras["DEFAULT"]
).name.lower()

self.state_dir = pl.Path(state_dir).expanduser().resolve()
if not self.state_dir.exists():
Expand Down Expand Up @@ -97,15 +97,10 @@ def __init__(
# TODO: proper calculation based on `utxoCostPerWord` needed
self._min_change_value = 1800_000

# Ignore the `tx_era` if `command_era` is set
self.tx_era = "" if self.command_era else tx_era.lower()

# Conway+ era
self.conway_genesis_json: tp.Optional[pl.Path] = None
self.conway_genesis: dict = {}
if consts.Eras[(self.command_era or "DEFAULT").upper()].value >= consts.Eras.CONWAY.value:
# Ignore the `tx_era`
self.tx_era = ""
if consts.Eras[self.era_in_use.upper()].value >= consts.Eras.CONWAY.value:
# Conway genesis
self.conway_genesis_json = clusterlib_helpers._find_conway_genesis_json(
clusterlib_obj=self
Expand Down
4 changes: 2 additions & 2 deletions cardano_clusterlib/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Eras(enum.Enum):
ALONZO: int = 6
BABBAGE: int = 8
CONWAY: int = 9
DEFAULT: int = BABBAGE
LATEST: int = BABBAGE
DEFAULT: int = CONWAY
LATEST: int = CONWAY


class MultiSigTypeArgs:
Expand Down
18 changes: 3 additions & 15 deletions cardano_clusterlib/transaction_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
class TransactionGroup:
def __init__(self, clusterlib_obj: "itp.ClusterLib") -> None:
self._clusterlib_obj = clusterlib_obj
self.tx_era_arg = (
[f"--{self._clusterlib_obj.tx_era}-era"] if self._clusterlib_obj.tx_era else []
)
self.min_fee = self._clusterlib_obj.genesis["protocolParams"]["minFeeB"]
self._has_debug_prop: tp.Optional[bool] = None

Expand Down Expand Up @@ -356,7 +353,6 @@ def build_raw_tx_bare( # noqa: C901
*helpers._prepend_flag("--withdrawal", withdrawal_strings),
*txtools._get_return_collateral_txout_args(txouts=return_collateral_txouts),
*misc_args,
*self.tx_era_arg,
]

self._clusterlib_obj.cli(cli_args)
Expand All @@ -369,7 +365,7 @@ def build_raw_tx_bare( # noqa: C901
out_file=out_file,
fee=fee,
build_args=cli_args,
era=self._clusterlib_obj.command_era or self._clusterlib_obj.tx_era,
era=self._clusterlib_obj.era_in_use,
script_txins=script_txins,
script_withdrawals=script_withdrawals,
script_votes=script_votes,
Expand Down Expand Up @@ -497,10 +493,7 @@ def build_raw_tx(
if (
ttl is None
and invalid_hereafter is None
and (
consts.Eras.SHELLEY.name.lower()
in (self._clusterlib_obj.tx_era, self._clusterlib_obj.command_era)
)
and (self._clusterlib_obj.era_in_use == consts.Eras.SHELLEY.name.lower())
):
invalid_hereafter = self.calculate_tx_ttl()

Expand Down Expand Up @@ -772,16 +765,13 @@ def calculate_min_req_utxo(

era = self._clusterlib_obj.g_query.get_era().lower()
era_upper = era.upper()
tx_era_args = []
command_era_args = []
if (
self._clusterlib_obj.command_era
or (era_upper not in consts.Eras.__members__)
or consts.Eras[era_upper].value >= consts.Eras.CONWAY.value
):
command_era_args = [era]
else:
tx_era_args = [f"--{era}-era"]

self._clusterlib_obj.create_pparams_file()
stdout = self._clusterlib_obj.cli(
Expand All @@ -792,7 +782,6 @@ def calculate_min_req_utxo(
"calculate-min-required-utxo",
"--protocol-params-file",
str(self._clusterlib_obj.pparams_file),
*tx_era_args,
*txout_args,
],
add_default_args=False,
Expand Down Expand Up @@ -1009,7 +998,6 @@ def build_tx( # noqa: C901
*helpers._prepend_flag("--withdrawal", withdrawal_strings),
*txtools._get_return_collateral_txout_args(txouts=return_collateral_txouts),
*misc_args,
*self.tx_era_arg,
*self._clusterlib_obj.magic_args,
*self._clusterlib_obj.socket_args,
]
Expand All @@ -1032,7 +1020,7 @@ def build_tx( # noqa: C901
out_file=out_file,
fee=estimated_fee,
build_args=cli_args,
era=self._clusterlib_obj.command_era or self._clusterlib_obj.tx_era,
era=self._clusterlib_obj.era_in_use,
script_txins=script_txins,
script_withdrawals=collected_data.script_withdrawals,
script_votes=script_votes,
Expand Down
Loading