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.

46 lines
942 B

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