Skip to content

Commit 2317c57

Browse files
authored
Accept cbor and str as input type in submit_tx (#231)
Making submit_tx backward compatible.
1 parent 93fd889 commit 2317c57

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pycardano/backend/base.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dataclasses import dataclass
44
from typing import Dict, List, Union
55

6+
from pycardano.exception import InvalidArgumentException
67
from pycardano.address import Address
78
from pycardano.network import Network
89
from pycardano.plutus import ExecutionUnits
@@ -158,17 +159,24 @@ def _utxos(self, address: str) -> List[UTxO]:
158159
"""
159160
raise NotImplementedError()
160161

161-
def submit_tx(self, tx: Transaction):
162+
def submit_tx(self, tx: Union[Transaction, bytes, str]):
162163
"""Submit a transaction to the blockchain.
163164
164165
Args:
165-
tx (Transaction): The transaction to be submitted.
166+
tx (Union[Transaction, bytes, str]): The transaction to be submitted.
166167
167168
Raises:
168169
:class:`InvalidArgumentException`: When the transaction is invalid.
169170
:class:`TransactionFailedException`: When fails to submit the transaction to blockchain.
170171
"""
171-
return self.submit_tx_cbor(tx.to_cbor("bytes"))
172+
if isinstance(tx, Transaction):
173+
return self.submit_tx_cbor(tx.to_cbor("bytes"))
174+
elif isinstance(tx, bytes):
175+
return self.submit_tx_cbor(tx)
176+
else:
177+
raise InvalidArgumentException(
178+
f"Invalid transaction type: {type(tx)}, expected Transaction, bytes, or str"
179+
)
172180

173181
def submit_tx_cbor(self, cbor: Union[bytes, str]):
174182
"""Submit a transaction to the blockchain.

0 commit comments

Comments
 (0)