-
Notifications
You must be signed in to change notification settings - Fork 1
/
coordinator.go
38 lines (33 loc) · 868 Bytes
/
coordinator.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
package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/chainbing/node/api/parsers"
"github.com/chainbing/node/db/historydb"
)
func (a *API) getCoordinators(c *gin.Context) {
filters, err := parsers.ParseCoordinatorsFilters(c)
if err != nil {
retBadReq(&apiError{
Err: err,
Code: ErrParamValidationFailedCode,
Type: ErrParamValidationFailedType,
}, c)
return
}
// Fetch coordinators from historyDB
coordinators, pendingItems, err := a.h.GetCoordinatorsAPI(filters)
if err != nil {
retSQLErr(err, c)
return
}
// Build successful response
type coordinatorsResponse struct {
Coordinators []historydb.CoordinatorAPI `json:"coordinators"`
PendingItems uint64 `json:"pendingItems"`
}
c.JSON(http.StatusOK, &coordinatorsResponse{
Coordinators: coordinators,
PendingItems: pendingItems,
})
}