rpc: make BlockNumber a fmt.Stringer

This commit is contained in:
Felix Lange 2016-11-24 14:04:48 +01:00
parent 5309cd73cb
commit aa70048e50

View file

@ -23,6 +23,7 @@ import (
"math" "math"
"math/big" "math/big"
"reflect" "reflect"
"strconv"
"strings" "strings"
"sync" "sync"
@ -275,6 +276,17 @@ func (bn BlockNumber) Int64() int64 {
return (int64)(bn) return (int64)(bn)
} }
func (bn BlockNumber) String() string {
switch bn {
case PendingBlockNumber:
return "pending"
case LatestBlockNumber:
return "latest"
default:
return "0x" + strconv.FormatInt(int64(bn), 16)
}
}
// HexBytes JSON-encodes as hex with 0x prefix. // HexBytes JSON-encodes as hex with 0x prefix.
type HexBytes []byte type HexBytes []byte