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.

44 lines
995 B

  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) getCoordinators(c *gin.Context) {
  8. bidderAddr, err := parseQueryEthAddr("bidderAddr", c)
  9. if err != nil {
  10. retBadReq(err, c)
  11. return
  12. }
  13. forgerAddr, err := parseQueryEthAddr("forgerAddr", c)
  14. if err != nil {
  15. retBadReq(err, 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. // Fetch coordinators from historyDB
  25. coordinators, pendingItems, err := a.h.GetCoordinatorsAPI(bidderAddr, forgerAddr, fromItem, limit, order)
  26. if err != nil {
  27. retSQLErr(err, c)
  28. return
  29. }
  30. // Build successful response
  31. type coordinatorsResponse struct {
  32. Coordinators []historydb.CoordinatorAPI `json:"coordinators"`
  33. PendingItems uint64 `json:"pendingItems"`
  34. }
  35. c.JSON(http.StatusOK, &coordinatorsResponse{
  36. Coordinators: coordinators,
  37. PendingItems: pendingItems,
  38. })
  39. }