Skip to content

Commit 78f8a60

Browse files
committed
Merge branch 'improve-errormsg'
2 parents 279b017 + 172c9e4 commit 78f8a60

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

33
## [Unreleased]
4+
- Improve error message when EtherScan responds with a rate limit error.
5+
6+
## 4.28.0 [released 2021-05-27]
47
- Bundle BitBox02 v9.6.0 firmware
58
- New feature: add additional accounts
69
- Remove the setting 'Separate accounts by address type (legacy behavior)'. BitBox02 accounts are now always unified.

backend/coins/eth/etherscan/etherscan.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package etherscan
1818
import (
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

Comments
 (0)