joyso.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import requests
  2. import json
  3. from fastapi import APIRouter, Depends
  4. from sqlalchemy.orm import Session
  5. from app.api import deps
  6. import uuid
  7. from app import crud, models
  8. from typing import Any
  9. router = APIRouter()
  10. baseUrl = "https://nft-api-staging.joyso.io/api/v1/"
  11. headers = {
  12. 'Authorization':
  13. 'Basic %s' % 'bmZ0OmMxOTEzOWMzYjM3YjdjZWU3ZmY3OTFiZGU3NzdjZWNl'
  14. }
  15. # Get address
  16. @router.get("/fetchaddress")
  17. def fetch_address(
  18. uid: str = "test01",
  19. ):
  20. """
  21. Get Address
  22. """
  23. path = 'accounts/'
  24. account_name = uid
  25. r = requests.get(baseUrl + path + account_name, headers=headers)
  26. return r.json()
  27. # Get nft balance
  28. @router.get("/nfts")
  29. def nft_balence(
  30. uid: str = "test01",
  31. ) -> Any:
  32. """
  33. Check NFT Balance
  34. """
  35. path = 'accounts/'
  36. path2 = '/nft_balances'
  37. account_name = uid
  38. r = requests.get(baseUrl + path + account_name + path2, headers=headers)
  39. return r.json()
  40. # Mint
  41. @router.post("/mint")
  42. def mint(
  43. uid: str = "88888888",
  44. address: str = "0x000000",
  45. amount: int = "0",
  46. db: Session = Depends(deps.get_db),
  47. skip: int = 0,
  48. limit: int = 100,
  49. current_user: models.users = Depends(deps.get_current_active_superuser),
  50. ) -> Any:
  51. """
  52. Mint NFT
  53. """
  54. path = "erc1155/mint"
  55. txid = str(uuid.uuid4())
  56. to = address
  57. uid = uid
  58. amount = amount
  59. data = {
  60. "txid": txid,
  61. "to": to,
  62. "uid": uid,
  63. "amount": amount
  64. }
  65. if crud.user.is_superuser(current_user):
  66. r = requests.post(
  67. baseUrl + path,
  68. headers=headers,
  69. data=json.dumps(data)
  70. )
  71. return r.text
  72. else:
  73. return "access denied"
  74. # Transfer
  75. @router.post("/transfer")
  76. def transfer_single(
  77. address: str ="0xe43250cd5ab89edcabc942b65dea3e1d4a220ce2",
  78. uid: str = "88888888",
  79. ):
  80. """
  81. Transfer NFT
  82. """
  83. path = "accounts/test01/erc1155/safe_transfer_to"
  84. txid = uuid.uuid4()
  85. to = address
  86. uid = uid
  87. contract = "0xe0d9102c88b09369df99b1c126fb2eebc13804f8"
  88. value = "1"
  89. data = {
  90. "txid": txid,
  91. "to": to,
  92. "uid": uid,
  93. "contract": contract,
  94. "value": value
  95. }
  96. r = requests.post(baseUrl+path, headers=headers, data=data)
  97. return r.json()
  98. # Get transaction status
  99. @router.get("/transaction")
  100. def transaction_status(
  101. uid: str = "test01",
  102. ) -> Any:
  103. """
  104. Check NFT Transaction Status
  105. """
  106. path = 'accounts/'
  107. path2 = '/nft_balances'
  108. account_name = uid
  109. r = requests.get(baseUrl + path + account_name + path2, headers=headers)
  110. return r.json()