Skip to content

Commit 8069fb6

Browse files
committed
(feat) Implemented OFAC list address check
1 parent 5541211 commit 8069fb6

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

pyinjective/core/broadcaster.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from decimal import Decimal
44
from typing import List, Optional
55

6+
import requests
67
from google.protobuf import any_pb2
78
from grpc import RpcError
89

@@ -12,6 +13,9 @@
1213
from pyinjective.constant import GAS_PRICE
1314
from pyinjective.core.gas_limit_estimator import GasLimitEstimator
1415
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"
1519

1620

1721
class BroadcasterAccountConfig(ABC):
@@ -62,6 +66,17 @@ def __init__(
6266
self._client = client
6367
self._composer = composer
6468
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}")
6580

6681
@classmethod
6782
def new_using_simulation(
@@ -157,6 +172,10 @@ async def broadcast(self, messages: List[any_pb2.Any]):
157172

158173
messages_for_transaction = self._account_config.messages_prepared_for_transaction(messages=messages)
159174

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+
160179
transaction = Transaction()
161180
transaction.with_messages(*messages_for_transaction)
162181
transaction.with_sequence(self._client.get_sequence())

pyinjective/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ class ConvertError(PyInjectiveError):
2828

2929
class SchemaError(PyInjectiveError):
3030
pass
31+
32+
33+
class BannedAddressError(PyInjectiveError):
34+
pass
35+
36+
37+
class OfacListFetchError(PyInjectiveError):
38+
pass

0 commit comments

Comments
 (0)