mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
Update types.go
This commit is contained in:
parent
5dd0fe2f53
commit
9e40f0f694
1 changed files with 1 additions and 5 deletions
|
|
@ -459,13 +459,9 @@ func (addr AddressEIP55) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
type Decimal uint64
|
type Decimal uint64
|
||||||
|
|
||||||
func isString(input []byte) bool {
|
|
||||||
return len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"'
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON parses a hash in hex syntax.
|
// UnmarshalJSON parses a hash in hex syntax.
|
||||||
func (d *Decimal) UnmarshalJSON(input []byte) error {
|
func (d *Decimal) UnmarshalJSON(input []byte) error {
|
||||||
if !isString(input) {
|
if !(len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"') {
|
||||||
return &json.UnmarshalTypeError{Value: "non-string", Type: reflect.TypeFor[uint64]()}
|
return &json.UnmarshalTypeError{Value: "non-string", Type: reflect.TypeFor[uint64]()}
|
||||||
}
|
}
|
||||||
if i, err := strconv.ParseUint(string(input[1:len(input)-1]), 10, 64); err == nil {
|
if i, err := strconv.ParseUint(string(input[1:len(input)-1]), 10, 64); err == nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue