Spaces:
Sleeping
Sleeping
Update components/middleware.py
Browse files- components/middleware.py +47 -1
components/middleware.py
CHANGED
|
@@ -40,6 +40,52 @@ def SecretNonceGenerator():
|
|
| 40 |
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def TokenCheck(walletPublicKey, api_key, required_mint,mint_amount):
|
| 44 |
|
| 45 |
url = f"https://mainnet.helius-rpc.com/?api-key={api_key}"
|
|
@@ -93,7 +139,7 @@ def TokenCheck(walletPublicKey, api_key, required_mint,mint_amount):
|
|
| 93 |
return False
|
| 94 |
|
| 95 |
|
| 96 |
-
|
| 97 |
|
| 98 |
|
| 99 |
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def TokenCheck(walletPublicKey, api_key, required_mint, mint_amount):
|
| 47 |
+
|
| 48 |
+
url = f"https://mainnet.helius-rpc.com/?api-key={api_key}"
|
| 49 |
+
payload = {
|
| 50 |
+
"jsonrpc": "2.0",
|
| 51 |
+
"id": "1",
|
| 52 |
+
"method": "getTokenAccountsByOwner",
|
| 53 |
+
"params": [
|
| 54 |
+
walletPublicKey,
|
| 55 |
+
{"mint": required_mint},
|
| 56 |
+
{"encoding": "jsonParsed"}
|
| 57 |
+
]
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
try:
|
| 61 |
+
response = requests.post(url, json=payload)
|
| 62 |
+
response.raise_for_status()
|
| 63 |
+
data = response.json()
|
| 64 |
+
except:
|
| 65 |
+
return False # always boolean
|
| 66 |
+
|
| 67 |
+
token_accounts = data.get("result", {}).get("value", [])
|
| 68 |
+
if not token_accounts:
|
| 69 |
+
return False
|
| 70 |
+
|
| 71 |
+
try:
|
| 72 |
+
token_amount = token_accounts[0]["account"]["data"]["parsed"]["info"]["tokenAmount"]
|
| 73 |
+
|
| 74 |
+
# reliable extraction
|
| 75 |
+
if token_amount["uiAmount"] is not None:
|
| 76 |
+
ui_amount = float(token_amount["uiAmount"])
|
| 77 |
+
else:
|
| 78 |
+
ui_amount = float(token_amount["uiAmountString"])
|
| 79 |
+
|
| 80 |
+
except:
|
| 81 |
+
return False # ALWAYS return strict boolean
|
| 82 |
+
|
| 83 |
+
# compare as float
|
| 84 |
+
return ui_amount >= float(mint_amount)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
'''
|
| 89 |
def TokenCheck(walletPublicKey, api_key, required_mint,mint_amount):
|
| 90 |
|
| 91 |
url = f"https://mainnet.helius-rpc.com/?api-key={api_key}"
|
|
|
|
| 139 |
return False
|
| 140 |
|
| 141 |
|
| 142 |
+
'''
|
| 143 |
|
| 144 |
|
| 145 |
|