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.

78 lines
1.6 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. // OnlyPendingWithdraws
  23. onlyPendingWithdraws, err := parseQueryBool("onlyPendingWithdraws", nil, c)
  24. if err != nil {
  25. retBadReq(err, c)
  26. return
  27. }
  28. // Pagination
  29. fromItem, order, limit, err := parsePagination(c)
  30. if err != nil {
  31. retBadReq(err, c)
  32. return
  33. }
  34. // Fetch exits from historyDB
  35. exits, pagination, err := h.GetExitsAPI(
  36. addr, bjj, tokenID, idx, batchNum, onlyPendingWithdraws, fromItem, limit, order,
  37. )
  38. if err != nil {
  39. retSQLErr(err, c)
  40. return
  41. }
  42. // Build succesfull response
  43. type exitsResponse struct {
  44. Exits []historydb.ExitAPI `json:"exits"`
  45. Pagination *db.Pagination `json:"pagination"`
  46. }
  47. c.JSON(http.StatusOK, &exitsResponse{
  48. Exits: exits,
  49. Pagination: pagination,
  50. })
  51. }
  52. func getExit(c *gin.Context) {
  53. // Get batchNum and accountIndex
  54. batchNum, err := parseParamUint("batchNum", nil, 0, maxUint32, c)
  55. if err != nil {
  56. retBadReq(err, c)
  57. return
  58. }
  59. idx, err := parseParamIdx(c)
  60. if err != nil {
  61. retBadReq(err, c)
  62. return
  63. }
  64. // Fetch tx from historyDB
  65. exit, err := h.GetExitAPI(batchNum, idx)
  66. if err != nil {
  67. retSQLErr(err, c)
  68. return
  69. }
  70. // Build succesfull response
  71. c.JSON(http.StatusOK, exit)
  72. }