mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-23 06:36:46 +01:00
deps(go-playground-validator): use inbuilt eth_addr_checksum validator on routes
This commit is contained in:
parent
ac5567bc56
commit
ef5bd1860f
@ -20,7 +20,6 @@ const (
|
|||||||
// Bootstrap API server.
|
// Bootstrap API server.
|
||||||
func initApiServer(custodialContainer *custodial.Custodial) *echo.Echo {
|
func initApiServer(custodialContainer *custodial.Custodial) *echo.Echo {
|
||||||
customValidator := validator.New()
|
customValidator := validator.New()
|
||||||
customValidator.RegisterValidation("eth_checksum", api.EthChecksumValidator)
|
|
||||||
|
|
||||||
server := echo.New()
|
server := echo.New()
|
||||||
server.HideBanner = true
|
server.HideBanner = true
|
||||||
|
@ -15,7 +15,7 @@ func HandleNetworkAccountStatus(c echo.Context) error {
|
|||||||
var (
|
var (
|
||||||
cu = c.Get("cu").(*custodial.Custodial)
|
cu = c.Get("cu").(*custodial.Custodial)
|
||||||
accountStatusRequest struct {
|
accountStatusRequest struct {
|
||||||
Address string `param:"address" validate:"required,eth_checksum"`
|
Address string `param:"address" validate:"required,eth_addr_checksum"`
|
||||||
}
|
}
|
||||||
networkBalance big.Int
|
networkBalance big.Int
|
||||||
networkNonce uint64
|
networkNonce uint64
|
||||||
|
@ -25,9 +25,9 @@ func HandleSignTransfer(c echo.Context) error {
|
|||||||
var (
|
var (
|
||||||
cu = c.Get("cu").(*custodial.Custodial)
|
cu = c.Get("cu").(*custodial.Custodial)
|
||||||
req struct {
|
req struct {
|
||||||
From string `json:"from" validate:"required,eth_checksum"`
|
From string `json:"from" validate:"required,eth_addr_checksum"`
|
||||||
To string `json:"to" validate:"required,eth_checksum"`
|
To string `json:"to" validate:"required,eth_addr_checksum"`
|
||||||
VoucherAddress string `json:"voucherAddress" validate:"required,eth_checksum"`
|
VoucherAddress string `json:"voucherAddress" validate:"required,eth_addr_checksum"`
|
||||||
Amount uint64 `json:"amount" validate:"required"`
|
Amount uint64 `json:"amount" validate:"required"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/celo-org/celo-blockchain/common"
|
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,12 +16,3 @@ func (v *Validator) Validate(i interface{}) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func EthChecksumValidator(fl validator.FieldLevel) bool {
|
|
||||||
addr, err := common.NewMixedcaseAddressFromString(fl.Field().String())
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return addr.ValidChecksum()
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user