license_service
This commit is contained in:
1 parent
752f42ba02
commit
839655b163
4 files changed
+169
-10
No files matched your search
@@ -1,5 +1,5 @@
|
||||
from app.core.models.node_storage import StoredContent
|
||||
from app.core.models.content.user_content import UserContent
|
||||
from app.core.models.content.user_content import UserContent, UserAction
|
||||
from app.core.logger import make_log
|
||||
from app.core._utils.tg_process_template import tg_process_template
|
||||
from app.core._config import PROJECT_HOST, CLIENT_TELEGRAM_BOT_USERNAME
|
||||
@@ -96,12 +96,25 @@ class PlayerTemplates:
|
||||
or bool(self.db_session.query(UserContent).filter_by(owner_address=user_wallet_address, status='active', content_id=content.id).first())
|
||||
)
|
||||
if not have_access:
|
||||
inline_keyboard_array.append([{
|
||||
'text': self.user.translated('buyTrackListenLicense_button').format(price=str(round(0.15 , 3))),
|
||||
'callback_data': f'PC_{content.id}'
|
||||
}])
|
||||
template_kwargs['audio'] = URLInputFile(local_content_url + '?seconds_limit=30')
|
||||
text = self.user.translated('p_playerContext_preview')
|
||||
purchase_action = self.db_session.query(UserAction).filter_by(
|
||||
type='purchase',
|
||||
from_address=user_wallet_address,
|
||||
content_id=content.id,
|
||||
status='requested'
|
||||
).first()
|
||||
if purchase_action:
|
||||
inline_keyboard_array.append([{
|
||||
'text': self.user.translated('gotoWallet_button'),
|
||||
'url': purchase_action.meta['confirmation_url']
|
||||
}])
|
||||
text = self.user.translated('p_playerContext_purchaseRequested')
|
||||
else:
|
||||
inline_keyboard_array.append([{
|
||||
'text': self.user.translated('buyTrackListenLicense_button').format(price=str(round(0.15, 3))),
|
||||
'callback_data': f'PC_{content.id}'
|
||||
}])
|
||||
text = self.user.translated('p_playerContext_preview')
|
||||
|
||||
make_log("TG-Player", f"Send content {content_type} ({content_encoding}) to chat {self._chat_id}. {cd_log}")
|
||||
for kmsg in self.db_session.query(KnownTelegramMessage).filter_by(
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
import traceback
|
||||
|
||||
import base58
|
||||
from sqlalchemy import and_
|
||||
|
||||
from app.core.logger import make_log
|
||||
from app.core.models import StoredContent
|
||||
from app.core.models.wallet_connection import WalletConnection
|
||||
from app.core._blockchain.ton.toncenter import toncenter
|
||||
from tonsdk.boc import Cell
|
||||
@@ -35,10 +42,44 @@ class NodeStorageIndexationMixin:
|
||||
pass # async def fetch_onchain_metadata(self):
|
||||
|
||||
|
||||
|
||||
class UserContentIndexationMixin:
|
||||
pass
|
||||
async def sync_with_chain(self, db_session):
|
||||
errored = False
|
||||
cc_indexator_result = await toncenter.run_get_method(self.onchain_address, 'indexator_data')
|
||||
if cc_indexator_result.get('exit_code', -1) != 0:
|
||||
errored = True
|
||||
|
||||
if not errored:
|
||||
try:
|
||||
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"
|
||||
values_slice = cc_indexator_data['values'].begin_parse()
|
||||
content_hash_b58 = base58.b58encode(bytes.fromhex(values_slice.read_uint(256).hex()[2:])).decode()
|
||||
stored_content = db_session.query(StoredContent).filter(
|
||||
and_(
|
||||
StoredContent.type == 'onchain/content',
|
||||
StoredContent.hash == content_hash_b58,
|
||||
|
||||
)
|
||||
).first()
|
||||
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)
|
||||
make_log("UserContent", f"Trusted cop address: {trusted_cop_address} / Contract address: {trusted_cop_address}", level="info")
|
||||
assert trusted_cop_address == cc_indexator_data['address'], "Trusted cop address is not equal"
|
||||
self.owner_address = cc_indexator_data['owner_address']
|
||||
self.type = 'nft/listen'
|
||||
self.content_id = stored_content.id
|
||||
db_session.commit()
|
||||
except BaseException as e:
|
||||
errored = True
|
||||
make_log("UserContent", f"Error: {e}" + '\n' + traceback.format_exc(), level="error")
|
||||
|
||||
if errored is True:
|
||||
self.type = 'nft/unknown'
|
||||
self.content_id = None
|
||||
db_session.commit()
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user