diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index dbdcf535..b85c68c0 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -1,6 +1,9 @@ package consts -import "fmt" +import ( + "fmt" + "math/big" +) const binsDir = "/usr/local/bin" @@ -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) diff --git a/cmd/run/services.go b/cmd/run/services.go index 38edc533..9f82a4f3 100644 --- a/cmd/run/services.go +++ b/cmd/run/services.go @@ -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) diff --git a/cmd/run/services_status.go b/cmd/run/services_status.go index 80c022d0..777884aa 100644 --- a/cmd/run/services_status.go +++ b/cmd/run/services_status.go @@ -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", diff --git a/cmd/utils/fetch_accounts_data.go b/cmd/utils/fetch_accounts_data.go index 379d32ac..2b9e8b9e 100644 --- a/cmd/utils/fetch_accounts_data.go +++ b/cmd/utils/fetch_accounts_data.go @@ -1,8 +1,10 @@ package utils import ( + "encoding/json" "fmt" "github.com/dymensionxyz/roller/cmd/consts" + "math/big" "path/filepath" ) @@ -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 +}