Skip to content

Commit d06912c

Browse files
committed
fix gettransaction when explorers return a bad status code.
1 parent b774a7c commit d06912c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

getblock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func getHash(height int64) (hash string, err error) {
110110
}
111111
defer w.Body.Close()
112112

113-
if w.StatusCode >= 404 {
113+
if w.StatusCode >= 400 {
114114
continue
115115
}
116116

gettransaction.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ func getTransaction(txid string) (tx TxResponse, err error) {
5656
}
5757
defer w.Body.Close()
5858

59+
if w.StatusCode >= 400 {
60+
data := make([]byte, 99)
61+
n, _ := w.Body.Read(data)
62+
message := string(data[0:n])
63+
if n >= 99 {
64+
message += "…"
65+
}
66+
err = fmt.Errorf("unexpected response: '%s'", message)
67+
continue
68+
}
69+
5970
errW = json.NewDecoder(w.Body).Decode(&tx)
6071
if errW != nil {
6172
err = errW

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func main() {
164164
p.Logf("failed to get tx %s: %s", txid, err.Error())
165165
return UTXOResponse{nil, nil}, 0, nil
166166
}
167+
167168
output := tx.Vout[vout]
168169
return UTXOResponse{&output.Value, &output.ScriptPubKey}, 0, nil
169170
},

0 commit comments

Comments
 (0)