|
| 1 | +"""Alonzo era compatible commands for `cardano-cli compatible alonzo`.""" |
| 2 | + |
| 3 | +import logging |
| 4 | +from typing import TYPE_CHECKING |
| 5 | + |
| 6 | +from cardano_clusterlib import types as itp |
| 7 | + |
| 8 | +if TYPE_CHECKING: |
| 9 | + from cardano_clusterlib.clusterlib_klass import ClusterLib |
| 10 | + |
| 11 | +LOGGER = logging.getLogger(__name__) |
| 12 | + |
| 13 | + |
| 14 | +class CompatibleAlonzoGroup: |
| 15 | + """ |
| 16 | + A Single container for ALL Alonzo compatible commands. |
| 17 | +
|
| 18 | + """ |
| 19 | + |
| 20 | + def __init__(self, clusterlib_obj: "ClusterLib") -> None: |
| 21 | + self._clusterlib_obj = clusterlib_obj |
| 22 | + self._base_args = ("compatible", "alonzo") |
| 23 | + |
| 24 | + self.stake_address = _StakeAddressGroup(clusterlib_obj, self._base_args) |
| 25 | + self.stake_pool = _StakePoolGroup(clusterlib_obj, self._base_args) |
| 26 | + self.governance = _GovernanceGroup(clusterlib_obj, self._base_args) |
| 27 | + self.transaction = _TransactionGroup(clusterlib_obj, self._base_args) |
| 28 | + |
| 29 | + def __repr__(self) -> str: |
| 30 | + return ( |
| 31 | + f"<{self.__class__.__name__}: base_args={self._base_args} " |
| 32 | + f"clusterlib_obj={id(self._clusterlib_obj)}>" |
| 33 | + ) |
| 34 | + |
| 35 | + |
| 36 | +class _StakeAddressGroup: |
| 37 | + """`cardano-cli compatible alonzo stake-address` commands.""" |
| 38 | + |
| 39 | + def __init__(self, clusterlib_obj: "ClusterLib", base_args: tuple[str, str]) -> None: |
| 40 | + self._clusterlib_obj = clusterlib_obj |
| 41 | + self._group_args = (*base_args, "stake-address") |
| 42 | + |
| 43 | + def run_raw(self, cli_args: itp.UnpackableSequence) -> None: |
| 44 | + """Generic low-level wrapper for stake-address commands.""" |
| 45 | + full_args = [*self._group_args, *cli_args] |
| 46 | + |
| 47 | + LOGGER.debug("Running compatible alonzo stake-address: %s", " ".join(full_args)) |
| 48 | + self._clusterlib_obj.cli(full_args) |
| 49 | + |
| 50 | + def __repr__(self) -> str: |
| 51 | + return f"<StakeAddressGroup base={self._group_args}>" |
| 52 | + |
| 53 | + |
| 54 | +class _StakePoolGroup: |
| 55 | + """`cardano-cli compatible alonzo stake-pool` commands.""" |
| 56 | + |
| 57 | + def __init__(self, clusterlib_obj: "ClusterLib", base_args: tuple[str, str]) -> None: |
| 58 | + self._clusterlib_obj = clusterlib_obj |
| 59 | + self._group_args = (*base_args, "stake-pool") |
| 60 | + |
| 61 | + def run_raw(self, cli_args: itp.UnpackableSequence) -> None: |
| 62 | + """Generic low-level wrapper.""" |
| 63 | + full_args = [*self._group_args, *cli_args] |
| 64 | + |
| 65 | + LOGGER.debug("Running compatible alonzo stake-pool: %s", " ".join(full_args)) |
| 66 | + self._clusterlib_obj.cli(full_args) |
| 67 | + |
| 68 | + def __repr__(self) -> str: |
| 69 | + return f"<StakePoolGroup base={self._group_args}>" |
| 70 | + |
| 71 | + |
| 72 | +class _GovernanceGroup: |
| 73 | + """`cardano-cli compatible alonzo governance` commands.""" |
| 74 | + |
| 75 | + def __init__(self, clusterlib_obj: "ClusterLib", base_args: tuple[str, str]) -> None: |
| 76 | + self._clusterlib_obj = clusterlib_obj |
| 77 | + self._group_args = (*base_args, "governance") |
| 78 | + |
| 79 | + def run_raw(self, cli_args: itp.UnpackableSequence) -> None: |
| 80 | + """Low-level wrapper.""" |
| 81 | + full_args = [*self._group_args, *cli_args] |
| 82 | + |
| 83 | + LOGGER.debug("Running compatible alonzo governance: %s", " ".join(full_args)) |
| 84 | + self._clusterlib_obj.cli(full_args) |
| 85 | + |
| 86 | + def __repr__(self) -> str: |
| 87 | + return f"<GovernanceGroup base={self._group_args}>" |
| 88 | + |
| 89 | + |
| 90 | +class _TransactionGroup: |
| 91 | + """Transaction commands for `cardano-cli compatible alonzo transaction`.""" |
| 92 | + |
| 93 | + def __init__(self, clusterlib_obj: "ClusterLib", base_args: tuple[str, str]) -> None: |
| 94 | + """Group for 'compatible alonzo transaction' commands. |
| 95 | +
|
| 96 | + Args: |
| 97 | + clusterlib_obj: Main ClusterLib instance. |
| 98 | + group_args: Fixed CLI prefix, e.g. ("compatible", "alonzo"). |
| 99 | + """ |
| 100 | + self._clusterlib_obj = clusterlib_obj |
| 101 | + self._group_args = (*base_args, "transaction") # corrected: append “transaction” here |
| 102 | + |
| 103 | + def signed_transaction( |
| 104 | + self, |
| 105 | + cli_args: itp.UnpackableSequence, |
| 106 | + ) -> None: |
| 107 | + """Low-level wrapper for `cardano-cli compatible alonzo transaction signed-transaction`.""" |
| 108 | + full_args: list[str] = [ |
| 109 | + *self._group_args, |
| 110 | + "transaction", |
| 111 | + "signed-transaction", |
| 112 | + *cli_args, |
| 113 | + ] |
| 114 | + |
| 115 | + LOGGER.debug( |
| 116 | + "Running compatible Alonzo signed-transaction: %s", |
| 117 | + " ".join(str(a) for a in full_args), |
| 118 | + ) |
| 119 | + |
| 120 | + self._clusterlib_obj.cli(full_args) |
| 121 | + |
| 122 | + def __repr__(self) -> str: |
| 123 | + return ( |
| 124 | + f"<CompatibleAlonzoTransactionGroup group_args={self._group_args} " |
| 125 | + f"clusterlib_obj={id(self._clusterlib_obj)}>" |
| 126 | + ) |
0 commit comments