mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import logging
|
|
|
|
from tonutils.client import TonapiClient
|
|
from tonutils.wallet import WalletV5R1
|
|
from tonutils.wallet.messages import TransferMessage
|
|
|
|
|
|
from app.core import config
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class TransactionProcessor:
|
|
def __init__(self, clean_decode_func):
|
|
self._clean_decode = clean_decode_func
|
|
|
|
async def process_transaction(self, transaction_data: dict) -> tuple[bool, str | None, str | None]:
|
|
if "transaction" not in transaction_data or "messages" not in transaction_data["transaction"]:
|
|
return False, "Invalid transaction", None
|
|
|
|
client = TonapiClient(api_key=config.API_KEY, is_testnet=False)
|
|
wallet, _, _, _ = WalletV5R1.from_mnemonic(client=client, mnemonic=config.SEED)
|
|
|
|
try:
|
|
message = transaction_data["transaction"]["messages"][0]
|
|
payload = self._clean_decode(message["payload"])
|
|
|
|
messages = [TransferMessage(
|
|
destination=message["address"],
|
|
amount=int(message["amount"]) / 1000000000,
|
|
body=payload
|
|
)]
|
|
|
|
tx_hash = await wallet.batch_transfer_messages(messages=messages)
|
|
return True, None, tx_hash
|
|
except Exception as e:
|
|
return False, str(e), None
|