mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-21 22:06: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.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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
@ -60,4 +57,5 @@ func HandleAccountCreate(c echo.Context) error {
|
|||||||
"trackingId": trackingId,
|
"trackingId": trackingId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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"`
|
||||||
}
|
}
|
||||||
@ -48,4 +48,5 @@ func HandleNetworkAccountStatus(c echo.Context) error {
|
|||||||
"nonce": networkNonce,
|
"nonce": networkNonce,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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"`
|
||||||
@ -95,4 +95,5 @@ func HandleSignTransfer(c echo.Context) error {
|
|||||||
"trackingId": trackingId,
|
"trackingId": trackingId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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"`
|
||||||
}
|
}
|
||||||
@ -39,4 +39,5 @@ func HandleTrackTx(c echo.Context) error {
|
|||||||
"transactions": txs,
|
"transactions": txs,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user