mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-12-04 19:06:08 +01:00
feat: add network account status (nonce, balance)
This commit is contained in:
parent
5679a675f3
commit
144d5018ea
@ -50,6 +50,7 @@ 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)
|
||||||
|
apiRoute.GET("/account/status/:address", api.HandleNetworkAccountStatus)
|
||||||
apiRoute.POST("/sign/transfer", api.HandleSignTransfer)
|
apiRoute.POST("/sign/transfer", api.HandleSignTransfer)
|
||||||
apiRoute.GET("/track/:trackingId", api.HandleTrackTx)
|
apiRoute.GET("/track/:trackingId", api.HandleTrackTx)
|
||||||
|
|
||||||
|
51
internal/api/network.go
Normal file
51
internal/api/network.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/grassrootseconomics/cic-custodial/internal/custodial"
|
||||||
|
"github.com/grassrootseconomics/w3-celo-patch"
|
||||||
|
"github.com/grassrootseconomics/w3-celo-patch/module/eth"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HandleNetworkAccountStatus(c echo.Context) error {
|
||||||
|
var (
|
||||||
|
cu = c.Get("cu").(*custodial.Custodial)
|
||||||
|
accountStatusRequest struct {
|
||||||
|
Address string `param:"address" validate:"required,eth_checksum"`
|
||||||
|
}
|
||||||
|
networkBalance big.Int
|
||||||
|
networkNonce uint64
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := c.Bind(&accountStatusRequest); err != nil {
|
||||||
|
return NewBadRequestError(ErrInvalidJSON)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.Validate(accountStatusRequest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cu.CeloProvider.Client.CallCtx(
|
||||||
|
c.Request().Context(),
|
||||||
|
eth.Nonce(w3.A(accountStatusRequest.Address), nil).Returns(&networkNonce),
|
||||||
|
eth.Balance(w3.A(accountStatusRequest.Address), nil).Returns(&networkBalance),
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if networkNonce > 0 {
|
||||||
|
networkNonce--
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, OkResp{
|
||||||
|
Ok: true,
|
||||||
|
Result: H{
|
||||||
|
"balance": fmt.Sprintf("%s CELO", w3.FromWei(&networkBalance, 18)),
|
||||||
|
"nonce": networkNonce,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user