2022-11-23 04:06:29 -08:00
|
|
|
// Package governor handle the request of governor data from governor endpoint defined in the api.
|
2022-11-17 07:37:29 -08:00
|
|
|
package governor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/wormhole-foundation/wormhole-explorer/api/middleware"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// Controller definition.
|
2022-11-17 07:37:29 -08:00
|
|
|
type Controller struct {
|
|
|
|
srv *Service
|
|
|
|
logger *zap.Logger
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// NewController create a new controler.
|
2022-11-17 07:37:29 -08:00
|
|
|
func NewController(serv *Service, logger *zap.Logger) *Controller {
|
|
|
|
return &Controller{srv: serv, logger: logger.With(zap.String("module", "GovernorController"))}
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// FindGovernorConfigurations handler for the endpoint /governor/config/
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) FindGovernorConfigurations(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
2022-11-17 07:37:29 -08:00
|
|
|
governorConfigs, err := c.srv.FindGovernorConfig(ctx.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(governorConfigs)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// FindGovernorConfigurationByGuardianAddress handler for the endpoint /governor/config/:guardian_address.
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) FindGovernorConfigurationByGuardianAddress(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
|
|
|
guardianAddress, err := middleware.ExtractGuardianAddress(ctx, c.logger)
|
2022-11-17 07:37:29 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
govConfig, err := c.srv.FindGovernorConfigByGuardianAddress(ctx.Context(), guardianAddress, p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(govConfig)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// FindGovernorStatus handler for the endpoint /governor/status/.
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) FindGovernorStatus(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
2022-11-17 07:37:29 -08:00
|
|
|
governorStatus, err := c.srv.FindGovernorStatus(ctx.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(governorStatus)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// FindGovernorStatusByGuardianAddress handler for the endpoint /governor/status/:guardian_address.
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) FindGovernorStatusByGuardianAddress(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
|
|
|
guardianAddress, err := middleware.ExtractGuardianAddress(ctx, c.logger)
|
2022-11-17 07:37:29 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
govStatus, err := c.srv.FindGovernorStatusByGuardianAddress(ctx.Context(), guardianAddress, p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(govStatus)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// GetGovernorLimit handler for the endpoint /governor/limit/
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) GetGovernorLimit(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
2022-11-17 07:37:29 -08:00
|
|
|
governorLimit, err := c.srv.GetGovernorLimit(ctx.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(governorLimit)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// FindNotionalLimit handler for the endpoint governor/notional/limit/
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) FindNotionalLimit(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
2022-11-17 07:37:29 -08:00
|
|
|
notionalLimit, err := c.srv.FindNotionalLimit(ctx.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(notionalLimit)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// GetNotionalLimitByChainID handler for the endpoint governor/notional/limit/:chain.
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) GetNotionalLimitByChainID(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
|
|
|
chainID, err := middleware.ExtractChainID(ctx, c.logger)
|
2022-11-17 07:37:29 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
notionalLimit, err := c.srv.GetNotionalLimitByChainID(ctx.Context(), p, chainID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(notionalLimit)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// GetAvailableNotional handler for the endpoint governor/notional/available/
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) GetAvailableNotional(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
2022-11-17 07:37:29 -08:00
|
|
|
notionalAvaialabilies, err := c.srv.GetAvailableNotional(ctx.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(notionalAvaialabilies)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// GetAvailableNotionalByChainID handler for the endpoint governor/notional/available/:chain
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) GetAvailableNotionalByChainID(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
|
|
|
chainID, err := middleware.ExtractChainID(ctx, c.logger)
|
2022-11-17 07:37:29 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
response, err := c.srv.GetAvailableNotionalByChainID(ctx.Context(), p, chainID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(response)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// GetMaxNotionalAvailableByChainID handler for the endpoint governor/max_available/:chain.
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) GetMaxNotionalAvailableByChainID(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
|
|
|
chainID, err := middleware.ExtractChainID(ctx, c.logger)
|
2022-11-17 07:37:29 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
response, err := c.srv.GetMaxNotionalAvailableByChainID(ctx.Context(), p, chainID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(response)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// GetEnqueueVass handler for the endpoint governor/enqueued_vaas/
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) GetEnqueueVass(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
2022-11-17 07:37:29 -08:00
|
|
|
enqueuedVaas, err := c.srv.GetEnqueueVass(ctx.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(enqueuedVaas)
|
|
|
|
}
|
|
|
|
|
2022-11-23 04:06:29 -08:00
|
|
|
// GetEnqueueVassByChainID handler for the endpoint governor/enqueued_vaas/:chain.
|
2022-11-17 07:37:29 -08:00
|
|
|
func (c *Controller) GetEnqueueVassByChainID(ctx *fiber.Ctx) error {
|
2022-11-23 04:06:29 -08:00
|
|
|
p := middleware.GetPaginationFromContext(ctx)
|
|
|
|
chainID, err := middleware.ExtractChainID(ctx, c.logger)
|
2022-11-17 07:37:29 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
enqueuedVaas, err := c.srv.GetEnqueueVassByChainID(ctx.Context(), p, chainID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ctx.JSON(enqueuedVaas)
|
|
|
|
}
|