Skip to content

Commit

Permalink
Added continous status fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jun 29, 2023
1 parent d025248 commit ab90223
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cmd/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package consts

import "fmt"
import (
"fmt"
"math/big"
)

const binsDir = "/usr/local/bin"

Expand Down Expand Up @@ -80,3 +83,6 @@ const DefaultRollappRPC = "http://localhost:26657"
const DefaultDALCRPC = "http://localhost:26659"
const CelestiaRestApiEndpoint = "https://api-arabica-8.consensus.celestia-arabica.com"
const DefaultCelestiaRPC = "consensus-full-arabica-8.celestia-arabica.com"

var OneSequencePrice = big.NewInt(1)
var OneDAWritePrice = big.NewInt(1)
2 changes: 1 addition & 1 deletion cmd/run/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func fetchServicesData(rollappConfig utils.RollappConfig, logger *log.Logger) ([
utils.GetSequencerData,
utils.GetHubRlyAccData,
utils.GetRolRlyAccData,
utils.GetCelLCAccData,
utils.GetCelLCAccDataFromLocalLC,
}
results := fetchAsync(fetchFuncs, rollappConfig)
data := processDataResults(results, len(fetchFuncs), logger)
Expand Down
12 changes: 10 additions & 2 deletions cmd/run/services_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,25 @@ func processDataResults(results chan fetchResult, size int, logger *log.Logger)
return data
}

func activeIfSufficientBalance(currentBalance, threshold *big.Int) string {
if currentBalance.Cmp(threshold) >= 0 {
return "Active"
} else {
return "Stopped"
}
}

func buildServiceData(data []*utils.AccountData, rollappConfig utils.RollappConfig) []ServiceData {
return []ServiceData{
{
Name: "Sequencer",
Balance: data[0].Balance.String() + consts.Denoms.Hub,
Status: "Active",
Status: activeIfSufficientBalance(data[0].Balance, consts.OneSequencePrice),
},
{
Name: "DA Light Client",
Balance: data[3].Balance.String() + consts.Denoms.Celestia,
Status: "Active",
Status: activeIfSufficientBalance(data[3].Balance, consts.OneDAWritePrice),
},
{
Name: "Relayer",
Expand Down
30 changes: 30 additions & 0 deletions cmd/utils/fetch_accounts_data.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package utils

import (
"encoding/json"
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"math/big"
"path/filepath"
)

Expand Down Expand Up @@ -88,3 +90,31 @@ func GetCelLCAccData(rollappConfig RollappConfig) (*AccountData, error) {
Balance: balance,
}, nil
}

func GetCelLCAccDataFromLocalLC(rollappConfig RollappConfig) (*AccountData, error) {
celAddress, err := GetCelestiaAddress(rollappConfig.Home)
if err != nil {
return nil, err
}
var restQueryUrl = fmt.Sprintf(
"%s/balance",
consts.DefaultDALCRPC,
)
balancesJson, err := RestQueryJson(restQueryUrl)
if err != nil {
return nil, err
}
var balanceResp Balance
err = json.Unmarshal(balancesJson.Bytes(), &balanceResp)
if err != nil {
return nil, err
}
balanceInt, ok := new(big.Int).SetString(balanceResp.Amount, 10)
if !ok {
return nil, fmt.Errorf("failed to parse balance")
}
return &AccountData{
Address: celAddress,
Balance: balanceInt,
}, nil
}

0 comments on commit ab90223

Please sign in to comment.