mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Coordinators methods for API
This commit is contained in:
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -23,6 +24,11 @@ const (
|
||||
maxUint32 = 4294967295
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrNillBidderAddr is used when a nil bidderAddr is received in the getCoordinator method
|
||||
ErrNillBidderAddr = errors.New("biderAddr can not be nil")
|
||||
)
|
||||
|
||||
func postAccountCreationAuth(c *gin.Context) {
|
||||
|
||||
}
|
||||
@@ -285,11 +291,49 @@ func getRecommendedFee(c *gin.Context) {
|
||||
}
|
||||
|
||||
func getCoordinators(c *gin.Context) {
|
||||
// Pagination
|
||||
fromItem, order, limit, err := parsePagination(c)
|
||||
if err != nil {
|
||||
retBadReq(err, c)
|
||||
return
|
||||
}
|
||||
|
||||
// Fetch coordinators from historyDB
|
||||
coordinators, pagination, err := h.GetCoordinators(fromItem, limit, order)
|
||||
if err != nil {
|
||||
retSQLErr(err, c)
|
||||
return
|
||||
}
|
||||
|
||||
// Build succesfull response
|
||||
apiCoordinators := coordinatorsToAPI(coordinators)
|
||||
c.JSON(http.StatusOK, &coordinatorsAPI{
|
||||
Coordinators: apiCoordinators,
|
||||
Pagination: pagination,
|
||||
})
|
||||
}
|
||||
|
||||
func getCoordinator(c *gin.Context) {
|
||||
// Get bidderAddr
|
||||
const name = "bidderAddr"
|
||||
bidderAddr, err := parseEthAddr(c, name)
|
||||
|
||||
if err != nil {
|
||||
retBadReq(err, c)
|
||||
return
|
||||
} else if bidderAddr == nil {
|
||||
retBadReq(ErrNillBidderAddr, c)
|
||||
return
|
||||
}
|
||||
|
||||
coordinator, err := h.GetCoordinator(*bidderAddr)
|
||||
if err != nil {
|
||||
retSQLErr(err, c)
|
||||
return
|
||||
}
|
||||
|
||||
apiCoordinator := coordinatorsToAPI([]historydb.HistoryCoordinator{*coordinator})
|
||||
c.JSON(http.StatusOK, apiCoordinator[0])
|
||||
}
|
||||
|
||||
func retSQLErr(err error, c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user