dev@locazia: add ton contracts

This commit is contained in:
user 2024-03-03 08:52:49 +03:00
parent 92eeb4e873
commit bf12866b8c
11 changed files with 158 additions and 4 deletions

View File

@ -13,7 +13,7 @@ app.register_middleware(close_db_session, "response")
from app.api.routes._index import s_index from app.api.routes._index import s_index
from app.api.routes._system import s_api_system, s_api_system_version from app.api.routes._system import s_api_system, s_api_system_version
from app.api.routes.auth import s_api_v1_auth_twa from app.api.routes.auth import s_api_v1_auth_twa
from app.api.routes.tonconnect import s_api_tonconnect_manifest from app.api.routes.statics import s_api_tonconnect_manifest, s_api_platform_metadata
from app.api.routes.node_storage import s_api_v1_storage_post, s_api_v1_storage_get from app.api.routes.node_storage import s_api_v1_storage_post, s_api_v1_storage_get
from app.api.routes.account import s_api_v1_account_get from app.api.routes.account import s_api_v1_account_get
from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \ from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \
@ -24,7 +24,8 @@ app.add_route(s_index, "/")
app.add_route(s_api_system, "/api/node", methods=["GET", "OPTIONS"]) app.add_route(s_api_system, "/api/node", methods=["GET", "OPTIONS"])
app.add_route(s_api_system_version, "/api/system.version", methods=["GET", "OPTIONS"]) app.add_route(s_api_system_version, "/api/system.version", methods=["GET", "OPTIONS"])
app.add_route(s_api_tonconnect_manifest, "/api/tonconnect-manifest.json") app.add_route(s_api_tonconnect_manifest, "/api/tonconnect-manifest.json", methods=["GET", "OPTIONS"])
app.add_route(s_api_platform_metadata, "/api/platform-metadata.json", methods=["GET", "OPTIONS"])
app.add_route(s_api_v1_auth_twa, "/api/v1/auth.twa", methods=["POST", "OPTIONS"]) app.add_route(s_api_v1_auth_twa, "/api/v1/auth.twa", methods=["POST", "OPTIONS"])

View File

@ -1,7 +1,10 @@
from sanic import response from sanic import response
from base58 import b58encode from base58 import b58encode
from app.core._secrets import hot_pubkey, service_wallet from app.core._secrets import hot_pubkey, service_wallet
from app.core._blockchain.ton.platform import platform
import subprocess import subprocess
import docker
from pprint import pprint
def get_git_info(): def get_git_info():
@ -11,9 +14,15 @@ def get_git_info():
async def s_api_system(request): async def s_api_system(request):
client = docker.from_env()
containers = client.containers.list(all=True)
pprint(containers)
return response.json({ return response.json({
'id': b58encode(hot_pubkey).decode(), 'id': b58encode(hot_pubkey).decode(),
'ton_address': service_wallet.address.to_string(1, 1, 1) 'master_address': platform.address.to_string(1, 1, 1),
'node_address': service_wallet.address.to_string(1, 1, 1),
'indexer_height': 0,
}) })

View File

@ -9,3 +9,10 @@ async def s_api_tonconnect_manifest(request):
"name": f"{PROJECT_HOST}", # TODO: maybe edit "name": f"{PROJECT_HOST}", # TODO: maybe edit
"iconUrl": "https://github.com/projscale/assets/blob/main/ton-connect.png?raw=true", "iconUrl": "https://github.com/projscale/assets/blob/main/ton-connect.png?raw=true",
}) })
async def s_api_platform_metadata(request):
return response.json({
"name": "@MY",
"image": "https://git.projscale.dev/my-dev/assets/raw/commit/81de5356c6b1d6f01988d77e22c580114b32bcbd/images/logo.jpg"
})

View File

@ -0,0 +1,2 @@

View File

