|
3 | 3 | from dataclasses import dataclass |
4 | 4 | from typing import Dict, List, Union |
5 | 5 |
|
| 6 | +from pycardano.exception import InvalidArgumentException |
6 | 7 | from pycardano.address import Address |
7 | 8 | from pycardano.network import Network |
8 | 9 | from pycardano.plutus import ExecutionUnits |
@@ -158,17 +159,24 @@ def _utxos(self, address: str) -> List[UTxO]: |
158 | 159 | """ |
159 | 160 | raise NotImplementedError() |
160 | 161 |
|
161 | | - def submit_tx(self, tx: Transaction): |
| 162 | + def submit_tx(self, tx: Union[Transaction, bytes, str]): |
162 | 163 | """Submit a transaction to the blockchain. |
163 | 164 |
|
164 | 165 | Args: |
165 | | - tx (Transaction): The transaction to be submitted. |
| 166 | + tx (Union[Transaction, bytes, str]): The transaction to be submitted. |
166 | 167 |
|
167 | 168 | Raises: |
168 | 169 | :class:`InvalidArgumentException`: When the transaction is invalid. |
169 | 170 | :class:`TransactionFailedException`: When fails to submit the transaction to blockchain. |
170 | 171 | """ |
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 | + ) |
172 | 180 |
|
173 | 181 | def submit_tx_cbor(self, cbor: Union[bytes, str]): |
174 | 182 | """Submit a transaction to the blockchain. |
|
0 commit comments