|
@@ -1,61 +1,127 @@
|
|
|
import requests
|
|
|
-from random import randrange
|
|
|
import json
|
|
|
-from app.schemas import joyso
|
|
|
-from fastapi import APIRouter
|
|
|
+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'}
|
|
|
+headers = {
|
|
|
+ 'Authorization':
|
|
|
+ 'Basic %s' % 'bmZ0OmMxOTEzOWMzYjM3YjdjZWU3ZmY3OTFiZGU3NzdjZWNl'
|
|
|
+}
|
|
|
|
|
|
|
|
|
-# # Get address
|
|
|
-# path = 'accounts/test01'
|
|
|
-# r = requests.get(baseUrl + path, headers=headers)
|
|
|
-#
|
|
|
-# print(r.json())
|
|
|
+# 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")
|
|
|
-async def mint(userModel : joyso.joysoMint):
|
|
|
+def mint(
|
|
|
+ uid: str = "88888888",
|
|
|
+ address: str = "0x000000",
|
|
|
+ amount: int = "0",
|
|
|
+ db: Session = Depends(deps.get_db),
|
|
|
+ skip: int = 0,
|
|
|
+ limit: int = 100,
|
|
|
+ current_user: models.users = Depends(deps.get_current_active_superuser),
|
|
|
+) -> Any:
|
|
|
+ """
|
|
|
+ Mint NFT
|
|
|
+ """
|
|
|
+
|
|
|
path = "erc1155/mint"
|
|
|
txid = str(uuid.uuid4())
|
|
|
- to = userModel.toaddress
|
|
|
- uid = '88888888'
|
|
|
- amount = userModel.amount
|
|
|
+ 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,
|
|
|
- "amount": amount
|
|
|
+ "contract": contract,
|
|
|
+ "value": value
|
|
|
}
|
|
|
|
|
|
- r = requests.post(baseUrl+path, headers=headers, data=json.dumps(data))
|
|
|
-
|
|
|
- return r.text
|
|
|
-
|
|
|
-
|
|
|
-# # Transfer
|
|
|
-# path = "accounts/test01/erc1155/safe_transfer_to"
|
|
|
-# txid = "202112229"
|
|
|
-# to = "0x72487C7A8bA487DFC3ed3Aa055ac5033138D8659"
|
|
|
-# uid = "88888888"
|
|
|
-# contract = "0xe0d9102c88b09369df99b1c126fb2eebc13804f8"
|
|
|
-# value = "1"
|
|
|
-#
|
|
|
-# data = {
|
|
|
-# "txid": txid,
|
|
|
-# "to": to,
|
|
|
-# "uid": uid,
|
|
|
-# "contract": contract,
|
|
|
-# "value": value
|
|
|
-# }
|
|
|
-#
|
|
|
-# r = requests.post(baseUrl+path, headers=headers, data=data)
|
|
|
-#
|
|
|
-# print(r.json())
|
|
|
+ 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()
|