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.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.BodyLimit("1M"))
server.Use(middleware.ContextTimeout(contextTimeout))
@ -48,10 +42,10 @@ func initApiServer(custodialContainer *custodial.Custodial) *echo.Echo {
apiRoute := server.Group("/api", systemGlobalLock)
apiRoute.POST("/account/create", api.HandleAccountCreate)
apiRoute.GET("/account/status/:address", api.HandleNetworkAccountStatus)
apiRoute.POST("/sign/transfer", api.HandleSignTransfer)
apiRoute.GET("/track/:trackingId", api.HandleTrackTx)
apiRoute.POST("/account/create", api.HandleAccountCreate(custodialContainer))
apiRoute.GET("/account/status/:address", api.HandleNetworkAccountStatus(custodialContainer))
apiRoute.POST("/sign/transfer", api.HandleSignTransfer(custodialContainer))
apiRoute.GET("/track/:trackingId", api.HandleTrackTx(custodialContainer))
return server
}

View File

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

View File

@ -11,9 +11,9 @@ import (
"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 (
cu = c.Get("cu").(*custodial.Custodial)
accountStatusRequest struct {
Address string `param:"address" validate:"required,eth_addr_checksum"`
}
@ -48,4 +48,5 @@ func HandleNetworkAccountStatus(c echo.Context) error {
"nonce": networkNonce,
},
})
}
}

View File

@ -21,9 +21,9 @@ import (
// amount -> int (6 d.p. precision)
// e.g. 1000000 = 1 VOUCHER
// 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 (
cu = c.Get("cu").(*custodial.Custodial)
req struct {
From string `json:"from" validate:"required,eth_addr_checksum"`
To string `json:"to" validate:"required,eth_addr_checksum"`
@ -95,4 +95,5 @@ func HandleSignTransfer(c echo.Context) error {
"trackingId": trackingId,
},
})
}
}

View File

@ -12,9 +12,9 @@ import (
// Route param:
// trackingId -> tracking UUID
// 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 (
cu = c.Get("cu").(*custodial.Custodial)
txStatusRequest struct {
TrackingId string `param:"trackingId" validate:"required,uuid"`
}
@ -39,4 +39,5 @@ func HandleTrackTx(c echo.Context) error {
"transactions": txs,
},
})
}
}