mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
6dd9dcb5d4
- Refactor `get_wallet()` to return `ton_balance` and `usdt_balance` in `WalletInfo`. - Update transaction processing to validate balances for both TON and USDT payment methods. - Introduce `parse_required_payment_amount` utility to extract payment amounts from responses. - Modify tests to cover new balance checks and payment method handling. - Upgrade GitHub Actions artifact upload action to v7. - Enhance documentation and examples to reflect changes in wallet balance handling.
97 lines
3.4 KiB
Python
97 lines
3.4 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import Any, Literal, get_args
|
|
|
|
from tonutils.contracts.wallet import WalletV4R2, WalletV5R1
|
|
|
|
# Payment methods
|
|
PaymentMethod = Literal["ton", "usdt_ton"]
|
|
SUPPORTED_PAYMENT_METHODS: frozenset[str] = frozenset(get_args(PaymentMethod))
|
|
|
|
# Single source of truth for supported wallet versions
|
|
WalletVersion = Literal["V4R2", "V5R1"]
|
|
SUPPORTED_WALLET_VERSIONS: frozenset[str] = frozenset(get_args(WalletVersion))
|
|
|
|
# Wallet class map — used to resolve the correct contract from WALLET_VERSION
|
|
WALLET_CLASSES: dict[str, Any] = {"V4R2": WalletV4R2, "V5R1": WalletV5R1}
|
|
|
|
# Minimum minimum TON balance required for payments (transaction amount + gas reserve).
|
|
MIN_TON_BALANCE: float = 0.33 # 0.3 TON for transaction + 0.03 TON gas reserve
|
|
|
|
# USDT (TON) jetton metadata used for payment-method balance checks.
|
|
USDT_TON_MASTER_ADDRESS: str = "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs"
|
|
MIN_USDT_BALANCE: float = 0.75
|
|
|
|
# Default HTTP request timeout in seconds.
|
|
DEFAULT_TIMEOUT: float = 30.0
|
|
|
|
# Required Fragment session cookie keys
|
|
REQUIRED_COOKIE_KEYS: tuple[str, ...] = ("stel_ssid", "stel_dt", "stel_token", "stel_ton_token")
|
|
|
|
# Fragment domain and page URLs
|
|
FRAGMENT_DOMAIN: str = "fragment.com" # for rookiepy
|
|
FRAGMENT_BASE_URL: str = f"https://{FRAGMENT_DOMAIN}"
|
|
STARS_PAGE: str = f"{FRAGMENT_BASE_URL}/stars/buy"
|
|
STARS_GIVEAWAY_PAGE: str = f"{FRAGMENT_BASE_URL}/stars/giveaway"
|
|
PREMIUM_PAGE: str = f"{FRAGMENT_BASE_URL}/premium/gift"
|
|
PREMIUM_GIVEAWAY_PAGE: str = f"{FRAGMENT_BASE_URL}/premium/giveaway"
|
|
ADS_TOPUP_PAGE: str = f"{FRAGMENT_BASE_URL}/ads/topup"
|
|
NUMBERS_PAGE: str = f"{FRAGMENT_BASE_URL}/numbers"
|
|
GIFTS_PAGE: str = f"{FRAGMENT_BASE_URL}/gifts"
|
|
|
|
# Browsers supported by get_cookies_from_browser()
|
|
SUPPORTED_BROWSERS: frozenset[str] = frozenset(
|
|
{
|
|
"arc",
|
|
"brave",
|
|
"chrome",
|
|
"chromium",
|
|
"chromium_based",
|
|
"edge",
|
|
"firefox",
|
|
"firefox_based",
|
|
"librewolf",
|
|
"opera",
|
|
"opera_gx",
|
|
"safari",
|
|
"vivaldi",
|
|
}
|
|
)
|
|
|
|
# Tonkeeper device fingerprint — serialized once, reused in every tx_data payload.
|
|
DEVICE: str = json.dumps(
|
|
{
|
|
"platform": "iphone",
|
|
"appName": "Tonkeeper",
|
|
"appVersion": "26.04.0",
|
|
"maxProtocolVersion": 2,
|
|
"features": [
|
|
"SendTransaction",
|
|
{"name": "SendTransaction", "maxMessages": 255},
|
|
{"name": "SignData", "types": ["text", "binary", "cell"]},
|
|
],
|
|
}
|
|
)
|
|
|
|
# Base HTTP headers — shared across all Fragment API requests.
|
|
# Each method merges these with its own "referer" and "x-aj-referer".
|
|
BASE_HEADERS: dict[str, str] = {
|
|
"accept": "application/json, text/javascript, */*; q=0.01",
|
|
"accept-language": "en-US,en;q=0.9,uk;q=0.8,ru;q=0.7",
|
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
"origin": FRAGMENT_BASE_URL,
|
|
"priority": "u=1, i",
|
|
"sec-ch-ua": '"Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147"',
|
|
"sec-ch-ua-mobile": "?1",
|
|
"sec-ch-ua-platform": '"Android"',
|
|
"sec-fetch-dest": "empty",
|
|
"sec-fetch-mode": "cors",
|
|
"sec-fetch-site": "same-origin",
|
|
"user-agent": (
|
|
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) "
|
|
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Mobile Safari/537.36"
|
|
),
|
|
"x-requested-with": "XMLHttpRequest",
|
|
}
|