You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
922 B

  1. package api
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. )
  6. func getHistoryTxs(c *gin.Context) {
  7. // Get query parameters
  8. tokenID, addr, bjj, idx, err := parseAccountFilters(c)
  9. if err != nil {
  10. retBadReq(err, c)
  11. return
  12. }
  13. // BatchNum
  14. batchNum, err := parseQueryUint("batchNum", nil, 0, maxUint32, c)
  15. if err != nil {
  16. retBadReq(err, c)
  17. return
  18. }
  19. // TxType
  20. txType, err := parseQueryTxType(c)
  21. if err != nil {
  22. retBadReq(err, c)
  23. return
  24. }
  25. // Pagination
  26. fromItem, order, limit, err := parsePagination(c)
  27. if err != nil {
  28. retBadReq(err, c)
  29. return
  30. }
  31. // Fetch txs from historyDB
  32. txs, pagination, err := h.GetHistoryTxs(
  33. addr, bjj, tokenID, idx, batchNum, txType, fromItem, limit, order,
  34. )
  35. if err != nil {
  36. retSQLErr(err, c)
  37. return
  38. }
  39. // Build succesfull response
  40. apiTxs := historyTxsToAPI(txs)
  41. c.JSON(http.StatusOK, &historyTxsAPI{
  42. Txs: apiTxs,
  43. Pagination: pagination,
  44. })
  45. }