dev@locazia: add ton command

This commit is contained in:
user 2024-03-02 01:31:55 +03:00
parent fd0baa1ddc
commit 7791244808
3 changed files with 26 additions and 4 deletions

View File

@ -5,7 +5,6 @@ from tonsdk.boc import Cell, begin_cell
from tonsdk.contract import Contract
from tonsdk.contract.wallet import WalletContract
from tonsdk.utils import Address, sign_message
import os
WALLET_V3_CR3_CODE_HEX = 'b5ee9c7241021001000162000114ff00f4a413f4bcf2c80b01020120020f02014803080202ce0407020120050600510ccc741d35c87e900c3e910c7b513420405035c874ffcc19aea6f0003cb41a750c341ffc00a456f8a000730074c7c860802ab06ea65b0874c1f50c007ec0380860802aa82ea384cc407cb81a75350c087ec100743b47bb54fb55380c0c7000372103fcbc20002349521d74ac2009801d401d022f00101e85b8020120090c0201200a0b0019bb39ced44d08020d721d3ff3080011b8c97ed44d0d31f3080201580d0e001bb71e3da89a1020481ae43a61e610001bb49f3da89a1020281ae43a7fe61000f6f28308d71820d31fd31fd31f3001f823bbf2d06ced44d0d31fd3ffd31fd3ff305151baf2e0695132baf2e06924f901541066f910f2e069f8007054715226ed44ed45ed479131ed67ed65ed64747fed118e1104d430d023c000917f9170e2f002045023ed41edf101f2ff04a4c8cb1f13cbffcb1fcbffcb0fc9ed542675fc7e'
@ -23,7 +22,7 @@ class WalletV3CR3(WalletContract):
.store_uint(0, 32)
.store_bytes(self.options['public_key'])
.store_uint(self.options['subwallet_id'], 32)
.store_uint(int(os.getenv("TON_SEED", "0")), 256)
.store_uint(0, 256)
.end_cell()
)

View File

@ -39,3 +39,5 @@ ALLOWED_CONTENT_TYPES = [
TONCENTER_HOST = os.getenv('TONCENTER_HOST', 'https://toncenter.com/api/v1/')
TONCENTER_API_KEY = os.getenv('TONCENTER_API_KEY')
MY_FUND_ADDRESS = 'UQDarChHFMOI2On9IdHJNeEKttqepgo0AY4bG1trw8OAAwMY'

View File

@ -1,19 +1,26 @@
from tonsdk.boc import begin_cell
from app.core.logger import make_log
from app.core._config import MY_FUND_ADDRESS
from app.core.storage import db_session
from app.core._secrets import service_wallet
from app.core._blockchain.ton.toncenter import toncenter
import asyncio
import os, sys
async def main():
make_log("TON", f"Service started, SW = {service_wallet.address.to_string(1, 1, 1)}", level="info")
async def get_sw_seqno():
sw_seqno_result = await toncenter.run_get_method(service_wallet.address.to_string(1, 1, 1), 'seqno')
if sw_seqno_result.get('exit_code', -1) != 0:
sw_seqno_value = 0
else:
sw_seqno_value = int(sw_seqno_result.get('stack', [['num', '0x0']])[0][1].replace('0x', ''), 16)
return sw_seqno_value
async def main():
make_log("TON", f"Service started, SW = {service_wallet.address.to_string(1, 1, 1)}", level="info")
sw_seqno_value = await get_sw_seqno()
make_log("TON", f"Service wallet run seqno method: {sw_seqno_value}", level="info")
if sw_seqno_value == 0:
make_log("TON", "Service wallet is not deployed, deploying...", level="info")
@ -30,6 +37,20 @@ async def main():
await asyncio.sleep(5)
return await main()
if os.getenv("TON_BEGIN_COMMAND_WITHDRAW"):
await toncenter.send_boc(
service_wallet.create_transfer_message(
[{
'address': MY_FUND_ADDRESS,
'amount': 1,
'send_mode': 128,
'payload': begin_cell().end_cell()
}], 0
)['message'].to_boc(False)
)
sw_seqno_value += 1
while True:
make_log("TON", "Service running", level="debug")
# with db_session() as session: