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.

47 lines
971 B

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