fix
This commit is contained in:
parent
d53cd588f7
commit
7dba36f8d8
|
|
@ -1,9 +1,12 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from app.core.models.content.user_content import UserContent
|
from app.core.models.content.user_content import UserContent
|
||||||
from app.core.models.wallet_connection import WalletConnection
|
from app.core.models.wallet_connection import WalletConnection
|
||||||
from app.core._blockchain.ton.toncenter import toncenter
|
from app.core._blockchain.ton.toncenter import toncenter
|
||||||
from tonsdk.utils import Address
|
from tonsdk.utils import Address
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from app.core.logger import make_log
|
from app.core.logger import make_log
|
||||||
|
from httpx import AsyncClient
|
||||||
|
|
||||||
|
|
||||||
class WalletMixin:
|
class WalletMixin:
|
||||||
|
|
@ -18,6 +21,50 @@ class WalletMixin:
|
||||||
return wallet_connection.wallet_address if wallet_connection else None
|
return wallet_connection.wallet_address if wallet_connection else None
|
||||||
|
|
||||||
async def scan_owned_user_content(self, db_session):
|
async def scan_owned_user_content(self, db_session):
|
||||||
|
user_wallet_address = self.wallet_address(db_session)
|
||||||
|
|
||||||
|
async def get_nft_items_list():
|
||||||
|
try:
|
||||||
|
# TODO: support more than 1000 items
|
||||||
|
async with AsyncClient() as client:
|
||||||
|
response = await client.get(f"https://tonapi.io/v2/accounts/{user_wallet_address}/nfts?limit=1000&offset=0&indirect_ownership=false")
|
||||||
|
response = response.json()
|
||||||
|
assert 'nft_items' in response
|
||||||
|
except BaseException as e:
|
||||||
|
make_log(self, f"Error while fetching NFTs: {e}", level='error')
|
||||||
|
await asyncio.sleep(2)
|
||||||
|
return await get_nft_items_list()
|
||||||
|
|
||||||
|
nfts_list = await get_nft_items_list()
|
||||||
|
for nft_item in nfts_list:
|
||||||
|
item_address = Address(nft_item['address']).to_string(1, 1, 1)
|
||||||
|
owner_address = Address(nft_item['owner']['address']).to_string(1, 1, 1)
|
||||||
|
|
||||||
|
user_content = db_session.query(UserContent).filter(
|
||||||
|
UserContent.onchain_address == item_address
|
||||||
|
).first()
|
||||||
|
if user_content:
|
||||||
|
continue
|
||||||
|
|
||||||
|
user_content = UserContent(
|
||||||
|
type='nft/unknown',
|
||||||
|
onchain_address=item_address,
|
||||||
|
owner_address=owner_address,
|
||||||
|
code_hash=None,
|
||||||
|
data_hash=None,
|
||||||
|
updated=datetime.fromtimestamp(0),
|
||||||
|
content_id=None, # not resolved yet
|
||||||
|
created=datetime.now(),
|
||||||
|
meta={},
|
||||||
|
user_id=self.id,
|
||||||
|
wallet_connection_id=self.wallet_connection(db_session).id,
|
||||||
|
status="active"
|
||||||
|
)
|
||||||
|
db_session.add(user_content)
|
||||||
|
db_session.commit()
|
||||||
|
make_log(self, f"New onchain NFT found: {item_address}", level='info')
|
||||||
|
|
||||||
|
async def ____scan_owned_user_content(self, db_session):
|
||||||
page_id = -1
|
page_id = -1
|
||||||
page_size = 100
|
page_size = 100
|
||||||
have_next_page = True
|
have_next_page = True
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue