Skip to content

Commit

Permalink
Merge pull request #242 from mkoura/create_hardfork
Browse files Browse the repository at this point in the history
Add `create_hardfork` function
  • Loading branch information
mkoura committed May 8, 2024
2 parents c359ff2 + e1916ae commit f0b62d6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardano_clusterlib/clusterlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from cardano_clusterlib.helpers import get_rand_str
from cardano_clusterlib.helpers import read_address_from_file
from cardano_clusterlib.structs import ActionConstitution
from cardano_clusterlib.structs import ActionHardfork
from cardano_clusterlib.structs import ActionInfo
from cardano_clusterlib.structs import ActionNoConfidence
from cardano_clusterlib.structs import ActionPParamsUpdate
Expand Down
74 changes: 74 additions & 0 deletions cardano_clusterlib/conway_gov_action_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,77 @@ def view(self, action_file: itp.FileType) -> tp.Dict[str, tp.Any]:

out: tp.Dict[str, tp.Any] = json.loads(stdout_dec)
return out

def create_hardfork(
self,
action_name: str,
deposit_amt: int,
anchor_url: str,
anchor_data_hash: str,
protocol_major_version: int,
protocol_minor_version: int,
prev_action_txid: str = "",
prev_action_ix: int = -1,
deposit_return_stake_vkey: str = "",
deposit_return_stake_vkey_file: tp.Optional[itp.FileType] = None,
deposit_return_stake_key_hash: str = "",
destination_dir: itp.FileType = ".",
) -> structs.ActionHardfork:
"""Create a hardfork initiation proposal."""
# pylint: disable=too-many-arguments
destination_dir = pl.Path(destination_dir).expanduser()
out_file = destination_dir / f"{action_name}_hardfork.action"
clusterlib_helpers._check_files_exist(out_file, clusterlib_obj=self._clusterlib_obj)

key_args = self._get_deposit_return_key_args(
deposit_return_stake_vkey=deposit_return_stake_vkey,
deposit_return_stake_vkey_file=deposit_return_stake_vkey_file,
deposit_return_stake_key_hash=deposit_return_stake_key_hash,
)

anchor_args = self._get_anchor_args(
anchor_url=anchor_url,
anchor_data_hash=anchor_data_hash,
)

prev_action_args = self._get_optional_prev_action_args(
prev_action_txid=prev_action_txid, prev_action_ix=prev_action_ix
)

self._clusterlib_obj.cli(
[
"cardano-cli",
"conway",
*self._group_args,
"create-hardfork",
*self.magic_args,
"--governance-action-deposit",
str(deposit_amt),
*key_args,
*prev_action_args,
*anchor_args,
"--protocol-major-version",
str(protocol_major_version),
"--protocol-minor-version",
str(protocol_minor_version),
"--out-file",
str(out_file),
],
add_default_args=False,
)
helpers._check_outfiles(out_file)

action_out = structs.ActionHardfork(
action_file=out_file,
deposit_amt=deposit_amt,
anchor_url=anchor_url,
anchor_data_hash=anchor_data_hash,
protocol_major_version=protocol_major_version,
protocol_minor_version=protocol_minor_version,
prev_action_txid=prev_action_txid,
prev_action_ix=prev_action_ix,
deposit_return_stake_vkey=deposit_return_stake_vkey,
deposit_return_stake_vkey_file=helpers._maybe_path(deposit_return_stake_vkey_file),
deposit_return_stake_key_hash=deposit_return_stake_key_hash,
)
return action_out
15 changes: 15 additions & 0 deletions cardano_clusterlib/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,18 @@ class ActionTreasuryWithdrawal:
deposit_return_stake_vkey: str = ""
deposit_return_stake_vkey_file: tp.Optional[pl.Path] = None
deposit_return_stake_key_hash: str = ""


@dataclasses.dataclass(frozen=True, order=True)
class ActionHardfork:
action_file: pl.Path
deposit_amt: int
anchor_url: str
anchor_data_hash: str
protocol_major_version: int
protocol_minor_version: int
prev_action_txid: str = ""
prev_action_ix: int = -1
deposit_return_stake_vkey: str = ""
deposit_return_stake_vkey_file: tp.Optional[pl.Path] = None
deposit_return_stake_key_hash: str = ""

0 comments on commit f0b62d6

Please sign in to comment.