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

package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/hermeznetwork/hermez-node/db/historydb"
)
func (a *API) getExits(c *gin.Context) {
// Get query parameters
// Account filters
tokenID, addr, bjj, idx, err := parseExitFilters(c)
if err != nil {
retBadReq(err, c)
return
}
// BatchNum
batchNum, err := parseQueryUint("batchNum", nil, 0, maxUint32, c)
if err != nil {
retBadReq(err, c)
return
}
// OnlyPendingWithdraws
onlyPendingWithdraws, err := parseQueryBool("onlyPendingWithdraws", nil, c)
if err != nil {
retBadReq(err, c)
return
}
// Pagination
fromItem, order, limit, err := parsePagination(c)
if err != nil {
retBadReq(err, c)
return
}
// Fetch exits from historyDB
exits, pendingItems, err := a.h.GetExitsAPI(
addr, bjj, tokenID, idx, batchNum, onlyPendingWithdraws, fromItem, limit, order,
)
if err != nil {
retSQLErr(err, c)
return
}
// Build succesfull response
type exitsResponse struct {
Exits []historydb.ExitAPI `json:"exits"`
PendingItems uint64 `json:"pendingItems"`
}
c.JSON(http.StatusOK, &exitsResponse{
Exits: exits,
PendingItems: pendingItems,
})
}
func (a *API) getExit(c *gin.Context) {
// Get batchNum and accountIndex
batchNum, err := parseParamUint("batchNum", nil, 0, maxUint32, c)
if err != nil {
retBadReq(err, c)
return
}
idx, err := parseParamIdx(c)
if err != nil {
retBadReq(err, c)
return
}
// Fetch tx from historyDB
exit, err := a.h.GetExitAPI(batchNum, idx)
if err != nil {
retSQLErr(err, c)
return
}
// Build succesfull response
c.JSON(http.StatusOK, exit)
}