From 6029ce24726ea1c1312acdad2b2c112984fcc146 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 27 Apr 2020 14:57:17 +0200 Subject: [PATCH] rpc: use hexutil.Big in example --- rpc/client_example_test.go | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/rpc/client_example_test.go b/rpc/client_example_test.go index 8638ee1f0c..4f5760b2bb 100644 --- a/rpc/client_example_test.go +++ b/rpc/client_example_test.go @@ -18,11 +18,10 @@ package rpc_test import ( "context" - "encoding/json" "fmt" - "math/big" "time" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/rpc" ) @@ -36,28 +35,12 @@ import ( // creates a subscription which fires block objects when new blocks arrive. type Block struct { - Number *BigInt -} - -type BigInt struct { - big.Int -} - -func (i *BigInt) UnmarshalJSON(b []byte) error { - var val string - err := json.Unmarshal(b, &val) - if err != nil { - return err - } - - i.SetString(val[2:], 16) - - return nil + Number *hexutil.Big } func ExampleClientSubscription() { // Connect the client. - client, _ := rpc.Dial("ws://127.0.0.1:8485") + client, _ := rpc.Dial("ws://127.0.0.1:8545") subch := make(chan Block) // Ensure that subch receives the latest block. @@ -92,7 +75,8 @@ func subscribeBlocks(client *rpc.Client, subch chan Block) { // The connection is established now. // Update the channel with the current block. var lastBlock Block - if err := client.CallContext(ctx, &lastBlock, "eth_getBlockByNumber", "latest", false); err != nil { + err = client.CallContext(ctx, &lastBlock, "eth_getBlockByNumber", "latest", false) + if err != nil { fmt.Println("can't get latest block:", err) return }