From 100d21b333d2b2090812064b4ec9b542378074a6 Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Sat, 9 Dec 2023 02:47:09 +0530 Subject: [PATCH] fix(github): hardcoding auth --- backend/api_app/monitoring/tasks.py | 55 ++++++++++++++++--------- backend/api_app/smartcontract/models.py | 4 +- backend/authentication/views.py | 1 + backend/backend/settings.py | 4 ++ 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/backend/api_app/monitoring/tasks.py b/backend/api_app/monitoring/tasks.py index b2ca4db..2e29c19 100644 --- a/backend/api_app/monitoring/tasks.py +++ b/backend/api_app/monitoring/tasks.py @@ -118,29 +118,41 @@ def monitor_contract(self, monitoring_task_id): logger.error(error_msg) raise Exception(error_msg) - network_id = settings.ETH_NETWORK_IDS.get(network) - if not network_id: - error_msg = f"Network {network} not supported" - logger.error(error_msg) - raise Exception(error_msg) + # network_id = settings.ETH_NETWORK_IDS.get(network) + # if not network_id: + # error_msg = f"Network {network} not supported" + # logger.error(error_msg) + # raise Exception(error_msg) w3 = Web3(Web3.WebsocketProvider(rpc_url)) w3.middleware_onion.inject(geth_poa_middleware, layer=0) - if network_id != int(w3.net.version): - raise ValueError("Connected to the wrong Ethereum network") + # if network_id != int(w3.net.version): + # raise ValueError("Connected to the wrong Ethereum network") ws = websocket.create_connection(rpc_url) - subscribe_data = { - "id": 1, - "jsonrpc": "2.0", - "method": "eth_subscribe", - "params": [ - "alchemy_pendingTransactions", - {"address": contract_address, "fromBlock": "latest"}, - ], - } + if chain == "eth": + subscribe_data = { + "id": 1, + "jsonrpc": "2.0", + "method": "eth_subscribe", + "params": [ + "alchemy_pendingTransactions", + {"address": contract_address, "fromBlock": "latest"}, + ], + } + elif chain == "arb": + subscribe_data = { + "id": 1, + "jsonrpc": "2.0", + "method": "eth_subscribe", + "params": [ + "alchemy_minedTransactions", + {"address": contract_address, "fromBlock": "latest"}, + ], + } + ws.send(json.dumps(subscribe_data)) subscription_id = None @@ -216,14 +228,19 @@ def trace_transaction(transaction_hash): message = ws.recv() response = json.loads(message) - if "result" in response and response.get("id") == 1: + if "result" in response and response.get("id") == 1 and chain == "eth": subscription_id = response["result"] elif ( subscription_id and "params" in response and response["params"]["subscription"] == subscription_id - ): - transaction_hash = response["params"]["result"]["hash"] + ) or ( + "result" in response + ): # this is for the arb chain + transaction_hash = response.get("hash") + if "eth" in chain: + transaction_hash = response["params"]["result"]["hash"] + transaction = fetch_transaction_details(transaction_hash) # fetch alerts from the database # run the alerts diff --git a/backend/api_app/smartcontract/models.py b/backend/api_app/smartcontract/models.py index e041fb5..975de6d 100644 --- a/backend/api_app/smartcontract/models.py +++ b/backend/api_app/smartcontract/models.py @@ -7,9 +7,11 @@ User = get_user_model() -# chain choices enum: "ETH", "BSC", "POLYGON" +# chain choices enum: "ETH", "ARB" class Chain(models.TextChoices): ETH = "ETH", "eth" + ARB = "ARB", "arb" + class Network(models.TextChoices): diff --git a/backend/authentication/views.py b/backend/authentication/views.py index cc40146..5c8b1c5 100644 --- a/backend/authentication/views.py +++ b/backend/authentication/views.py @@ -174,6 +174,7 @@ def github_login(request): if settings.DEMO_INSTANCE: redirect_uri = redirect_uri.replace("http://", "https://") + redirect_uri = "https://demo.thirdeyelabs.xyz/api/authentication/github-callback" try: return oauth.github.authorize_redirect(request, redirect_uri) diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 11562c9..031bce9 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -25,12 +25,16 @@ GOERLI_RPC_URL = os.environ.get("GOERLI_RPC_URL", "") MAINNET_RPC_URL = os.environ.get("MAINNET_RPC_URL", "") +ARBITRUM_RPC_URL = os.environ.get("ARBITRUM_RPC_URL", "") # mapping of URLs to different ethereum based chains and networks CHAINS_AND_NETWORKS = { "eth": { "mainnet": MAINNET_RPC_URL, "goerli": GOERLI_RPC_URL, + }, + "arb": { + "mainnet": ARBITRUM_RPC_URL, } }