add monitor script & edit default license type

This commit is contained in:
user committed 2024-08-21 23:49:56 +03:00
1 parent 40fd420b67
commit 569893b0aa
4 files changed
+146 -56

No files matched your search

+55 -56
View File
@@ -49,9 +49,8 @@ async def s_api_v1_blockchain_send_new_content_message(request):
assert field_key in request.json, f"No {field_key} provided"
assert field_value(request.json[field_key]), f"Invalid {field_key} provided"
ton_connect, ton_connection = TonConnect.by_user(request.ctx.db_session, request.ctx.user, callback_fn=())
await ton_connect.restore_connection()
assert ton_connect.connected, "No connected wallet"
wallet_connection = request.ctx.user.wallet_connection(request.ctx.db_session)
assert wallet_connection, "No wallet connection found"
decrypted_content_cid, err = resolve_content(request.json['content'])
assert not err, f"Invalid content CID"
@@ -93,66 +92,45 @@ async def s_api_v1_blockchain_send_new_content_message(request):
)
i += 1
request.app.add_task(ton_connect._sdk_client.send_transaction({
'valid_until': int(datetime.now().timestamp() + 120),
'messages': [
{
'address': platform.address.to_string(1, 1, 1),
'amount': str(int(0.15 * 10 ** 9)),
'payload': b64encode(
return response.json({
'address': platform.address.to_string(1, 1, 1),
'amount': str(int(0.15 * 10 ** 9)),
'payload': b64encode(
begin_cell()
.store_uint(0x5491d08c, 32)
.store_uint(int.from_bytes(encrypted_content_cid.content_hash, "big", signed=False), 256)
.store_ref(
begin_cell()
.store_uint(0x5491d08c, 32)
.store_uint(int.from_bytes(encrypted_content_cid.content_hash, "big", signed=False), 256)
.store_ref(
begin_cell()
.store_ref(
begin_cell()
.store_coins(int(request.json['price']))
.store_coins(int(100000000 * 10 ** 9))
.store_coins(int(500000000 * 10 ** 9))
.end_cell()
)
.store_maybe_ref(royalties_dict.end_dict())
.store_uint(0, 1)
.store_coins(int(800000000 * 10 ** 9))
.store_coins(int(800000000 * 10 ** 9))
.store_coins(int(request.json['price']))
.end_cell()
)
.store_maybe_ref(royalties_dict.end_dict())
.store_uint(0, 1)
.end_cell()
)
.store_ref(
begin_cell()
.store_ref(
begin_cell()
.store_bytes(f"{PROJECT_HOST}/api/v1/storage/{metadata_content.cid.serialize_v2(include_accept_type=True)}".encode())
.end_cell()
)
.store_ref(
begin_cell()
.store_ref(
begin_cell()
.store_bytes(f"{PROJECT_HOST}/api/v1/storage/{metadata_content.cid.serialize_v2(include_accept_type=True)}".encode())
.end_cell()
)
.store_ref(
begin_cell()
.store_ref(begin_cell().store_bytes(f"{encrypted_content_cid.serialize_v2()}".encode()).end_cell())
.store_ref(begin_cell().store_bytes(f"{image_content_cid.serialize_v2() if image_content_cid else ''}".encode()).end_cell())
.store_ref(begin_cell().store_bytes(f"{metadata_content.cid.serialize_v2()}".encode()).end_cell())
.end_cell()
)
.store_ref(begin_cell().store_bytes(f"{encrypted_content_cid.serialize_v2()}".encode()).end_cell())
.store_ref(begin_cell().store_bytes(f"{image_content_cid.serialize_v2() if image_content_cid else ''}".encode()).end_cell())
.store_ref(begin_cell().store_bytes(f"{metadata_content.cid.serialize_v2()}".encode()).end_cell())
.end_cell()
)
.end_cell().to_boc(False)
).decode()
}
]
}))
await request.ctx.user_uploader_wrapper.send_message(
request.ctx.user.translated('p_tonconnectTransactionRequested'),
reply_markup=get_inline_keyboard([
[{
'text': request.ctx.user.translated('gotoWallet_button'),
'url': wallet_obj_by_name(ton_connection.wallet_key.split('==')[0])['universal_url']
}],
[{
'text': request.ctx.user.translated('home_button'),
'callback_data': 'home'
}]
])
)
return response.json({"message": "Transaction requested"})
.end_cell()
)
.end_cell().to_boc(False)
).hex()
})
except BaseException as e:
make_log("Blockchain", f"Error while sending new content message: {e}" + '\n' + traceback.format_exc(), level='error')
return response.json({"error": str(e)}, status=400)
@@ -163,9 +141,30 @@ async def s_api_v1_blockchain_send_purchase_content_message(request):
for field_key, field_value in {
'content_address': lambda x: isinstance(x, str),
# 'price': lambda x: (isinstance(x, str) and x.isdigit()),
'license_type': lambda x: x in ['resale']
}.items():
assert field_key in request.json, f"No {field_key} provided"
assert field_value(request.json[field_key]), f"Invalid {field_key} provided"
return response.json({"message": "Transaction requested"})
r_content = StoredContent.from_cid(request.ctx.db_session, request.json['content_address'])
content = r_content.open_content(request.ctx.db_session)
licenses_cost = content['encrypted_content'].json_format()['license']
assert request.json['lisense_type'] in licenses_cost
return response.json({
'address': request.json['content_address'],
'amount': str(int(licenses_cost['resale']['price'])),
'payload': (
begin_cell()
.store_uint(0x2a319593, 32)
.store_uint(0, 64)
.store_uint(3, 8)
# .store_uint({
# 'listen': 1,
# 'resale': 3
# }[request.json['license_type']], 8)
.store_uint(0, 256)
.end_cell()
).to_boc(False).hex()
})
+5
View File
@@ -91,6 +91,8 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]:
item_distribution_slice = item_distribution.begin_parse()
item_prices_slice = item_distribution_slice.refs[0].begin_parse()
item_listen_license_price = item_prices_slice.read_coins()
item_use_license_price = item_prices_slice.read_coins()
item_resale_license_price = item_prices_slice.read_coins()
item_values_slice = item_values.begin_parse()
item_content_hash_int = item_values_slice.read_uint(256)
@@ -118,6 +120,9 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]:
'license': {
'listen': {
'price': str(item_listen_license_price)
},
'resale': {
'price': str(item_listen_license_price)
}
}
}