import requests import json from fastapi import APIRouter, Depends from sqlalchemy.orm import Session from app.api import deps import uuid from app import crud, models from typing import Any router = APIRouter() baseUrl = "https://nft-api-staging.joyso.io/api/v1/" headers = { 'Authorization': 'Basic %s' % 'bmZ0OmMxOTEzOWMzYjM3YjdjZWU3ZmY3OTFiZGU3NzdjZWNl' } # Get address @router.get("/fetchaddress") def fetch_address( uid: str = "test01", ): """ Get Address """ path = 'accounts/' account_name = uid r = requests.get(baseUrl + path + account_name, headers=headers) return r.json() # Get nft balance @router.get("/nfts") def nft_balence( uid: str = "test01", ) -> Any: """ Check NFT Balance """ path = 'accounts/' path2 = '/nft_balances' account_name = uid r = requests.get(baseUrl + path + account_name + path2, headers=headers) return r.json() # Mint @router.post("/mint") def mint( uid: str = "88888888", address: str = "0x000000", amount: int = "1", db: Session = Depends(deps.get_db), current_user: models.users = Depends(deps.get_current_active_superuser), ) -> Any: """ Mint NFT """ path = "erc1155/mint" txid = str(uuid.uuid4()) to = address uid = uid amount = amount data = { "txid": txid, "to": to, "uid": uid, "amount": amount } if crud.user.is_superuser(current_user): r = requests.post( baseUrl + path, headers=headers, data=json.dumps(data) ) return r.text else: return "access denied" # Transfer @router.post("/transfer") def transfer_single( address: str ="0xe43250cd5ab89edcabc942b65dea3e1d4a220ce2", uid: str = "88888888", ): """ Transfer NFT """ path = "accounts/test01/erc1155/safe_transfer_to" txid = uuid.uuid4() to = address uid = uid contract = "0xe0d9102c88b09369df99b1c126fb2eebc13804f8" value = "1" data = { "txid": txid, "to": to, "uid": uid, "contract": contract, "value": value } r = requests.post(baseUrl+path, headers=headers, data=data) return r.json() # Get transaction status @router.get("/transaction") def transaction_status( uid: str = "test01", ) -> Any: """ Check NFT Transaction Status """ path = 'accounts/' path2 = '/nft_balances' account_name = uid r = requests.get(baseUrl + path + account_name + path2, headers=headers) return r.json()