deps(go-playground-validator): use inbuilt eth_addr_checksum validator on routes

This commit is contained in:
Mohamed Sohail 2023-03-28 06:30:29 +00:00
parent ac5567bc56
commit ef5bd1860f
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
4 changed files with 4 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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"`
} }
) )

View File

@ -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()
}