diff --git a/app/api/__init__.py b/app/api/__init__.py index 5837f1b..86a293a 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -23,7 +23,7 @@ from app.api.routes.content import s_api_v1_content_list app.add_route(s_index, "/", methods=["GET", "OPTIONS"]) app.add_route(s_favicon, "/favicon.ico", methods=["GET", "OPTIONS"]) -app.add_route(s_api_v1_node, "/api/1/node", methods=["GET", "OPTIONS"]) +app.add_route(s_api_v1_node, "/api/v1/node", methods=["GET", "OPTIONS"]) app.add_route(s_api_system_version, "/api/system.version", methods=["GET", "OPTIONS"]) app.add_route(s_api_system_send_status, "/api/system.sendStatus", methods=["POST", "OPTIONS"]) diff --git a/app/api/routes/_system.py b/app/api/routes/_system.py index 172c7de..76dbe8a 100644 --- a/app/api/routes/_system.py +++ b/app/api/routes/_system.py @@ -47,6 +47,7 @@ async def s_api_system_send_status(request): return response.json({'error': 'Invalid signature'}, status=400) message = json.loads(message) + assert message.get('service') in request.app.ctx.memory.known_states, "Unknown service" request.app.ctx.memory.known_states[ message['service'] ] = { diff --git a/app/core/background/ton_service.py b/app/core/background/ton_service.py index ce7f7d5..ba32371 100644 --- a/app/core/background/ton_service.py +++ b/app/core/background/ton_service.py @@ -1,10 +1,11 @@ from tonsdk.boc import begin_cell from app.core.logger import make_log -from app.core._config import MY_FUND_ADDRESS +from app.core._config import MY_FUND_ADDRESS, MY_PLATFORM_CONTRACT from app.core.storage import db_session from app.core._secrets import service_wallet from app.core._blockchain.ton.toncenter import toncenter from app.core._utils.send_status import send_status +from tonsdk.utils import Address import asyncio import os, sys @@ -37,7 +38,7 @@ async def main_fn(): )['message'].to_boc(False) ) await asyncio.sleep(5) - return await main() + return await main_fn() if os.getenv("TON_BEGIN_COMMAND_WITHDRAW"): await toncenter.send_boc( @@ -53,17 +54,31 @@ async def main_fn(): make_log("TON", "Withdraw command sent", level="info") await asyncio.sleep(10) + platform_state = await toncenter.get_account(MY_PLATFORM_CONTRACT) + if not platform_state.get('code'): + make_log("TON", "Platform contract is not deployed, shutdown service..", level="info") + await send_status("ton_daemon", "Platform contract is not deployed, not working") + while True: + await asyncio.sleep(100) + while True: - sw_seqno_value = await get_sw_seqno() - make_log("TON", f"Service running ({sw_seqno_value})", level="debug") - # with db_session() as session: - # for stored_content in session.query(StoredContent).filter(StoredContent.uploaded == False).all(): - # pass + try: + sw_seqno_value = await get_sw_seqno() + make_log("TON", f"Service running ({sw_seqno_value})", level="debug") - await asyncio.sleep(5) - await send_status("ton", f"working (seqno={sw_seqno_value})") + + # with db_session() as session: + # for stored_content in session.query(StoredContent).filter(StoredContent.uploaded == False).all(): + # pass + + await asyncio.sleep(5) + await send_status("ton_daemon", f"working (seqno={sw_seqno_value})") + except BaseException as e: + make_log("TON", f"Error: {e}", level="error") + await asyncio.sleep(3) + # if __name__ == '__main__': # loop = asyncio.get_event_loop() # loop.run_until_complete(main())