Skip to content

Commit 6ef842c

Browse files
committed
feat(transaction): return txid from submit_tx and submit_tx_bare
- Updated `submit_tx_bare` to return transaction ID (txid) as a string. - Modified `submit_tx` to return transaction ID (txid) as a string. - Added extraction of txid from the CLI output in `submit_tx_bare`. - Ensured `submit_tx` captures and returns the txid from `submit_tx_bare`.
1 parent 33774ef commit 6ef842c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

cardano_clusterlib/transaction_group.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,13 +1128,16 @@ def assemble_tx(
11281128
helpers._check_outfiles(out_file)
11291129
return out_file
11301130

1131-
def submit_tx_bare(self, tx_file: itp.FileType) -> None:
1131+
def submit_tx_bare(self, tx_file: itp.FileType) -> str:
11321132
"""Submit a transaction, don't do any verification that it made it to the chain.
11331133
11341134
Args:
11351135
tx_file: A path to signed transaction file.
1136+
1137+
Returns:
1138+
str: A transaction ID.
11361139
"""
1137-
self._clusterlib_obj.cli(
1140+
out = self._clusterlib_obj.cli(
11381141
[
11391142
"transaction",
11401143
"submit",
@@ -1145,22 +1148,30 @@ def submit_tx_bare(self, tx_file: itp.FileType) -> None:
11451148
]
11461149
)
11471150

1151+
stdout_dec = out.stdout.strip().decode("utf-8") if out.stdout else ""
1152+
txhash_maybe = stdout_dec.split("\n")[-1]
1153+
txhash = (json.loads(txhash_maybe).get("txhash") or "") if "txhash" in txhash_maybe else ""
1154+
return txhash
1155+
11481156
def submit_tx(
11491157
self, tx_file: itp.FileType, txins: tp.List[structs.UTXOData], wait_blocks: int = 2
1150-
) -> None:
1158+
) -> str:
11511159
"""Submit a transaction, resubmit if the transaction didn't make it to the chain.
11521160
11531161
Args:
11541162
tx_file: A path to signed transaction file.
11551163
txins: An iterable of `structs.UTXOData`, specifying input UTxOs.
11561164
wait_blocks: A number of new blocks to wait for (default = 2).
1165+
1166+
Returns:
1167+
str: A transaction ID.
11571168
"""
11581169
txid = ""
11591170
for r in range(20):
11601171
err = None
11611172

11621173
if r == 0:
1163-
self.submit_tx_bare(tx_file)
1174+
txid = self.submit_tx_bare(tx_file)
11641175
else:
11651176
txid = txid or self.get_txid(tx_file=tx_file)
11661177
LOGGER.warning(f"Resubmitting transaction '{txid}' (from '{tx_file}').")
@@ -1193,6 +1204,8 @@ def submit_tx(
11931204
msg = f"Transaction '{txid}' didn't make it to the chain (from '{tx_file}')."
11941205
raise exceptions.CLIError(msg)
11951206

1207+
return txid
1208+
11961209
def send_tx(
11971210
self,
11981211
src_address: str,

0 commit comments

Comments
 (0)