Skip to content

Commit 0ee54fd

Browse files
Compatible group
1 parent 1f871b4 commit 0ee54fd

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Group of subgroups for 'compatible alonzo' commands."""
2+
3+
import logging
4+
5+
from cardano_clusterlib.compatilbe_group import compatible_alonzo_transaction_group
6+
7+
LOGGER = logging.getLogger(__name__)
8+
9+
10+
class CompatibleAlonzoGroup:
11+
def __init__(self, clusterlib_obj: "itp.ClusterLib") -> None:
12+
self._clusterlib_obj = clusterlib_obj
13+
14+
# Groups of commands within this era
15+
self._transaction_group: (
16+
compatible_alonzo_transaction_group.CompatibleAlonzoTransactionGroup | None
17+
) = None
18+
19+
@property
20+
def transaction(self) -> "compatible_alonzo_transaction_group.CompatibleAlonzoTransactionGroup":
21+
"""Transaction group for Alonzo compatible commands."""
22+
if not self._transaction_group:
23+
self._transaction_group = (
24+
compatible_alonzo_transaction_group.CompatibleAlonzoTransactionGroup(
25+
clusterlib_obj=self._clusterlib_obj
26+
)
27+
)
28+
return self._transaction_group
29+
30+
def __repr__(self) -> str:
31+
return f"<{self.__class__.__name__}: era=alonzo clusterlib_obj={id(self._clusterlib_obj)}>"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""Transaction commands for 'cardano-cli compatible alonzo transaction'."""
2+
3+
import logging
4+
from typing import Sequence
5+
6+
from cardano_clusterlib import types as itp
7+
8+
LOGGER = logging.getLogger(__name__)
9+
10+
11+
class CompatibleAlonzoTransactionGroup:
12+
def __init__(self, clusterlib_obj: "itp.ClusterLib") -> None:
13+
self._clusterlib_obj = clusterlib_obj
14+
15+
def build_raw(
16+
self,
17+
txins: Sequence[str],
18+
txouts: Sequence[str],
19+
out_file: itp.FileType,
20+
extra_args: Sequence[str] | None = None,
21+
) -> None:
22+
"""Simple wrapper for `cardano-cli compatible alonzo transaction build-raw`.
23+
"""
24+
if not txins:
25+
msg = "`txins` must not be empty for compatible transaction build-raw."
26+
raise ValueError(msg)
27+
28+
extra_args = extra_args or ()
29+
30+
cmd: list[str] = [
31+
"cardano-cli",
32+
"compatible",
33+
"alonzo",
34+
"transaction",
35+
"build-raw",
36+
]
37+
38+
for txin in txins:
39+
cmd.extend(["--tx-in", txin])
40+
41+
for txout in txouts:
42+
cmd.extend(["--tx-out", txout])
43+
44+
cmd.extend(["--out-file", str(out_file)])
45+
cmd.extend(list(extra_args))
46+
47+
LOGGER.debug("Running compatible Alonzo transaction build-raw: %s", " ".join(cmd))
48+
49+
self._clusterlib_obj.cli(cmd)
50+
51+
def __repr__(self) -> str:
52+
return f"<{self.__class__.__name__}: clusterlib_obj={id(self._clusterlib_obj)}>"

0 commit comments

Comments
 (0)