diff --git a/app/api/routes/_system.py b/app/api/routes/_system.py index 3dd31ff..9e6b1f2 100644 --- a/app/api/routes/_system.py +++ b/app/api/routes/_system.py @@ -5,6 +5,7 @@ from datetime import datetime from base58 import b58encode, b58decode from sanic import response +from app.core.models.node_storage import StoredContent from app.core._blockchain.ton.platform import platform from app.core._crypto.signer import Signer from app.core._secrets import hot_pubkey, service_wallet, hot_seed @@ -18,11 +19,16 @@ def get_git_info(): async def s_api_v1_node(request): # /api/v1/node + last_known_index = request.ctx.db_session.query(StoredContent).filter( + StoredContent.type == "onchain/content" + ).order_by(StoredContent.onchain_index.desc()).first() + last_known_index = last_known_index.onchain_index if last_known_index else 0 + last_known_index = max(last_known_index, 0) return response.json({ 'id': b58encode(hot_pubkey).decode(), 'node_address': service_wallet.address.to_string(1, 1, 1), 'master_address': platform.address.to_string(1, 1, 1), - 'indexer_height': 0, + 'indexer_height': last_known_index, 'services': { service_key: { 'status': (service['status'] if (service['timestamp'] and (datetime.now() - service['timestamp']).total_seconds() < 30) else 'not working: timeout'), diff --git a/app/core/content/content_id.py b/app/core/content/content_id.py index 43d333c..4ccd9b9 100644 --- a/app/core/content/content_id.py +++ b/app/core/content/content_id.py @@ -1,5 +1,4 @@ from base58 import b58encode, b58decode -import math from tonsdk.boc import begin_cell from app.core._config import ALLOWED_CONTENT_TYPES @@ -45,7 +44,10 @@ class ContentId: ) if not (self.safe_onchain_index is None): oi_bin_hex = hex(self.safe_onchain_index)[2:] - oi_bin_len = math.ceil(len(oi_bin_hex) / 2) + if len(oi_bin_hex) % 2: + oi_bin_hex = '0' + oi_bin_hex + + oi_bin_len = len(oi_bin_hex) / 2 cid_bin += b'\xb0' + oi_bin_len.to_bytes(1, 'big') + bytes.fromhex(oi_bin_hex) if self.accept_type and include_accept_type: at_bin_len = len(self.accept_type.encode())