|
|
|
@ -21,6 +21,7 @@ import ( |
|
|
|
|
"encoding/json" |
|
|
|
|
"fmt" |
|
|
|
|
"math" |
|
|
|
|
"strconv" |
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
@ -191,3 +192,24 @@ func BlockNumberOrHashWithHash(hash common.Hash, canonical bool) BlockNumberOrHa |
|
|
|
|
RequireCanonical: canonical, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// DecimalOrHex unmarshals a non-negative decimal or hex parameter into a uint64.
|
|
|
|
|
type DecimalOrHex uint64 |
|
|
|
|
|
|
|
|
|
// UnmarshalJSON implements json.Unmarshaler.
|
|
|
|
|
func (dh *DecimalOrHex) UnmarshalJSON(data []byte) error { |
|
|
|
|
input := strings.TrimSpace(string(data)) |
|
|
|
|
if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' { |
|
|
|
|
input = input[1 : len(input)-1] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
value, err := strconv.ParseUint(input, 10, 64) |
|
|
|
|
if err != nil { |
|
|
|
|
value, err = hexutil.DecodeUint64(input) |
|
|
|
|
} |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
*dh = DecimalOrHex(value) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|