mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-12-23 10:17:32 +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.
|
||||
func initApiServer(custodialContainer *custodial.Custodial) *echo.Echo {
|
||||
customValidator := validator.New()
|
||||
customValidator.RegisterValidation("eth_checksum", api.EthChecksumValidator)
|
||||
|
||||
server := echo.New()
|
||||
server.HideBanner = true
|
||||
|
@ -15,7 +15,7 @@ func HandleNetworkAccountStatus(c echo.Context) error {
|
||||
var (
|
||||
cu = c.Get("cu").(*custodial.Custodial)
|
||||
accountStatusRequest struct {
|
||||
Address string `param:"address" validate:"required,eth_checksum"`
|
||||
Address string `param:"address" validate:"required,eth_addr_checksum"`
|
||||
}
|
||||
networkBalance big.Int
|
||||
networkNonce uint64
|
||||
|
@ -25,9 +25,9 @@ func HandleSignTransfer(c echo.Context) error {
|
||||
var (
|
||||
cu = c.Get("cu").(*custodial.Custodial)
|
||||
req struct {
|
||||
From string `json:"from" validate:"required,eth_checksum"`
|
||||
To string `json:"to" validate:"required,eth_checksum"`
|
||||
VoucherAddress string `json:"voucherAddress" validate:"required,eth_checksum"`
|
||||
From string `json:"from" validate:"required,eth_addr_checksum"`
|
||||
To string `json:"to" validate:"required,eth_addr_checksum"`
|
||||
VoucherAddress string `json:"voucherAddress" validate:"required,eth_addr_checksum"`
|
||||
Amount uint64 `json:"amount" validate:"required"`
|
||||
}
|
||||
)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
@ -17,12 +16,3 @@ func (v *Validator) Validate(i interface{}) error {
|
||||
}
|
||||
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