From bfa2d54e16a17613944a4f2d15d4c1836c487a30 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 13 Jan 2020 11:27:22 +0300 Subject: [PATCH] rpc: move validateAddress() function from wrappers into server It's a server implementation detail, it has nothing to do with the data format itself. It also makes no sense exporing it. --- pkg/rpc/server.go | 14 +++++++++++++- pkg/rpc/wrappers/validate_address.go | 19 +++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pkg/rpc/server.go b/pkg/rpc/server.go index 1ebb345b6..880d3959b 100644 --- a/pkg/rpc/server.go +++ b/pkg/rpc/server.go @@ -11,6 +11,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/core" "github.com/CityOfZion/neo-go/pkg/core/state" "github.com/CityOfZion/neo-go/pkg/core/transaction" + "github.com/CityOfZion/neo-go/pkg/encoding/address" "github.com/CityOfZion/neo-go/pkg/io" "github.com/CityOfZion/neo-go/pkg/network" "github.com/CityOfZion/neo-go/pkg/rpc/result" @@ -209,7 +210,7 @@ Methods: resultsErr = errInvalidParams break Methods } - results = wrappers.ValidateAddress(param.Value) + results = validateAddress(param.Value) case "getassetstate": getassetstateCalled.Inc() @@ -551,3 +552,14 @@ func (s *Server) blockHeightFromParam(param *Param) (int, error) { } return num, nil } + +// validateAddress verifies that the address is a correct NEO address +// see https://docs.neo.org/en-us/node/cli/2.9.4/api/validateaddress.html +func validateAddress(addr interface{}) wrappers.ValidateAddressResponse { + resp := wrappers.ValidateAddressResponse{Address: addr} + if addr, ok := addr.(string); ok { + _, err := address.StringToUint160(addr) + resp.IsValid = (err == nil) + } + return resp +} diff --git a/pkg/rpc/wrappers/validate_address.go b/pkg/rpc/wrappers/validate_address.go index dfde7b833..3af2c0d23 100644 --- a/pkg/rpc/wrappers/validate_address.go +++ b/pkg/rpc/wrappers/validate_address.go @@ -1,22 +1,9 @@ package wrappers -import ( - "github.com/CityOfZion/neo-go/pkg/encoding/address" -) - -// ValidateAddressResponse represents response to validate address call. +// ValidateAddressResponse represents response to validate address call. Notice +// Address is an interface{} here because server echoes back whatever address +// value user has sent to it, even if it's not a string. type ValidateAddressResponse struct { Address interface{} `json:"address"` IsValid bool `json:"isvalid"` } - -// ValidateAddress verifies that the address is a correct NEO address -// see https://docs.neo.org/en-us/node/cli/2.9.4/api/validateaddress.html -func ValidateAddress(addr interface{}) ValidateAddressResponse { - resp := ValidateAddressResponse{Address: addr} - if addr, ok := addr.(string); ok { - _, err := address.StringToUint160(addr) - resp.IsValid = err == nil - } - return resp -}