Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: scaffold chain-registry files #4413

Merged
merged 20 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [#4436](https://github.com/ignite/cli/pull/4436) Return tx hash to the faucet API
- [#4437](https://github.com/ignite/cli/pull/4437) Remove module placeholders
- [#4289](https://github.com/ignite/cli/pull/4289), [#4423](https://github.com/ignite/cli/pull/4423), [#4432](https://github.com/ignite/cli/pull/4432) Cosmos SDK v0.52 support
- [#4413](https://github.com/ignite/cli/pull/4413) Add `ignite s chain-registry` command

### Changes

Expand Down
1 change: 1 addition & 0 deletions ignite/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ with an "--ibc" flag. Note that the default module is not IBC-enabled.
NewScaffoldPacket(),
NewScaffoldVue(),
NewScaffoldReact(),
NewScaffoldChainRegistry(),
)

return c
Expand Down
68 changes: 68 additions & 0 deletions ignite/cmd/scaffold_chain_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package ignitecmd

import (
"github.com/spf13/cobra"

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/services/chain"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
)

// NewScaffoldChainRegistry returns the command to scaffold the chain registry chain.json and assets.json files.
func NewScaffoldChainRegistry() *cobra.Command {
c := &cobra.Command{
Use: "chain-registry",
Short: "Configs for the chain registry",
Long: `Scaffold the chain registry chain.json and assets.json files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should certain fields should be configurable?

For instance:

c.Flags().String("status", "upcoming", "Chain status (mainnet, testnet, upcoming, etc.)")

and then consumed in scaffoldChainRegistryFiles

status, _ := cmd.Flags().GetString("status")

And passed down to AddChainRegistryFiles

if err = sc.AddChainRegistryFiles(c, cfg, status); err != nil {
    return err
}
``

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't super sure. As youd scaffold this when you need the frontend, and usually it is at devnet. Wanted to keep it KISS. But we can always add if you find it valuable.

The chain registry is a GitHub repo, hosted at https://github.com/cosmos/cosmos-registry, that
contains the chain.json and assets.json files of most of chains in the Cosmos ecosystem.
It is good practices, when creating a new chain, and about to launch a testnet or mainnet, to
publish the chain's metadata in the chain registry.

Read more about the chain.json at https://github.com/cosmos/chain-registry?tab=readme-ov-file#chainjson
Read more about the assets.json at https://github.com/cosmos/chain-registry?tab=readme-ov-file#assetlists`,
Args: cobra.NoArgs,
PreRunE: migrationPreRunHandler,
RunE: scaffoldChainRegistryFiles,
}

flagSetPath(c)
flagSetClearCache(c)

c.Flags().AddFlagSet(flagSetYes())

return c
}

func scaffoldChainRegistryFiles(cmd *cobra.Command, _ []string) error {
session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
defer session.End()

cfg, _, err := getChainConfig(cmd)
if err != nil {
return err
}

c, err := chain.NewWithHomeFlags(cmd)
if err != nil {
return err
}

appPath := flagGetPath(cmd)
sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path)
if err != nil {
return err
}

if err = sc.AddChainRegistryFiles(c, cfg); err != nil {
return err
}

// no need for post scaffolding, as we are just creating two files
// that are not part of the build process

session.Printf("🎉 chain-registry files successfully scaffolded\n")

return nil
}
20 changes: 20 additions & 0 deletions ignite/pkg/xgit/xgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,23 @@ func IsRepository(path string) (bool, error) {
}
return true, nil
}

// RepositoryURL returns the URL of the origin remote of a Git repository.
func RepositoryURL(path string) (string, error) {
repo, err := git.PlainOpenWithOptions(path, &defaultOpenOpts)
if err != nil {
return "", err
}

cfg, err := repo.Config()
if err != nil {
return "", err
}

origin, ok := cfg.Remotes["origin"]
if !ok {
return "", errors.Errorf("no origin remote found in %s", path)
}

return origin.URLs[0], nil
}
Loading
Loading