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.

77 lines
1.6 KiB

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