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.

56 lines
1.1 KiB

  1. package api
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "github.com/hermeznetwork/hermez-node/db/historydb"
  6. )
  7. func (a *API) getCoordinator(c *gin.Context) {
  8. // Get bidderAddr
  9. const name = "bidderAddr"
  10. bidderAddr, err := parseParamEthAddr(name, c)
  11. if err != nil {
  12. retBadReq(err, c)
  13. return
  14. } else if bidderAddr == nil {
  15. retBadReq(ErrNillBidderAddr, c)
  16. return
  17. }
  18. coordinator, err := a.h.GetCoordinatorAPI(*bidderAddr)
  19. if err != nil {
  20. retSQLErr(err, c)
  21. return
  22. }
  23. c.JSON(http.StatusOK, coordinator)
  24. }
  25. func (a *API) getCoordinators(c *gin.Context) {
  26. // Pagination
  27. fromItem, order, limit, err := parsePagination(c)
  28. if err != nil {
  29. retBadReq(err, c)
  30. return
  31. }
  32. // Fetch coordinators from historyDB
  33. coordinators, pendingItems, err := a.h.GetCoordinatorsAPI(fromItem, limit, order)
  34. if err != nil {
  35. retSQLErr(err, c)
  36. return
  37. }
  38. // Build succesfull response
  39. type coordinatorsResponse struct {
  40. Coordinators []historydb.CoordinatorAPI `json:"coordinators"`
  41. PendingItems uint64 `json:"pendingItems"`
  42. }
  43. c.JSON(http.StatusOK, &coordinatorsResponse{
  44. Coordinators: coordinators,
  45. PendingItems: pendingItems,
  46. })
  47. }