Skip to content

Commit

Permalink
fix: making airstack identities work ❤️
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0elliot committed Jan 30, 2024
1 parent 0b6287d commit 584ff8a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
29 changes: 29 additions & 0 deletions backend/api_app/monitoring/integrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import requests

# move this to a separate file later
def airstack_identities(self, wallet: str) -> dict:
url = "https://api.airstack.xyz/gql"

headers = {
"authorization": os.environ.get("AIRSTACK_API_KEY"),
"content-type": "application/json",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
}

query = f'{{"query":"query MyQuery {{ Wallet(input: {{identity: \\"{wallet}\\", blockchain: ethereum}}) {{ identity socials {{ dappName profileName }} }} }}","operationName":"MyQuery"}}'

response = requests.post(url, headers=headers, data=query)

if response.status_code == 200:
data = response.json()
wallet_data = data.get("data", {}).get("Wallet", {})

identity = wallet_data.get("identity", "")
socials = wallet_data.get("socials", [])

result = {"identity": identity, "socials": socials}

return result
else:
return {"error": f"Error: {response.status_code} - {response.text}"}
36 changes: 6 additions & 30 deletions backend/api_app/monitoring/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,10 @@
ContractFunctionError,
)
from api_app.monitoring.models import Alerts, Notification
from api_app.monitoring.integrations import airstack_identities

logger = logging.getLogger(__name__)


def airstack_identities(wallet: str) -> dict:
url = "https://api.airstack.xyz/gql"

headers = {
"authorization": os.environ.get("AIRSTACK_API_KEY"),
"content-type": "application/json",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
}

query = f'{{"query":"query MyQuery {{ Wallet(input: {{identity: \\"{wallet}\\", blockchain: ethereum}}) {{ identity socials {{ dappName profileName }} }} }}","operationName":"MyQuery"}}'

response = requests.post(url, headers=headers, data=query)

if response.status_code == 200:
data = response.json()
wallet_data = data.get("data", {}).get("Wallet", {})

identity = wallet_data.get("identity", "")
socials = wallet_data.get("socials", [])

result = {"identity": identity, "socials": socials}

return result
else:
return {"error": f"Error: {response.status_code} - {response.text}"}


class Transaction:
def __init__(self, transaction_data):
# base class for all transactions
Expand Down Expand Up @@ -108,7 +81,7 @@ def __init__(self, transaction_data):
"s": self.s,
"timestamp": self.timestamp,
"output": self.output,
"airstack_identities": airstack_identities,
# "airstack_identities": airstack_identities(),
}


Expand Down Expand Up @@ -235,7 +208,7 @@ def run(self):
else:
# condition not met
pass

def trigger_automations(self, automations):
abi = self.Alert.smart_contract.abi

Expand Down Expand Up @@ -273,6 +246,7 @@ def check_alert_condition(self, alert) -> bool:

variables = {
"txn": txn_or_block,
"airstack_identities": airstack_identities,
}

if condition is None:
Expand Down Expand Up @@ -331,6 +305,8 @@ def send_webhook(self, alert_data):
"transaction": self.transaction.compile_to_dict(),
}

logger.info("[INFO] Alert body: " + str(alert_body))

notification = Notification.objects.create(
alert=self.Alert,
notification_type="send_webhook",
Expand Down

0 comments on commit 584ff8a

Please sign in to comment.