refactor: use echo ctx only for cancellation/propagation

This commit is contained in:
Mohamed Sohail 2023-03-28 06:39:44 +00:00
parent ef5bd1860f
commit 5f5678e25b
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
5 changed files with 173 additions and 178 deletions

View File

@ -29,12 +29,6 @@ func initApiServer(custodialContainer *custodial.Custodial) *echo.Echo {
} }
server.HTTPErrorHandler = customHTTPErrorHandler server.HTTPErrorHandler = customHTTPErrorHandler
server.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Set("cu", custodialContainer)
return next(c)
}
})
server.Use(middleware.Recover()) server.Use(middleware.Recover())
server.Use(middleware.BodyLimit("1M")) server.Use(middleware.BodyLimit("1M"))
server.Use(middleware.ContextTimeout(contextTimeout)) server.Use(middleware.ContextTimeout(contextTimeout))
@ -48,10 +42,10 @@ func initApiServer(custodialContainer *custodial.Custodial) *echo.Echo {
apiRoute := server.Group("/api", systemGlobalLock) apiRoute := server.Group("/api", systemGlobalLock)
apiRoute.POST("/account/create", api.HandleAccountCreate) apiRoute.POST("/account/create", api.HandleAccountCreate(custodialContainer))
apiRoute.GET("/account/status/:address", api.HandleNetworkAccountStatus) apiRoute.GET("/account/status/:address", api.HandleNetworkAccountStatus(custodialContainer))
apiRoute.POST("/sign/transfer", api.HandleSignTransfer) apiRoute.POST("/sign/transfer", api.HandleSignTransfer(custodialContainer))
apiRoute.GET("/track/:trackingId", api.HandleTrackTx) apiRoute.GET("/track/:trackingId", api.HandleTrackTx(custodialContainer))
return server return server
} }

View File

@ -15,11 +15,8 @@ import (
// CreateAccountHandler route. // CreateAccountHandler route.
// POST: /api/account/create // POST: /api/account/create
// Returns the public key. // Returns the public key.
func HandleAccountCreate(c echo.Context) error { func HandleAccountCreate(cu *custodial.Custodial) func(echo.Context) error {
var ( return func(c echo.Context) error {
cu = c.Get("cu").(*custodial.Custodial)
)
generatedKeyPair, err := keypair.Generate() generatedKeyPair, err := keypair.Generate()
if err != nil { if err != nil {
return err return err
@ -61,3 +58,4 @@ func HandleAccountCreate(c echo.Context) error {
}, },
}) })
} }
}

View File

@ -11,9 +11,9 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
func HandleNetworkAccountStatus(c echo.Context) error { func HandleNetworkAccountStatus(cu *custodial.Custodial) func(echo.Context) error {
return func(c echo.Context) error {
var ( var (
cu = c.Get("cu").(*custodial.Custodial)
accountStatusRequest struct { accountStatusRequest struct {
Address string `param:"address" validate:"required,eth_addr_checksum"` Address string `param:"address" validate:"required,eth_addr_checksum"`
} }
@ -49,3 +49,4 @@ func HandleNetworkAccountStatus(c echo.Context) error {
}, },
}) })
} }
}

View File

@ -21,9 +21,9 @@ import (
// amount -> int (6 d.p. precision) // amount -> int (6 d.p. precision)
// e.g. 1000000 = 1 VOUCHER // e.g. 1000000 = 1 VOUCHER
// Returns the task id. // Returns the task id.
func HandleSignTransfer(c echo.Context) error { func HandleSignTransfer(cu *custodial.Custodial) func(echo.Context) error {
return func(c echo.Context) error {
var ( var (
cu = c.Get("cu").(*custodial.Custodial)
req struct { req struct {
From string `json:"from" validate:"required,eth_addr_checksum"` From string `json:"from" validate:"required,eth_addr_checksum"`
To string `json:"to" validate:"required,eth_addr_checksum"` To string `json:"to" validate:"required,eth_addr_checksum"`
@ -96,3 +96,4 @@ func HandleSignTransfer(c echo.Context) error {
}, },
}) })
} }
}

View File

@ -12,9 +12,9 @@ import (
// Route param: // Route param:
// trackingId -> tracking UUID // trackingId -> tracking UUID
// Returns array of tx status. // Returns array of tx status.
func HandleTrackTx(c echo.Context) error { func HandleTrackTx(cu *custodial.Custodial) func(echo.Context) error {
return func(c echo.Context) error {
var ( var (
cu = c.Get("cu").(*custodial.Custodial)
txStatusRequest struct { txStatusRequest struct {
TrackingId string `param:"trackingId" validate:"required,uuid"` TrackingId string `param:"trackingId" validate:"required,uuid"`
} }
@ -40,3 +40,4 @@ func HandleTrackTx(c echo.Context) error {
}, },
}) })
} }
}