joyso.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 = "1",
  46. db: Session = Depends(deps.get_db),
  47. current_user: models.users = Depends(deps.get_current_active_superuser),
  48. ) -> Any:
  49. """
  50. Mint NFT
  51. """
  52. path = "erc1155/mint"
  53. txid = str(uuid.uuid4())
  54. to = address
  55. uid = uid
  56. amount = amount
  57. data = {
  58. "txid": txid,
  59. "to": to,
  60. "uid": uid,
  61. "amount": amount
  62. }
  63. if crud.user.is_superuser(current_user):
  64. r = requests.post(
  65. baseUrl + path,
  66. headers=headers,
  67. data=json.dumps(data)
  68. )
  69. return r.text
  70. else:
  71. return "access denied"
  72. # Transfer
  73. @router.post("/transfer")
  74. def transfer_single(
  75. address: str ="0xe43250cd5ab89edcabc942b65dea3e1d4a220ce2",
  76. uid: str = "88888888",
  77. ):
  78. """
  79. Transfer NFT
  80. """
  81. path = "accounts/test01/erc1155/safe_transfer_to"
  82. txid = uuid.uuid4()
  83. to = address
  84. uid = uid
  85. contract = "0xe0d9102c88b09369df99b1c126fb2eebc13804f8"
  86. value = "1"
  87. data = {
  88. "txid": txid,
  89. "to": to,
  90. "uid": uid,
  91. "contract": contract,
  92. "value": value
  93. }
  94. r = requests.post(baseUrl+path, headers=headers, data=data)
  95. return r.json()
  96. # Get transaction status
  97. @router.get("/transaction")
  98. def transaction_status(
  99. uid: str = "test01",
  100. ) -> Any:
  101. """
  102. Check NFT Transaction Status
  103. """
  104. path = 'accounts/'
  105. path2 = '/nft_balances'
  106. account_name = uid
  107. r = requests.get(baseUrl + path + account_name + path2, headers=headers)
  108. return r.json()