Skip to content

Commit

Permalink
don't be so eager to crash on rpc errors
Browse files Browse the repository at this point in the history
  • Loading branch information
blockpane committed Oct 3, 2022
1 parent c72f04d commit becf339
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func main() {
for range tick.C {
votes, pct, hrs, dur, e := prevotes.GetPreVotes(os.Args[1], v)
if e != nil {
log.Fatal(e)
SummaryChan <- e.Error()
continue
}
if dur < 0 {
dur = 0
Expand Down
30 changes: 20 additions & 10 deletions prevotes/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@ func GetValNames(addr string) *ValNames {
for more {
resp, err := http.Get(httpAddr + "/validators?per_page=" + strconv.Itoa(perPage) + "&page=" + strconv.Itoa(page))
if err != nil {
log.Fatal(err)
log.Println(err)
continue
}
r, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log.Fatal(err)
log.Println(err)
continue
}
valResp := &rpcValidatorsResp{}
err = json.Unmarshal(r, valResp)
if err != nil {
log.Fatal(err)
log.Println(err)
continue
}

for _, val := range valResp.Result.Validators {
Expand All @@ -84,17 +87,20 @@ func GetValNames(addr string) *ValNames {
for more {
resp, err := http.Get(httpAddr + "/validators?per_page=" + strconv.Itoa(perPage) + "&page=" + strconv.Itoa(page))
if err != nil {
log.Fatal(err)
log.Println(err)
continue
}
r, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log.Fatal(err)
log.Println(err)
continue
}
valResp := &rpcValidatorsResp{}
err = json.Unmarshal(r, valResp)
if err != nil {
log.Fatal(err)
log.Println(err)
continue
}

for _, val := range valResp.Result.Validators {
Expand Down Expand Up @@ -124,23 +130,27 @@ func GetValNames(addr string) *ValNames {
}
q, e := valsQuery.Marshal()
if e != nil {
log.Fatal(e)
log.Println(e)
continue
}
valsResult, e := client.ABCIQuery(context.Background(), "/cosmos.staking.v1beta1.Query/Validators", q)
if e != nil {
log.Fatal(e)
log.Println(e)
continue
}
if len(valsResult.Response.Value) > 0 {
valsResp := staketypes.QueryValidatorsResponse{}
e = valsResp.Unmarshal(valsResult.Response.Value)
if e != nil {
log.Fatal(e)
log.Println(e)
continue
}
for _, val := range valsResp.Validators {
annoyed := make(map[string]interface{})
e = yaml.Unmarshal([]byte(val.String()), &annoyed)
if e != nil {
log.Fatal(e)
log.Println(e)
continue
}
i := v.getByKey(annoyed["consensus_pubkey"].(map[string]interface{})["key"].(string))
v.setIndex(i, strings.TrimSpace(val.Description.Moniker))
Expand Down

0 comments on commit becf339

Please sign in to comment.