-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
get_unique_proposers.go
51 lines (42 loc) 路 1.28 KB
/
get_unique_proposers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package http
import (
"net/http"
"github.com/cyberhorsey/webutils"
"github.com/labstack/echo/v4"
"github.com/patrickmn/go-cache"
"github.com/taikoxyz/taiko-mono/packages/eventindexer"
)
type uniqueProposersResp struct {
Proposers []eventindexer.UniqueProposersResponse `json:"proposers"`
UniqueProposers int `json:"uniqueProposers"`
}
// GetUniqueProposers
//
// returns all unique proposers
//
// @Summary Get unique proposers
// @ID get-unique-proposers
// @Accept json
// @Produce json
// @Success 200 {object} uniqueProposersResp
// @Router /uniqueProposers [get]
func (srv *Server) GetUniqueProposers(c echo.Context) error {
cached, found := srv.cache.Get(CacheKeyUniqueProposers)
var proposers []eventindexer.UniqueProposersResponse
var err error
if found {
proposers = cached.([]eventindexer.UniqueProposersResponse)
} else {
proposers, err = srv.eventRepo.FindUniqueProposers(
c.Request().Context(),
)
if err != nil {
return webutils.LogAndRenderErrors(c, http.StatusUnprocessableEntity, err)
}
srv.cache.Set(CacheKeyUniqueProposers, proposers, cache.DefaultExpiration)
}
return c.JSON(http.StatusOK, &uniqueProposersResp{
Proposers: proposers,
UniqueProposers: len(proposers),
})
}