Add support for JSON decimal integer block numbers

This commit is contained in:
Nick Johnson 2018-09-25 15:32:40 +01:00
parent 5b4438d6bb
commit fab8333bd2

View file

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"math" "math"
"reflect" "reflect"
"strconv"
"strings" "strings"
"sync" "sync"
@ -135,6 +136,11 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
input := strings.TrimSpace(string(data)) input := strings.TrimSpace(string(data))
if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' { if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' {
input = input[1 : len(input)-1] input = input[1 : len(input)-1]
} else {
// Integer block number
value, err := strconv.Atoi(string(data))
*bn = BlockNumber(value)
return err
} }
switch input { switch input {