Skip to content

Commit

Permalink
feat: scaffold chain-registry files (#4413)
Browse files Browse the repository at this point in the history
* feat: scaffold chain-registry files

* cl

* cl

* updates

* updates

* typo

* renaming

* finalize chain-registry

* updates

* lint

* lint

* typos
  • Loading branch information
julienrbrt authored Jan 13, 2025
1 parent 65f991d commit ed3d0b3
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 @@ -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.
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

0 comments on commit ed3d0b3

Please sign in to comment.