Skip to content

Commit

Permalink
feat: add support for arabica-11 in download-genesis command (celesti…
Browse files Browse the repository at this point in the history
…aorg#2978)

Closes celestiaorg#2976

## Testing

Updated the help and error messages to include arabica-11
```
$ ./build/celestia-appd download-genesis --help
Download genesis file from https://github.com/celestiaorg/networks.
The first argument should be a known chain-id. Ex. celestia, mocha-4, arabica-10, arabica-11

$ ./build/celestia-appd download-genesis arabaica-12
Error: unknown chain-id: arabaica-12. Must be: celestia, mocha-4, arabica-10, arabica-11
```

Downloading arabica-11 genesis works
```
$ ./build/celestia-appd download-genesis arabica-11
Downloading genesis file for arabica-11 to /Users/rootulp/.celestia-app/config/genesis.json
Downloaded genesis file for arabica-11 to /Users/rootulp/.celestia-app/config/genesis.json
SHA-256 hash verified for arabica-11
```

---------

Co-authored-by: Rootul P <[email protected]>
  • Loading branch information
subhajit20 and rootulp authored Jan 3, 2024
1 parent 3e494b1 commit 5f224ae
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/celestia-appd/cmd/download_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"os"
"strings"

"github.com/cosmos/cosmos-sdk/server"
"github.com/spf13/cobra"
Expand All @@ -19,20 +20,21 @@ var chainIDToSha256 = map[string]string{
"celestia": "9727aac9bbfb021ce7fc695a92f901986421283a891b89e0af97bc9fad187793",
"mocha-4": "0846b99099271b240b638a94e17a6301423b5e4047f6558df543d6e91db7e575",
"arabica-10": "fad0a187669f7a2c11bb07f9dc27140d66d2448b7193e186312713856f28e3e1",
"arabica-11": "77605cee57ce545b1be22402110d4baacac837bdc7fc3f5c74020abf9a08810f",
}

func downloadGenesisCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "download-genesis [chain-id]",
Short: "Download genesis file from https://github.com/celestiaorg/networks",
Long: "Download genesis file from https://github.com/celestiaorg/networks.\n" +
"The first argument should be a known chain-id. Ex. celestia, mocha-4, or arabica-10.\n" +
fmt.Sprintf("The first argument should be a known chain-id. Ex. %s\n", chainIDs()) +
"If no argument is provided, defaults to celestia.\n",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
chainID := getChainIDOrDefault(args)
if !isKnownChainID(chainID) {
return fmt.Errorf("unknown chain-id: %s. Must be: celestia, mocha-4, or arabica-10", chainID)
return fmt.Errorf("unknown chain-id: %s. Must be: %s", chainID, chainIDs())
}
outputFile := server.GetServerContextFromCmd(cmd).Config.GenesisFile()
fmt.Printf("Downloading genesis file for %s to %s\n", chainID, outputFile)
Expand Down Expand Up @@ -82,6 +84,10 @@ func isKnownChainID(chainID string) bool {
return contains(knownChainIDs, chainID)
}

func chainIDs() string {
return strings.Join(getKeys(chainIDToSha256), ", ")
}

// contains checks if a string is present in a slice.
func contains(slice []string, s string) bool {
for _, v := range slice {
Expand Down

0 comments on commit 5f224ae

Please sign in to comment.