@ -0,0 +1,22 @@
from tonsdk.boc import Cell, begin_cell
from tonsdk.contract import Contract
from app.core._secrets import service_wallet
class Blank(Contract):
code = 'B5EE9C72010104010042000114FF00F4A413F4BCF2C80B010202CA0203004FD043A0E9AE43F48061DA89A1F480618E0BE5C323A803A1A843F60803A1DA3DDAA7A861DAA9E2026F0007A0DD7C12'
def __init__(self, **kwargs):
kwargs['code'] = Cell.one_from_boc(self.code)
super().__init__(**kwargs)
def create_data_cell(self):
return begin_cell() \
.store_address(service_wallet.address) \
.store_uint(self.options['type_id'], 8) \
.store_ref(
begin_cell()
.store_bytes(self.options['user_id'])
.end_cell()
).end_cell()

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,36 @@
from tonsdk.boc import Cell, begin_cell
from tonsdk.contract import Contract
class Platform(Contract):
code = 'b5ee9c724102180100039f000114ff00f4a413f4bcf2c80b01020120030200a2f28308d71831d33f01f823bbf264d31f30810e7fba8e39f8007082f0be521f12758263c40b0dc6bdd1f5a26dbc8c7b7c349068647f749da5a716aea521748010c8cb05cb02cb07cbffcb6ac98306fb00e00201480f0402012008050201200706004bbac877382f06949f6f27c3c5650394e5f9b14a79bc4d647b8fe4870c0014ece6b05cb2bd74780057b905bed44d0fa4001f861d3ff01f862d401f863f843d0d431d430f864d401f865d1f845d0f84201d430f84180201200c090201200b0a00a1b4f47da89a1f48003f0c3a7fe03f0c5a803f0c7f087a1a863a861f0c9a803f0cba3f089f050e0079197ff92826190a0079e2d960f9992e04191960227e801e801960193f200e0e9919605940f97ff93a10000fb5daee0419193a100201200e0d0059b6a9bda89a1f48003f0c3a7fe03f0c5a803f0c7f087a1a863a861f0c9a803f0cba2e1f051f085f087f089f08b00051b56ba63da89a1f48003f0c3a7fe03f0c5a803f0c7f087a1a863a861f0c9a803f0cba2e391960f999300202c711100007a0dd7c120201cf131200113e910c30003cb8536002f30cf434c0c05c6c2497c0f83e90087c007e900c7e800c5c75c87e800c7e800c1cea6d0008f5d27048245c2540f4c7d411388830002497c1783b51343e90007e1874ffc07e18b5007e18fe10f4350c750c3e1935007e1974482084091ea7aeaea497c178082084152474232ea3a14c104c36cf380c4cbe1071c160161401c4f2e19120820833cc77ba9730d4d30730fb00e0208210b99cd03bba9701fa4001f86101de208210d81c632fba9601d401f86501de208210b5de5f9ebae30282102fa30f96ba98d401fb04d430ed54e030f845f843f842c8f841cf16cbffccccc9ed5415008a30fa40fa00306d6d71708010c8cb055006cf165004fa0214cb68216e947032cb019bc858cf17c97158cb00f400e2226e95327058cb0099c85003cf17c958f400e2c901fb0001e4821005f5e10001a013bef2e20801d3ffd4d430f844f82870f842c8cbffc9c85003cf16cb07ccc97020c8cb0113f400f400cb00c920f9007074c8cb02ca07cbffc9d0f843d070c804d014cf16f843f842c8cbfff828cf16c903d430c8cc13ccc9c8cc17cbff5007cf1614cc15cccc433080401700a6708010c8cb055006cf165004fa0214cb68216e947032cb019bc858cf17c97158cb00f400e2226e95327058cb0099c85003cf17c958f400e2c901fb00f842a4f862f845f843f842c8f841cf16cbffccccc9ed54f7fbeaf8'
def __init__(self, **kwargs):
kwargs['code'] = Cell.one_from_boc(self.code)
super().__init__(**kwargs)
def create_content_cell(self) -> Cell:
return (
begin_cell()
.store_ref(
begin_cell()
.store_uint(1, 8)
.store_bytes(self.options['collection_content_uri'].encode())
.end_cell()
)
.store_ref(begin_cell().end_cell())
.end_cell()
)
def create_data_cell(self) -> Cell:
return begin_cell() \
.store_address(self.options['admin_address']) \
.store_uint(0, 256) \
.store_ref(
begin_cell()
.store_ref(self.options['cop_code'])
.store_ref(self.options['blank_code'])
.end_cell()
) \
.store_ref(self.create_content_cell()) \
.end_cell()

