123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- 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()
|