Skip to content

Commit

Permalink
feat: cosmos endpoint getter (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchon authored Sep 4, 2024
1 parent c336621 commit b4e81f3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions playground/cosmosdaemon/cli_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit b4e81f3

Please sign in to comment.