@@ -18,6 +18,7 @@ package etherscan
1818import (
1919 "context"
2020 "encoding/json"
21+ "io/ioutil"
2122 "math/big"
2223 "net/http"
2324 "net/url"
@@ -67,9 +68,13 @@ func (etherScan *EtherScan) call(params url.Values, result interface{}) error {
6768 if response .StatusCode != http .StatusOK {
6869 return errp .Newf ("expected 200 OK, got %d" , response .StatusCode )
6970 }
70- if err := json .NewDecoder (response .Body ).Decode (result ); err != nil {
71+ body , err := ioutil .ReadAll (response .Body )
72+ if err != nil {
7173 return errp .WithStack (err )
7274 }
75+ if err := json .Unmarshal (body , result ); err != nil {
76+ return errp .Newf ("unexpected response from EtherScan: %s" , string (body ))
77+ }
7378 return nil
7479}
7580
@@ -368,7 +373,10 @@ func (etherScan *EtherScan) rpcCall(params url.Values, result interface{}) error
368373 if wrapped .Result == nil {
369374 return errp .New ("expected result" )
370375 }
371- return json .Unmarshal (* wrapped .Result , result )
376+ if err := json .Unmarshal (* wrapped .Result , result ); err != nil {
377+ return errp .WithStack (err )
378+ }
379+ return nil
372380}
373381
374382// TransactionReceiptWithBlockNumber implements rpc.Interface.
@@ -435,11 +443,11 @@ func (etherScan *EtherScan) BalanceAt(ctx context.Context, account common.Addres
435443 return nil , err
436444 }
437445 if result .Status != "1" {
438- return nil , errp .New ("unexpected response" )
446+ return nil , errp .New ("unexpected response from EtherScan " )
439447 }
440448 balance , ok := new (big.Int ).SetString (result .Result , 10 )
441449 if ! ok {
442- return nil , errp .New ("unexpected response" )
450+ return nil , errp .New ("unexpected response from EtherScan " )
443451 }
444452 return balance , nil
445453}
0 commit comments