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