mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-21 13:56:47 +01:00
refactor: use echo ctx only for cancellation/propagation
This commit is contained in:
parent
ef5bd1860f
commit
5f5678e25b
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
@ -61,3 +58,4 @@ func HandleAccountCreate(c echo.Context) error {
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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"`
|
||||
}
|
||||
@ -49,3 +49,4 @@ func HandleNetworkAccountStatus(c echo.Context) error {
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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"`
|
||||
@ -96,3 +96,4 @@ func HandleSignTransfer(c echo.Context) error {
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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"`
|
||||
}
|
||||
@ -40,3 +40,4 @@ func HandleTrackTx(c echo.Context) error {
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user