forked from TrueCloudLab/neoneo-go
rpc: allow to unmarshal integer params from string
This commit is contained in:
parent
4f26064aab
commit
4e92642dec
1 changed files with 6 additions and 3 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"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.
|
// GetInt returns int value of te parameter.
|
||||||
func (p Param) GetInt() (int, error) {
|
func (p Param) GetInt() (int, error) {
|
||||||
i, ok := p.Value.(int)
|
i, ok := p.Value.(int)
|
||||||
if !ok {
|
if ok {
|
||||||
return 0, errors.New("not an integer")
|
return i, nil
|
||||||
|
} else if s, ok := p.Value.(string); ok {
|
||||||
|
return strconv.Atoi(s)
|
||||||
}
|
}
|
||||||
return i, nil
|
return 0, errors.New("not an integer")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetArray returns a slice of Params stored in the parameter.
|
// GetArray returns a slice of Params stored in the parameter.
|
||||||
|
|
Loading…
Reference in a new issue