Spaces:
Sleeping
Sleeping
Update components/middleware.py
Browse files- components/middleware.py +8 -87
components/middleware.py
CHANGED
|
@@ -42,61 +42,23 @@ def SecretNonceGenerator():
|
|
| 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 |
-
|
| 90 |
-
|
|
|
|
| 91 |
|
| 92 |
-
url = f"https://mainnet.helius-rpc.com/?api-key=
|
| 93 |
payload = {
|
| 94 |
"jsonrpc": "2.0",
|
| 95 |
"id": "1",
|
| 96 |
"method": "getTokenAccountsByOwner",
|
| 97 |
"params": [
|
| 98 |
walletPublicKey,
|
| 99 |
-
{"mint":
|
| 100 |
{"encoding": "jsonParsed"}
|
| 101 |
]
|
| 102 |
}
|
|
@@ -130,59 +92,18 @@ def TokenCheck(walletPublicKey, api_key, required_mint,mint_amount):
|
|
| 130 |
|
| 131 |
return {"status": False, "message": "Could not parse token account data"}
|
| 132 |
|
| 133 |
-
if ui_amount >=
|
| 134 |
|
| 135 |
print(ui_amount)
|
| 136 |
return True
|
| 137 |
|
| 138 |
else:
|
| 139 |
-
|
| 140 |
return False
|
| 141 |
|
| 142 |
|
| 143 |
-
'''
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
async def TokenCheck(address):
|
| 151 |
-
|
| 152 |
-
url = "https://mainnet.helius-rpc.com/?api-key=4e833ada-d32c-48c5-b020-c11b2253f25b"
|
| 153 |
-
payload = {
|
| 154 |
-
"jsonrpc": "2.0",
|
| 155 |
-
"id": "1",
|
| 156 |
-
"method": "getTokenAccountsByOwner",
|
| 157 |
-
"params": [
|
| 158 |
-
address,
|
| 159 |
-
{"mint": "3d4XyPWkUJzruF5c2qc1QfpLgsaNaDLMtTya1bWBpump"},
|
| 160 |
-
{"encoding": "jsonParsed"}
|
| 161 |
-
],
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
try:
|
| 165 |
-
async with httpx.AsyncClient() as client:
|
| 166 |
-
response = await client.post(url, json=payload)
|
| 167 |
-
response.raise_for_status()
|
| 168 |
-
data = response.json()
|
| 169 |
-
except Exception:
|
| 170 |
-
return False
|
| 171 |
-
|
| 172 |
-
token_accounts = data.get("result", {}).get("value")
|
| 173 |
-
|
| 174 |
-
if not token_accounts:
|
| 175 |
-
return False
|
| 176 |
|
| 177 |
-
try:
|
| 178 |
-
account_info = token_accounts[0]["account"]["data"]["parsed"]["info"]
|
| 179 |
-
token_amount = account_info["tokenAmount"]
|
| 180 |
-
ui_amount = token_amount.get("uiAmount")
|
| 181 |
-
except:
|
| 182 |
-
return False
|
| 183 |
|
| 184 |
-
print(ui_amount)
|
| 185 |
-
return ui_amount >= 100000.0
|
| 186 |
|
| 187 |
|
| 188 |
|
|
@@ -256,7 +177,7 @@ class x401Kit(BaseHTTPMiddleware):
|
|
| 256 |
challange=f"CHALLENGE::{X_401_Nonce}::{request.url.path}::{self.secret_domain}"
|
| 257 |
|
| 258 |
signverify=SignatureVerification(X_401_Addr,X_401_Nonce,X_401_Sign,challange)
|
| 259 |
-
tokenverify=
|
| 260 |
print(tokenverify)
|
| 261 |
|
| 262 |
if signverify == True and tokenverify == True:
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
|
|
|
|
|
|
| 46 |
|
|
|
|
|
|
|
| 47 |
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def TokenCheck(walletPublicKey):
|
| 53 |
|
| 54 |
+
url = f"https://mainnet.helius-rpc.com/?api-key=4e833ada-d32c-48c5-b020-c11b2253f25b"
|
| 55 |
payload = {
|
| 56 |
"jsonrpc": "2.0",
|
| 57 |
"id": "1",
|
| 58 |
"method": "getTokenAccountsByOwner",
|
| 59 |
"params": [
|
| 60 |
walletPublicKey,
|
| 61 |
+
{"mint":"3d4XyPWkUJzruF5c2qc1QfpLgsaNaDLMtTya1bWBpump" },
|
| 62 |
{"encoding": "jsonParsed"}
|
| 63 |
]
|
| 64 |
}
|
|
|
|
| 92 |
|
| 93 |
return {"status": False, "message": "Could not parse token account data"}
|
| 94 |
|
| 95 |
+
if ui_amount >= 100000.0:
|
| 96 |
|
| 97 |
print(ui_amount)
|
| 98 |
return True
|
| 99 |
|
| 100 |
else:
|
| 101 |
+
print(ui_amount)
|
| 102 |
return False
|
| 103 |
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
|
|
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
|
|
|
|
| 177 |
challange=f"CHALLENGE::{X_401_Nonce}::{request.url.path}::{self.secret_domain}"
|
| 178 |
|
| 179 |
signverify=SignatureVerification(X_401_Addr,X_401_Nonce,X_401_Sign,challange)
|
| 180 |
+
tokenverify=TokenCheck(X_401_Addr)
|
| 181 |
print(tokenverify)
|
| 182 |
|
| 183 |
if signverify == True and tokenverify == True:
|