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.

57 lines
1.2 KiB

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