Prathamesh Musale
8e9f08b652
All checks were successful
Integration Tests / test-integration (push) Successful in 3m6s
E2E Tests / test-e2e (push) Successful in 4m21s
Lint / Run golangci-lint (push) Successful in 4m36s
Unit Tests / test-unit (push) Successful in 2m49s
SDK Tests / sdk_tests_nameservice_expiry (push) Successful in 9m3s
SDK Tests / sdk_tests (push) Successful in 9m25s
SDK Tests / sdk_tests_auctions (push) Successful in 15m30s
Part of https://www.notion.so/Port-laconicd-to-cosmos-sdk-v0-50-x-43b30ab4e33a49c5912ebb2871cb777c Reviewed-on: deep-stack/laconic2d#23 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
105 lines
2.9 KiB
Go
105 lines
2.9 KiB
Go
package gql
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
)
|
|
|
|
// NodeDataPath is the path to the laconic2d data folder.
|
|
var NodeDataPath = os.ExpandEnv("$HOME/.laconic2d/data")
|
|
|
|
func getStatusInfo(client client.Context) (*NodeInfo, *SyncInfo, *ValidatorInfo, error) {
|
|
nodeClient, err := client.GetNode()
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
nodeStatus, err := nodeClient.Status(context.Background())
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
|
|
return &NodeInfo{
|
|
ID: string(nodeStatus.NodeInfo.ID()),
|
|
Network: nodeStatus.NodeInfo.Network,
|
|
Moniker: nodeStatus.NodeInfo.Moniker,
|
|
}, &SyncInfo{
|
|
LatestBlockHash: nodeStatus.SyncInfo.LatestBlockHash.String(),
|
|
LatestBlockHeight: strconv.FormatInt(nodeStatus.SyncInfo.LatestBlockHeight, 10),
|
|
LatestBlockTime: nodeStatus.SyncInfo.LatestBlockTime.String(),
|
|
CatchingUp: nodeStatus.SyncInfo.CatchingUp,
|
|
}, &ValidatorInfo{
|
|
Address: nodeStatus.ValidatorInfo.Address.String(),
|
|
VotingPower: strconv.FormatInt(nodeStatus.ValidatorInfo.VotingPower, 10),
|
|
ProposerPriority: nil,
|
|
}, nil
|
|
}
|
|
|
|
func getNetInfo(client client.Context) (string, []*PeerInfo, error) {
|
|
// TODO: Implement
|
|
|
|
// nodeClient, err := client.GetNode()
|
|
// if err != nil {
|
|
// return "", nil, err
|
|
// }
|
|
// netInfo, err := nodeClient.NetInfo(context.Background())
|
|
// if err != nil {
|
|
// return "", nil, err
|
|
// }
|
|
|
|
// peersInfo := make([]*PeerInfo, netInfo.NPeers)
|
|
// // TODO: find a way to get the peer information from nodeClient
|
|
// for index, peer := range netInfo.Peers {
|
|
// peersInfo[index] = &PeerInfo{
|
|
// Node: &NodeInfo{
|
|
// ID: string(peer.NodeInfo.ID()),
|
|
// // Moniker: peer.Node.Moniker,
|
|
// // Network: peer.Node.Network,
|
|
// },
|
|
// // IsOutbound: peer.IsOutbound,
|
|
// // RemoteIP: peer.RemoteIP,
|
|
// }
|
|
// }
|
|
|
|
// return strconv.FormatInt(int64(netInfo.NPeers), 10), peersInfo, nil
|
|
|
|
return strconv.FormatInt(int64(0), 10), []*PeerInfo{}, nil
|
|
}
|
|
|
|
func getValidatorSet(client client.Context) ([]*ValidatorInfo, error) {
|
|
nodeClient, err := client.GetNode()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res, err := nodeClient.Validators(context.Background(), nil, nil, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
validatorSet := make([]*ValidatorInfo, len(res.Validators))
|
|
for index, validator := range res.Validators {
|
|
proposerPriority := strconv.FormatInt(validator.ProposerPriority, 10)
|
|
validatorSet[index] = &ValidatorInfo{
|
|
Address: validator.Address.String(),
|
|
VotingPower: strconv.FormatInt(validator.VotingPower, 10),
|
|
ProposerPriority: &proposerPriority,
|
|
}
|
|
}
|
|
|
|
return validatorSet, nil
|
|
}
|
|
|
|
// GetDiskUsage returns disk usage for the given path.
|
|
func GetDiskUsage(dirPath string) (string, error) {
|
|
out, err := exec.Command("du", "-sh", dirPath).Output() // #nosec G204
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return strings.Fields(string(out))[0], nil
|
|
}
|