Skip to content

Commit

Permalink
(feat) Implemented OFAC list address check
Browse files Browse the repository at this point in the history
  • Loading branch information
shibaeff committed Sep 6, 2024
1 parent 5541211 commit 8069fb6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pyinjective/core/broadcaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from decimal import Decimal
from typing import List, Optional

import requests
from google.protobuf import any_pb2
from grpc import RpcError

Expand All @@ -12,6 +13,9 @@
from pyinjective.constant import GAS_PRICE
from pyinjective.core.gas_limit_estimator import GasLimitEstimator
from pyinjective.core.network import Network
from pyinjective.exceptions import BannedAddressError, OfacListFetchError

OFAC_LIST_URL = "https://raw.githubusercontent.com/InjectiveLabs/injective-lists/master/wallets/ofac.json"


class BroadcasterAccountConfig(ABC):
Expand Down Expand Up @@ -62,6 +66,17 @@ def __init__(
self._client = client
self._composer = composer
self._fee_calculator = fee_calculator
self._ofac_list = self.load_ofac_list()

@classmethod
def load_ofac_list(cls) -> List[str]:
try:
response = requests.get(OFAC_LIST_URL)
response.raise_for_status()
ofac_list = response.json()
return ofac_list
except requests.exceptions.RequestException as e:
raise OfacListFetchError(f"Error fetching OFAC list: {e}")

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

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

# before contraucting the transaction, check if sender address is in the OFAC list
if self._account_config.trading_injective_address in self._ofac_list:
raise BannedAddressError(f"Address {self._account_config.trading_injective_address} is in the OFAC list")

transaction = Transaction()
transaction.with_messages(*messages_for_transaction)
transaction.with_sequence(self._client.get_sequence())
Expand Down
8 changes: 8 additions & 0 deletions pyinjective/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ class ConvertError(PyInjectiveError):

class SchemaError(PyInjectiveError):
pass


class BannedAddressError(PyInjectiveError):
pass


class OfacListFetchError(PyInjectiveError):
pass

0 comments on commit 8069fb6

Please sign in to comment.