diff --git a/cmd/nodecmd/destroy.go b/cmd/nodecmd/destroy.go index 154db3a2f..5b3fcb1a5 100644 --- a/cmd/nodecmd/destroy.go +++ b/cmd/nodecmd/destroy.go @@ -5,6 +5,7 @@ package nodecmd import ( "errors" "fmt" + "github.com/ava-labs/avalanche-cli/pkg/models" "os" "strings" @@ -324,3 +325,36 @@ func getClusterMonitoringNode(clusterName string) (string, error) { } return clustersConfig.Clusters[clusterName].MonitoringInstance, nil } + +func checkCluster(clusterName string) error { + _, err := getClusterNodes(clusterName) + return err +} + +func checkClusterExists(clusterName string) (bool, error) { + clustersConfig := models.ClustersConfig{} + if app.ClustersConfigExists() { + var err error + clustersConfig, err = app.LoadClustersConfig() + if err != nil { + return false, err + } + } + _, ok := clustersConfig.Clusters[clusterName] + return ok, nil +} + +func getClusterNodes(clusterName string) ([]string, error) { + if exists, err := checkClusterExists(clusterName); err != nil || !exists { + return nil, fmt.Errorf("cluster %q not found", clusterName) + } + clustersConfig, err := app.LoadClustersConfig() + if err != nil { + return nil, err + } + clusterNodes := clustersConfig.Clusters[clusterName].Nodes + if len(clusterNodes) == 0 { + return nil, fmt.Errorf("no nodes found in cluster %s", clusterName) + } + return clusterNodes, nil +} diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 7e3ea6c8f..e7227e673 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -559,3 +559,11 @@ func notImplementedForLocal(what string) error { ux.Logger.PrintToUser("Unsupported cmd: %s is not supported by local clusters", logging.LightBlue.Wrap(what)) return nil } + +func getRPCEndpoint(endpoint string, blockchainID string) string { + return models.NewDevnetNetwork(endpoint, 0).BlockchainEndpoint(blockchainID) +} + +func getWSEndpoint(endpoint string, blockchainID string) string { + return models.NewDevnetNetwork(endpoint, 0).BlockchainWSEndpoint(blockchainID) +} diff --git a/go.mod b/go.mod index e1b111f53..ecd4a9c5e 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014184529-5bcdd0c507ec + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014200823-e2da066cad54 github.com/ava-labs/avalanchego v1.12.0-initial-poc.5 github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 github.com/ava-labs/coreth v0.13.8 diff --git a/go.sum b/go.sum index ed6cff884..7eda900c1 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014184529-5bcdd0c507ec h1:SPDvCcpYkG7kVDdogbW9tDYTYTIJkAeBzU4gAm3ZhXs= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014184529-5bcdd0c507ec/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014200823-e2da066cad54 h1:Hc06tSzeuQZTacGcrVLOnZjgKg1Cs655GT1Mmp9fCsU= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014200823-e2da066cad54/go.mod h1:ASWB/CKJm8wVZUBp3DY0AV8jTBLCs01kzQz9GGwtzi8= github.com/ava-labs/avalanchego v1.12.0-initial-poc.5 h1:gW4xAqZNvkA4gP8M9yDyd7YUzuwfQbbCR+hgd1ztOto= github.com/ava-labs/avalanchego v1.12.0-initial-poc.5/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 h1:M58jcqAG51RrKKVCfhAZpPqCFdkqRzahEgkFqQA5EME=