From b4e81f3ebb93c7c7169702c3357227b06d06fa32 Mon Sep 17 00:00:00 2001 From: Guillermo Paoletti Date: Wed, 4 Sep 2024 19:41:48 +0200 Subject: [PATCH] feat: cosmos endpoint getter (#49) --- playground/cosmosdaemon/cli_helpers.go | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/playground/cosmosdaemon/cli_helpers.go b/playground/cosmosdaemon/cli_helpers.go index 5f83906..b15c985 100644 --- a/playground/cosmosdaemon/cli_helpers.go +++ b/playground/cosmosdaemon/cli_helpers.go @@ -177,3 +177,31 @@ func GetWeb3Endpoint(queries *database.Queries, cmd *cobra.Command) (string, err } return endpoint, nil } + +func GetCosmosEndpoint(queries *database.Queries, cmd *cobra.Command) (string, error) { + endpoint := "" + mainnet, _ := cmd.Flags().GetBool("mainnet") + if mainnet { + return "https://proxy.evmos.org/cosmos", nil + } + + url, _ := cmd.Flags().GetString("url") + if url != "" { + endpoint = url + } else { + nodeID, err := cmd.Flags().GetString("node") + if err != nil { + return "", fmt.Errorf("node not set") + } + validatorID, err := strconv.ParseInt(nodeID, 10, 64) + if err != nil { + return "", err + } + ports, err := queries.GetNodePorts(context.Background(), validatorID) + if err != nil { + return "", err + } + endpoint = fmt.Sprintf("http://localhost:%d", ports.P1317) + } + return endpoint, nil +}