View File

@ -0,0 +1,20 @@
from app.core._config import TESTNET, MY_PLATFORM_CONTRACT
from app.core._secrets import service_wallet
from app.core._blockchain.ton.contracts.platform import Platform
from app.core._blockchain.ton.contracts.cop_nft import COP_NFT
from app.core._blockchain.ton.contracts.blank import Blank
from tonsdk.boc import Cell
from tonsdk.utils import Address
kwargs = {}
if TESTNET is False:
kwargs['address'] = Address(MY_PLATFORM_CONTRACT)
platform = Platform(
admin_address=service_wallet.address,
blank_code=Cell.one_from_boc(Blank.code),
cop_code=Cell.one_from_boc(COP_NFT.code),
collection_content_uri='https://music-gateway.letsw.app/api/platform-metadata.json',
**kwargs
)

View File

@ -37,7 +37,11 @@ ALLOWED_CONTENT_TYPES = [
'audio/mpeg', 'audio/ogg', 'audio/wav', 'audio/mpeg', 'audio/ogg', 'audio/wav',
] ]
TESTNET = bool(int(os.getenv('TESTNET', '0')))
TONCENTER_HOST = os.getenv('TONCENTER_HOST', 'https://toncenter.com/api/v1/') TONCENTER_HOST = os.getenv('TONCENTER_HOST', 'https://toncenter.com/api/v1/')
TONCENTER_API_KEY = os.getenv('TONCENTER_API_KEY') TONCENTER_API_KEY = os.getenv('TONCENTER_API_KEY')
# 706a0565aae1e89968aea905043f1b6e150a5b80130ce92a57b4904c82865b43
MY_PLATFORM_CONTRACT = 'EQAGbwW0sFghy9N4MQ0Ozp8YOIr0lcMI8J5kbbydFnQtheMY'
MY_FUND_ADDRESS = 'UQDarChHFMOI2On9IdHJNeEKttqepgo0AY4bG1trw8OAAwMY' MY_FUND_ADDRESS = 'UQDarChHFMOI2On9IdHJNeEKttqepgo0AY4bG1trw8OAAwMY'

View File

@ -11,15 +11,17 @@ class StoredContent(AlchemyBase):
__tablename__ = 'node_storage' __tablename__ = 'node_storage'
id = Column(Integer, autoincrement=True, primary_key=True) id = Column(Integer, autoincrement=True, primary_key=True)
type = Column(String(32), nullable=False)
hash = Column(String(64), nullable=False, unique=True) # base58 hash = Column(String(64), nullable=False, unique=True) # base58
onchain_index = Column(BigInteger, nullable=True, default=None) onchain_index = Column(BigInteger, nullable=True, default=None)
status = Column(String(32), nullable=True)
filename = Column(String(1024), nullable=False) filename = Column(String(1024), nullable=False)
meta = Column(JSON, nullable=False, default={}) meta = Column(JSON, nullable=False, default={})
user_id = Column(Integer, ForeignKey('users.id'), nullable=False) user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
storj_cid = Column(String(1024), nullable=False, unique=True) btfs_cid = Column(String(1024), nullable=False, unique=True)
ipfs_cid = Column(String(1024), nullable=False, unique=True) ipfs_cid = Column(String(1024), nullable=False, unique=True)
telegram_cid = Column(String(1024), nullable=False, unique=True) telegram_cid = Column(String(1024), nullable=False, unique=True)

View File

@ -8,3 +8,4 @@ pytonconnect==0.3.0
base58==2.1.1 base58==2.1.1
tonsdk==1.0.13 tonsdk==1.0.13
httpx==0.25.0 httpx==0.25.0
docker==7.0.0