Load Notamon NFTS
This commit is contained in:
parent
2dcb86f610
commit
ee0972d096
|
@ -1,5 +1,6 @@
|
|||
import flask
|
||||
import pbc_client
|
||||
import pbcabi
|
||||
import base64
|
||||
import dataclasses
|
||||
import requests_cache
|
||||
|
@ -66,7 +67,9 @@ class Notamon:
|
|||
species_name: str
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class NotamonAttributes:
|
||||
class NotamonNFTData:
|
||||
nickname: str
|
||||
owner: str
|
||||
species_id: int
|
||||
skin_id: int
|
||||
effect_id: int
|
||||
|
@ -133,14 +136,33 @@ def to_base64_png(b: bytes) -> str:
|
|||
return f'data:image/png;base64,{base64.b64encode(b)}'
|
||||
|
||||
|
||||
def get_notamon_nfts(client: pbc_client.PbcClient):
|
||||
asset_contract_state, _ = client.get_contract_state(ADDRESS_NFTS)
|
||||
print(asset_contract_state)
|
||||
|
||||
yield from []
|
||||
def get_notamon_nfts(client: pbc_client.PbcClient) -> Iterator[NotamonNFTData]:
|
||||
asset_contract_state, _ = client.get_typed_contract_state(ADDRESS_NFTS)
|
||||
|
||||
owners, _ = client.get_typed_contract_avl_tree(ADDRESS_NFTS, asset_contract_state['owners'])
|
||||
attributes, _ = client.get_typed_contract_avl_tree(ADDRESS_NFTS, asset_contract_state['notamon_attributes'])
|
||||
|
||||
for notamon_id in owners:
|
||||
attr = attributes.get(notamon_id)
|
||||
yield NotamonNFTData(
|
||||
nickname = 'Dude',
|
||||
owner =owners.get(notamon_id),
|
||||
species_id= attr['species_id']['id'],
|
||||
skin_id = attr['skin_id']['id'],
|
||||
effect_id = attr['effect_id']['id'],
|
||||
stat_hp = attr['stat_hp'],
|
||||
stat_attack = attr['stat_attack'],
|
||||
stat_defense = attr['stat_defense'],
|
||||
)
|
||||
|
||||
|
||||
def nft_to_notamon_view(nft: NotamonNFTData, assets) -> Notamon:
|
||||
return Notamon(
|
||||
image_src = to_base64_png(assets[nft.species_id]),
|
||||
effect_css = to_base64_png(assets[nft.effect_id]),
|
||||
nickname = nft.nickname,
|
||||
species_name = 'Mudkip',
|
||||
)
|
||||
|
||||
def select_notamons():
|
||||
client = pbc_client.PbcClient(SESSION, pbc_client.HOSTNAME_TESTNET)
|
||||
|
@ -153,7 +175,7 @@ def select_notamons():
|
|||
assets = list(get_asset_variables(client, ADDRESS_ASSETS))
|
||||
print(assets )
|
||||
|
||||
return [TEST_NOTAMON for i in range(100)]
|
||||
return [nft_to_notamon_view(nft, assets) for nft in nfts]
|
||||
|
||||
@app.route("/")
|
||||
def hello_world():
|
||||
|
|
4
start_server.sh
Normal file
4
start_server.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
cd python/notamon_viewer
|
||||
flask run
|
||||
|
Loading…
Reference in New Issue
Block a user