Skip to content

Commit

Permalink
fix(github): hardcoding auth
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0elliot committed Dec 8, 2023
1 parent d5d6970 commit 100d21b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
55 changes: 36 additions & 19 deletions backend/api_app/monitoring/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion backend/api_app/smartcontract/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions backend/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down

0 comments on commit 100d21b

Please sign in to comment.