Skip to content

Commit

Permalink
feat: scaffold chain-registry files (backport #4413) (#4461)
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 13, 2025
1 parent f110f48 commit 849218c
Show file tree
Hide file tree
Showing 6 changed files with 454 additions and 0 deletions.
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

0 comments on commit 849218c

Please sign in to comment.