Merge pull request #794 from nspcc-dev/fix/rpc

rpc: allow to unmarshal integer params from string
This commit is contained in:
Roman Khimov 2020-03-25 17:32:36 +03:00 committed by GitHub
commit e5fbf3ef2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
@ -55,10 +56,12 @@ func (p Param) GetString() (string, error) {
// GetInt returns int value of te parameter.
func (p Param) GetInt() (int, error) {
i, ok := p.Value.(int)
if !ok {
return 0, errors.New("not an integer")
}
if ok {
return i, nil
} else if s, ok := p.Value.(string); ok {
return strconv.Atoi(s)
}
return 0, errors.New("not an integer")
}
// GetArray returns a slice of Params stored in the parameter.