From aa70048e5021bc5d5c3e13e4b6c7bdb7d9b4f065 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 24 Nov 2016 14:04:48 +0100 Subject: [PATCH] rpc: make BlockNumber a fmt.Stringer --- rpc/types.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rpc/types.go b/rpc/types.go index ebe3883735..5d8a62ed69 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -23,6 +23,7 @@ import ( "math" "math/big" "reflect" + "strconv" "strings" "sync" @@ -275,6 +276,17 @@ func (bn BlockNumber) Int64() int64 { 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. type HexBytes []byte