mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
fix: pass cookies to AsyncClient instead of per-request
Fixes httpx DeprecationWarning: Setting per-request cookies is deprecated. Cookies are now set on the AsyncClient instance and removed from all individual post() calls and internal function signatures.
This commit is contained in:
+4
-9
@@ -26,19 +26,16 @@ HEADERS: dict[str, str] = {
|
||||
async def search_ads_recipient(
|
||||
client: httpx.AsyncClient,
|
||||
fragment_hash: str,
|
||||
cookies: dict,
|
||||
username: str,
|
||||
) -> str:
|
||||
await client.post(
|
||||
f"https://fragment.com/api?hash={fragment_hash}",
|
||||
headers=HEADERS,
|
||||
cookies=cookies,
|
||||
data={"mode": "new", "method": "updateAdsTopupState"},
|
||||
)
|
||||
resp = await client.post(
|
||||
f"https://fragment.com/api?hash={fragment_hash}",
|
||||
headers=HEADERS,
|
||||
cookies=cookies,
|
||||
data={"query": username, "method": "searchAdsTopupRecipient"},
|
||||
)
|
||||
result = parse_json_response(resp, "searchAdsTopupRecipient")
|
||||
@@ -54,14 +51,12 @@ async def search_ads_recipient(
|
||||
async def init_ads_topup(
|
||||
client: httpx.AsyncClient,
|
||||
fragment_hash: str,
|
||||
cookies: dict,
|
||||
recipient: str,
|
||||
amount: int,
|
||||
) -> str:
|
||||
resp = await client.post(
|
||||
f"https://fragment.com/api?hash={fragment_hash}",
|
||||
headers=HEADERS,
|
||||
cookies=cookies,
|
||||
data={"recipient": recipient, "amount": amount, "method": "initAdsTopupRequest"},
|
||||
)
|
||||
result = parse_json_response(resp, "initAdsTopupRequest")
|
||||
@@ -88,12 +83,12 @@ async def topup_ton(username: str, amount: int) -> dict:
|
||||
# logger.info("Retrieving TON wallet info")
|
||||
account = await get_account_info()
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
async with httpx.AsyncClient(cookies=cookies) as client:
|
||||
logger.info("Searching recipient: %s", username)
|
||||
recipient = await search_ads_recipient(client, fragment_hash, cookies, username)
|
||||
recipient = await search_ads_recipient(client, fragment_hash, username)
|
||||
|
||||
logger.info("Initializing topup request: %s TON to %s", amount, username)
|
||||
req_id = await init_ads_topup(client, fragment_hash, cookies, recipient, amount)
|
||||
req_id = await init_ads_topup(client, fragment_hash, recipient, amount)
|
||||
|
||||
# logger.info("Requesting transaction payload (req_id=%s)", req_id)
|
||||
tx_data = {
|
||||
@@ -105,7 +100,7 @@ async def topup_ton(username: str, amount: int) -> dict:
|
||||
"method": "getAdsTopupLink",
|
||||
}
|
||||
transaction = await execute_transaction_request(
|
||||
client, HEADERS, cookies, account, tx_data, fragment_hash
|
||||
client, HEADERS, account, tx_data, fragment_hash
|
||||
)
|
||||
|
||||
logger.info("Broadcasting transaction to TON blockchain")
|
||||
|
||||
Reference in New Issue
Block a user