improve work
This commit is contained in:
1 parent
64491e19e1
commit
3511ebd247
23 files changed
+1595
-310
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import os
|
||||
import traceback
|
||||
|
||||
import base58
|
||||
from sqlalchemy import and_, select
|
||||
from sqlalchemy import select
|
||||
from datetime import datetime
|
||||
|
||||
from app.core.logger import make_log
|
||||
from app.core.models import StoredContent
|
||||
@@ -42,6 +44,9 @@ class NodeStorageIndexationMixin:
|
||||
pass # async def fetch_onchain_metadata(self):
|
||||
|
||||
|
||||
MIN_ONCHAIN_INDEX = int(os.getenv("MIN_ONCHAIN_INDEX", "8"))
|
||||
|
||||
|
||||
class UserContentIndexationMixin:
|
||||
async def sync_with_chain(self, db_session):
|
||||
errored = False
|
||||
@@ -54,12 +59,29 @@ class UserContentIndexationMixin:
|
||||
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['address'] == self.onchain_address, "Address is not equal"
|
||||
if cc_indexator_data['index'] < MIN_ONCHAIN_INDEX:
|
||||
make_log(
|
||||
"UserContent",
|
||||
f"Skip license {self.onchain_address} with index {cc_indexator_data['index']} < MIN_ONCHAIN_INDEX={MIN_ONCHAIN_INDEX}",
|
||||
level="info"
|
||||
)
|
||||
self.type = 'nft/ignored'
|
||||
self.content_id = None
|
||||
self.updated = datetime.utcnow()
|
||||
await db_session.commit()
|
||||
return
|
||||
values_slice = cc_indexator_data['values'].begin_parse()
|
||||
content_hash_b58 = base58.b58encode(bytes.fromhex(hex(values_slice.read_uint(256))[2:])).decode()
|
||||
make_log("UserContent", f"License ({self.onchain_address}) content hash: {content_hash_b58}", level="info")
|
||||
stored_content = (await db_session.execute(select(StoredContent).where(
|
||||
and_(StoredContent.type == 'onchain/content', StoredContent.hash == content_hash_b58)
|
||||
StoredContent.hash == content_hash_b58
|
||||
))).scalars().first()
|
||||
if not stored_content:
|
||||
raise AssertionError(f"Stored content not found for hash={content_hash_b58}")
|
||||
if not (stored_content.type or '').startswith('onchain/content'):
|
||||
stored_content.type = 'onchain/content' if stored_content.key_id else 'onchain/content_unknown'
|
||||
stored_content.onchain_index = stored_content.onchain_index or cc_indexator_data['index']
|
||||
stored_content.owner_address = stored_content.owner_address or cc_indexator_data['owner_address']
|
||||
trusted_cop_address_result = await toncenter.run_get_method(stored_content.meta['item_address'], 'get_nft_address_by_index', [['num', cc_indexator_data['index']]])
|
||||
assert trusted_cop_address_result.get('exit_code', -1) == 0, "Trusted cop address error"
|
||||
trusted_cop_address = Cell.one_from_boc(b64decode(trusted_cop_address_result['stack'][0][1]['bytes'])).begin_parse().read_msg_addr().to_string(1, 1, 1)
|
||||
@@ -77,5 +99,3 @@ class UserContentIndexationMixin:
|
||||
self.type = 'nft/unknown'
|
||||
self.content_id = None
|
||||
await db_session.commit()
|
||||
|
||||
|
||||
Reference in new issue
Block a user