mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
from typing import Dict, Any, Tuple
|
|
|
|
import httpx
|
|
|
|
|
|
class ApiClient:
|
|
def __init__(self, config: dict, headers: dict, wallet_linker):
|
|
self.config = config
|
|
self.headers = headers
|
|
self.wallet_linker = wallet_linker
|
|
|
|
async def execute_transaction_request(self, tx_data: Dict[str, Any], account: Dict[str, Any]) -> Tuple[
|
|
bool, Dict[str, Any]]:
|
|
async with httpx.AsyncClient() as client:
|
|
tx_resp = await client.post(f"https://fragment.com/api?hash={self.config['hash']}",
|
|
headers=self.headers, data=tx_data)
|
|
transaction = tx_resp.json()
|
|
|
|
if transaction.get("need_verify"):
|
|
if not await self.wallet_linker.link_wallet(account):
|
|
return False, {"success": False, "error": "Failed to link wallet"}
|
|
|
|
tx_resp = await client.post(f"https://fragment.com/api?hash={self.config['hash']}",
|
|
headers=self.headers, data=tx_data)
|
|
transaction = tx_resp.json()
|
|
|
|
return True, transaction
|