|
| 1 | +from typing import Any, Dict, Optional, Protocol |
| 2 | + |
| 3 | +from multiversx_sdk_network_providers import GenericError, ProxyNetworkProvider |
| 4 | + |
| 5 | +from multiversx_sdk_cli.errors import ProxyError |
| 6 | +from multiversx_sdk_cli.interfaces import ISimulateResponse, ITransaction |
| 7 | + |
| 8 | + |
| 9 | +class ITransactionOnNetwork(Protocol): |
| 10 | + hash: str |
| 11 | + is_completed: Optional[bool] |
| 12 | + |
| 13 | + def to_dictionary(self) -> Dict[str, Any]: |
| 14 | + ... |
| 15 | + |
| 16 | + |
| 17 | +class CustomNetworkProvider: |
| 18 | + def __init__(self, url: str) -> None: |
| 19 | + self._provider = ProxyNetworkProvider(url) |
| 20 | + |
| 21 | + def send_transaction(self, transaction: ITransaction) -> str: |
| 22 | + try: |
| 23 | + hash = self._provider.send_transaction(transaction) |
| 24 | + return hash |
| 25 | + except GenericError as ge: |
| 26 | + url = ge.url |
| 27 | + message = ge.data.get("error", "") |
| 28 | + data = ge.data.get("data", "") |
| 29 | + code = ge.data.get("code", "") |
| 30 | + raise ProxyError(message, url, data, code) |
| 31 | + |
| 32 | + def get_transaction(self, tx_hash: str, with_process_status: Optional[bool] = False) -> ITransactionOnNetwork: |
| 33 | + return self._provider.get_transaction(tx_hash, with_process_status) |
| 34 | + |
| 35 | + def simulate_transaction(self, transaction: ITransaction) -> ISimulateResponse: |
| 36 | + return self._provider.simulate_transaction(transaction) |
0 commit comments