last fixes, normally work self node

This commit is contained in:
root 2025-10-05 14:04:44 +00:00
parent 8651efd578
commit c170ca5433
3 changed files with 42 additions and 14 deletions

View File

@ -1,4 +1,6 @@
from aiogram import types, Router, F from aiogram import types, Router, F
from sqlalchemy import select
from app.core.logger import make_log from app.core.logger import make_log
from app.core.models import StarsInvoice from app.core.models import StarsInvoice
@ -12,9 +14,10 @@ async def t_pre_checkout_query_stars_processing(pre_checkout_query: types.PreChe
invoice_id = pre_checkout_query.invoice_payload invoice_id = pre_checkout_query.invoice_payload
existing_invoice = db_session.query(StarsInvoice).filter( result = await db_session.execute(
StarsInvoice.external_id == invoice_id select(StarsInvoice).where(StarsInvoice.external_id == invoice_id)
).first() )
existing_invoice = result.scalars().first()
if not existing_invoice: if not existing_invoice:
return await pre_checkout_query.answer(ok=False, error_message="Invoice not found") return await pre_checkout_query.answer(ok=False, error_message="Invoice not found")

View File

@ -59,7 +59,8 @@ class UserContentIndexationMixin:
cc_indexator_data = unpack_item_indexator_data(cc_indexator_result) cc_indexator_data = unpack_item_indexator_data(cc_indexator_result)
assert cc_indexator_data['type'] == 1, "Type is not a content" assert cc_indexator_data['type'] == 1, "Type is not a content"
assert cc_indexator_data['address'] == self.onchain_address, "Address is not equal" assert cc_indexator_data['address'] == self.onchain_address, "Address is not equal"
if cc_indexator_data['index'] < MIN_ONCHAIN_INDEX: license_type = cc_indexator_data.get('license_type')
if cc_indexator_data['index'] < MIN_ONCHAIN_INDEX and (license_type is None or license_type == 0):
make_log( make_log(
"UserContent", "UserContent",
f"Skip license {self.onchain_address} with index {cc_indexator_data['index']} < MIN_ONCHAIN_INDEX={MIN_ONCHAIN_INDEX}", f"Skip license {self.onchain_address} with index {cc_indexator_data['index']} < MIN_ONCHAIN_INDEX={MIN_ONCHAIN_INDEX}",
@ -90,6 +91,7 @@ class UserContentIndexationMixin:
self.owner_address = cc_indexator_data['owner_address'] self.owner_address = cc_indexator_data['owner_address']
self.type = 'nft/listen' self.type = 'nft/listen'
self.content_id = stored_content.id self.content_id = stored_content.id
self.meta = {**(self.meta or {}), 'license_type': license_type}
await db_session.commit() await db_session.commit()
except BaseException as e: except BaseException as e:
errored = True errored = True

View File

@ -57,23 +57,27 @@ class WalletMixin:
collection_address = collection_address or nft_item.get('collection_address') collection_address = collection_address or nft_item.get('collection_address')
if collection_address: if collection_address:
try: try:
normalized_collection = Address(collection_address).to_string(1, 1, 1) collection_address = Address(collection_address).to_string(1, 1, 1)
except Exception: except Exception:
normalized_collection = collection_address pass
if normalized_collection != platform_address:
make_log(self, f"Skip foreign NFT {item_address} from collection {normalized_collection}", level='debug')
continue
item_index = None item_index = None
license_type = None
# Prefer index from tonapi payload if available # Prefer index from tonapi payload if available
raw_index = nft_item.get('index') if isinstance(nft_item, dict) else None raw_index = nft_item.get('index') if isinstance(nft_item, dict) else None
if isinstance(raw_index, int): if isinstance(raw_index, int):
item_index = raw_index item_index = raw_index
if item_index is None:
need_chain_probe = item_index is None or item_index < MIN_ONCHAIN_INDEX
platform_address_onchain = None
if need_chain_probe:
try: try:
indexator_raw = await toncenter.run_get_method(item_address, 'indexator_data') indexator_raw = await toncenter.run_get_method(item_address, 'indexator_data')
if indexator_raw.get('exit_code', -1) == 0: if indexator_raw.get('exit_code', -1) == 0:
item_index = unpack_item_indexator_data(indexator_raw)['index'] indexator_data = unpack_item_indexator_data(indexator_raw)
item_index = indexator_data['index']
license_type = indexator_data.get('license_type')
platform_address_onchain = indexator_data.get('platform_address')
except BaseException as err: except BaseException as err:
make_log(self, f"Failed to fetch indexator data for {item_address}: {err}", level='warning') make_log(self, f"Failed to fetch indexator data for {item_address}: {err}", level='warning')
@ -81,13 +85,32 @@ class WalletMixin:
make_log(self, f"Skip NFT {item_address}: unable to resolve on-chain index", level='warning') make_log(self, f"Skip NFT {item_address}: unable to resolve on-chain index", level='warning')
continue continue
if item_index is not None and item_index < MIN_ONCHAIN_INDEX: if platform_address_onchain and platform_address_onchain != platform_address:
make_log(self, f"Ignore NFT {item_address} with index {item_index} < MIN_ONCHAIN_INDEX={MIN_ONCHAIN_INDEX}", level='debug') make_log(
self,
f"Skip foreign NFT {item_address}: platform mismatch {platform_address_onchain} != {platform_address}",
level='debug'
)
continue
if item_index < MIN_ONCHAIN_INDEX and (license_type is None or license_type == 0):
make_log(
self,
f"Ignore NFT {item_address} with index {item_index} < MIN_ONCHAIN_INDEX={MIN_ONCHAIN_INDEX} (license_type={license_type})",
level='debug'
)
continue continue
from sqlalchemy import select from sqlalchemy import select
user_content = (await db_session.execute(select(UserContent).where(UserContent.onchain_address == item_address))).scalars().first() user_content = (await db_session.execute(select(UserContent).where(UserContent.onchain_address == item_address))).scalars().first()
if user_content: if user_content:
if license_type is not None and license_type != 0 and user_content.type == 'nft/ignored':
user_content.type = 'nft/unknown'
user_content.meta = {**(user_content.meta or {}), 'license_type': license_type}
user_content.owner_address = owner_address
user_content.status = 'active'
user_content.updated = datetime.fromtimestamp(0)
await db_session.commit()
continue continue
user_content = UserContent( user_content = UserContent(
@ -99,7 +122,7 @@ class WalletMixin:
updated=datetime.fromtimestamp(0), updated=datetime.fromtimestamp(0),
content_id=None, # not resolved yet content_id=None, # not resolved yet
created=datetime.now(), created=datetime.now(),
meta={}, meta={'license_type': license_type} if license_type is not None else {},
user_id=self.id, user_id=self.id,
wallet_connection_id=(await self.wallet_connection_async(db_session)).id, wallet_connection_id=(await self.wallet_connection_async(db_session)).id,
status="active" status="active"