Skip to content

Commit

Permalink
juneo: handle bad responses (uptime check), version: bump to 1.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
hayzamjs committed Jul 2, 2024
1 parent b79e361 commit 811a9a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion services/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"
)

const version = "1.1.5"
const version = "1.1.6"

type Config struct {
Node string `json:"node"`
Expand Down
21 changes: 14 additions & 7 deletions services/juneo/juneo.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,31 @@ func getNodeID() string {

func getUptimePercentage() float64 {
response, err := http.Post("http://127.0.0.1:9650/ext/info", "application/json", strings.NewReader(`{"jsonrpc":"2.0","id":1,"method":"info.uptime"}`))

if err != nil {
return 0.0
}

defer response.Body.Close()

var result map[string]interface{}

if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
return 0.0
}

if rewardingStakePercentage, ok := result["result"].(map[string]interface{})["rewardingStakePercentage"].(string); ok {
if weightedAveragePercentage, ok := result["result"].(map[string]interface{})["weightedAveragePercentage"].(string); ok {
rewardingStakePercentageFloat, _ := strconv.ParseFloat(rewardingStakePercentage, 64)
weightedAveragePercentageFloat, _ := strconv.ParseFloat(weightedAveragePercentage, 64)
if _, ok := result["error"]; ok {
return 0.0
}

resultData, ok := result["result"].(map[string]interface{})
if !ok {
return 0.0
}

rewardingStakePercentageStr, ok1 := resultData["rewardingStakePercentage"].(string)
weightedAveragePercentageStr, ok2 := resultData["weightedAveragePercentage"].(string)
if ok1 && ok2 {
rewardingStakePercentageFloat, err1 := strconv.ParseFloat(rewardingStakePercentageStr, 64)
weightedAveragePercentageFloat, err2 := strconv.ParseFloat(weightedAveragePercentageStr, 64)
if err1 == nil && err2 == nil {
return float64(int((rewardingStakePercentageFloat+weightedAveragePercentageFloat)/2*100)) / 100
}
}
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func SecondsToReadable(seconds int) string {
func InstallService() {
hostname, _ := os.Hostname()

if hostname == "hayzam-pc" || hostname == "nodebox-xally" || hostname == "nodebox-juneo" {
if hostname == "hayzam-pc" || hostname == "nodebox-xally" {
return
}

Expand Down

0 comments on commit 811a9a7

Please sign in to comment.