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
|
||||
@ -60,4 +57,5 @@ func HandleAccountCreate(c echo.Context) error {
|
||||
"trackingId": trackingId,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user