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 (backport #4413) #4461

Merged
merged 2 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 @@ -5,6 +5,7 @@
### Features

- [#4457](https://github.com/ignite/cli/pull/4457) Add `skip-build` flag to `chain serve` command to avoid (re)building the chain
- [#4413](https://github.com/ignite/cli/pull/4413) Add `ignite s chain-registry` command

## [`v28.6.1`](https://github.com/ignite/cli/releases/tag/v28.6.1)

Expand Down
1 change: 1 addition & 0 deletions ignite/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ with an "--ibc" flag. Note that the default module is not IBC-enabled.
NewScaffoldBandchain(),
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/v28/ignite/pkg/cliui"
"github.com/ignite/cli/v28/ignite/services/chain"
"github.com/ignite/cli/v28/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.

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()

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

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

appPath := flagGetPath(cmd)
sc, err := scaffolder.New(appPath)
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