hermez-node/api/bids.go
api/bids.goRaw
1package api
2
3import (
4 "errors"
5 "net/http"
6
7 "github.com/gin-gonic/gin"
8 "github.com/hermeznetwork/hermez-node/db/historydb"
9)
10
11func (a *API) getBids(c *gin.Context) {
12 slotNum, bidderAddr, err := parseBidFilters(c)
13 if err != nil {
14 retBadReq(err, c)
15 return
16 }
17 if slotNum == nil && bidderAddr == nil {
18 retBadReq(errors.New("It is necessary to add at least one filter: slotNum or/and bidderAddr"), c)
19 return
20 }
21 // Pagination
22 fromItem, order, limit, err := parsePagination(c)
23 if err != nil {
24 retBadReq(err, c)
25 return
26 }
27
28 bids, pendingItems, err := a.h.GetBidsAPI(
29 slotNum, bidderAddr, fromItem, limit, order,
30 )
31
32 if err != nil {
33 retSQLErr(err, c)
34 return
35 }
36
37 // Build succesfull response
38 type bidsResponse struct {
39 Bids []historydb.BidAPI `json:"bids"`
40 PendingItems uint64 `json:"pendingItems"`
41 }
42 c.JSON(http.StatusOK, &bidsResponse{
43 Bids: bids,
44 PendingItems: pendingItems,
45 })
46}