|
3 | 3 | from decimal import Decimal |
4 | 4 | from typing import List, Optional |
5 | 5 |
|
| 6 | +import requests |
6 | 7 | from google.protobuf import any_pb2 |
7 | 8 | from grpc import RpcError |
8 | 9 |
|
|
12 | 13 | from pyinjective.constant import GAS_PRICE |
13 | 14 | from pyinjective.core.gas_limit_estimator import GasLimitEstimator |
14 | 15 | from pyinjective.core.network import Network |
| 16 | +from pyinjective.exceptions import BannedAddressError, OfacListFetchError |
| 17 | + |
| 18 | +OFAC_LIST_URL = "https://raw.githubusercontent.com/InjectiveLabs/injective-lists/master/wallets/ofac.json" |
15 | 19 |
|
16 | 20 |
|
17 | 21 | class BroadcasterAccountConfig(ABC): |
@@ -62,6 +66,17 @@ def __init__( |
62 | 66 | self._client = client |
63 | 67 | self._composer = composer |
64 | 68 | self._fee_calculator = fee_calculator |
| 69 | + self._ofac_list = self.load_ofac_list() |
| 70 | + |
| 71 | + @classmethod |
| 72 | + def load_ofac_list(cls) -> List[str]: |
| 73 | + try: |
| 74 | + response = requests.get(OFAC_LIST_URL) |
| 75 | + response.raise_for_status() |
| 76 | + ofac_list = response.json() |
| 77 | + return ofac_list |
| 78 | + except requests.exceptions.RequestException as e: |
| 79 | + raise OfacListFetchError(f"Error fetching OFAC list: {e}") |
65 | 80 |
|
66 | 81 | @classmethod |
67 | 82 | def new_using_simulation( |
@@ -157,6 +172,10 @@ async def broadcast(self, messages: List[any_pb2.Any]): |
157 | 172 |
|
158 | 173 | messages_for_transaction = self._account_config.messages_prepared_for_transaction(messages=messages) |
159 | 174 |
|
| 175 | + # before contraucting the transaction, check if sender address is in the OFAC list |
| 176 | + if self._account_config.trading_injective_address in self._ofac_list: |
| 177 | + raise BannedAddressError(f"Address {self._account_config.trading_injective_address} is in the OFAC list") |
| 178 | + |
160 | 179 | transaction = Transaction() |
161 | 180 | transaction.with_messages(*messages_for_transaction) |
162 | 181 | transaction.with_sequence(self._client.get_sequence()) |
|
0 commit comments