dev@locazia: add ton command
This commit is contained in:
1 parent
fd0baa1ddc
commit
7791244808
3 files changed
+26
-4
No files matched your search
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user