mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 14:24:31 +00:00
efcdda6b74
- Migrate from tonutils 0.5.x to 2.0.0 API: - ToncenterClient → TonapiClient with NetworkGlobalID - tonutils.client → tonutils.clients - tonutils.wallet → tonutils.contracts.wallet - pub_key.as_hex property, wallet.balance nanotons - async with client context manager - Centralize TON client init into initialize_ton_client() in wallet.py - Move process_transaction logic into wallet.py, transaction.py re-exports - Add WALLET_VERSION config (V4R2/V5R1, default V5R1) - Add WALLET_CLASSES and SUPPORTED_WALLET_VERSIONS to constants.py - Restore balance check before broadcasting - Wait for seqno confirmation after transfer (120×2s) to prevent duplicate seqno - Fix Fragment hash fetching: use browser navigation headers - Remove accept-encoding from BASE_HEADERS (httpx handles decompression) - Add cookies.example.json template - Add cookies.json to .gitignore
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import logging
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Literal
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from app.core.constants import SUPPORTED_WALLET_VERSIONS
|
|
from app.core.exceptions import ConfigError
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
WalletVersion = Literal["V4R2", "V5R1"]
|
|
|
|
|
|
class Config:
|
|
SEED: str
|
|
API_KEY: str
|
|
WALLET_VERSION: WalletVersion
|
|
|
|
def __init__(self) -> None:
|
|
# Load .env if present; env vars already in the process take precedence
|
|
env_path = Path(__file__).resolve().parents[2] / ".env"
|
|
if env_path.exists():
|
|
load_dotenv(env_path)
|
|
|
|
missing = [k for k in ("SEED", "API_KEY") if not os.getenv(k, "").strip()]
|
|
if missing:
|
|
raise ConfigError(
|
|
f"Missing required environment variables: {', '.join(missing)}. "
|
|
"Copy .env.example to .env and fill in SEED and API_KEY."
|
|
)
|
|
|
|
self.SEED = os.getenv("SEED", "").strip()
|
|
self.API_KEY = os.getenv("API_KEY", "").strip()
|
|
|
|
version = os.getenv("WALLET_VERSION", "V5R1").strip().upper()
|
|
if version not in SUPPORTED_WALLET_VERSIONS:
|
|
raise ConfigError(
|
|
f"Unsupported WALLET_VERSION '{version}'. "
|
|
f"Must be one of: {', '.join(sorted(SUPPORTED_WALLET_VERSIONS))}."
|
|
)
|
|
self.WALLET_VERSION: WalletVersion = version # type: ignore[assignment]
|
|
|
|
|
|
config: Config | None = None
|
|
try:
|
|
config = Config()
|
|
except ConfigError as e:
|
|
logger.warning("Configuration not loaded: %s", e)
|