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.

72 lines
1.4 KiB

  1. package api
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "github.com/hermeznetwork/hermez-node/db"
  6. "github.com/hermeznetwork/hermez-node/db/historydb"
  7. )
  8. func getExits(c *gin.Context) {
  9. // Get query parameters
  10. // Account filters
  11. tokenID, addr, bjj, idx, err := parseAccountFilters(c)
  12. if err != nil {
  13. retBadReq(err, c)
  14. return
  15. }
  16. // BatchNum
  17. batchNum, err := parseQueryUint("batchNum", nil, 0, maxUint32, c)
  18. if err != nil {
  19. retBadReq(err, c)
  20. return
  21. }
  22. // Pagination
  23. fromItem, order, limit, err := parsePagination(c)
  24. if err != nil {
  25. retBadReq(err, c)
  26. return
  27. }
  28. // Fetch exits from historyDB
  29. exits, pagination, err := h.GetExitsAPI(
  30. addr, bjj, tokenID, idx, batchNum, fromItem, limit, order,
  31. )
  32. if err != nil {
  33. retSQLErr(err, c)
  34. return
  35. }
  36. // Build succesfull response
  37. type exitsResponse struct {
  38. Exits []historydb.ExitAPI `json:"exits"`
  39. Pagination *db.Pagination `json:"pagination"`
  40. }
  41. c.JSON(http.StatusOK, &exitsResponse{
  42. Exits: exits,
  43. Pagination: pagination,
  44. })
  45. }
  46. func getExit(c *gin.Context) {
  47. // Get batchNum and accountIndex
  48. batchNum, err := parseParamUint("batchNum", nil, 0, maxUint32, c)
  49. if err != nil {
  50. retBadReq(err, c)
  51. return
  52. }
  53. idx, err := parseParamIdx(c)
  54. if err != nil {
  55. retBadReq(err, c)
  56. return
  57. }
  58. // Fetch tx from historyDB
  59. exit, err := h.GetExitAPI(batchNum, idx)
  60. if err != nil {
  61. retSQLErr(err, c)
  62. return
  63. }
  64. // Build succesfull response
  65. c.JSON(http.StatusOK, exit)
  66. }