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.
This commit is contained in:
parent
72a62f1292
commit
bfa2d54e16
2 changed files with 16 additions and 17 deletions
pkg/rpc
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/core"
|
"github.com/CityOfZion/neo-go/pkg/core"
|
||||||
"github.com/CityOfZion/neo-go/pkg/core/state"
|
"github.com/CityOfZion/neo-go/pkg/core/state"
|
||||||
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
"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/io"
|
||||||
"github.com/CityOfZion/neo-go/pkg/network"
|
"github.com/CityOfZion/neo-go/pkg/network"
|
||||||
"github.com/CityOfZion/neo-go/pkg/rpc/result"
|
"github.com/CityOfZion/neo-go/pkg/rpc/result"
|
||||||
|
@ -209,7 +210,7 @@ Methods:
|
||||||
resultsErr = errInvalidParams
|
resultsErr = errInvalidParams
|
||||||
break Methods
|
break Methods
|
||||||
}
|
}
|
||||||
results = wrappers.ValidateAddress(param.Value)
|
results = validateAddress(param.Value)
|
||||||
|
|
||||||
case "getassetstate":
|
case "getassetstate":
|
||||||
getassetstateCalled.Inc()
|
getassetstateCalled.Inc()
|
||||||
|
@ -551,3 +552,14 @@ func (s *Server) blockHeightFromParam(param *Param) (int, error) {
|
||||||
}
|
}
|
||||||
return num, nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -1,22 +1,9 @@
|
||||||
package wrappers
|
package wrappers
|
||||||
|
|
||||||
import (
|
// ValidateAddressResponse represents response to validate address call. Notice
|
||||||
"github.com/CityOfZion/neo-go/pkg/encoding/address"
|
// Address is an interface{} here because server echoes back whatever address
|
||||||
)
|
// value user has sent to it, even if it's not a string.
|
||||||
|
|
||||||
// ValidateAddressResponse represents response to validate address call.
|
|
||||||
type ValidateAddressResponse struct {
|
type ValidateAddressResponse struct {
|
||||||
Address interface{} `json:"address"`
|
Address interface{} `json:"address"`
|
||||||
IsValid bool `json:"isvalid"`
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue