Skip to content

Commit 849218c

Browse files
authored
feat: scaffold chain-registry files (backport #4413) (#4461)
1 parent f110f48 commit 849218c

File tree

6 files changed

+454
-0
lines changed

6 files changed

+454
-0
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features
66

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

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

ignite/cmd/scaffold.go

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ with an "--ibc" flag. Note that the default module is not IBC-enabled.
130130
NewScaffoldBandchain(),
131131
NewScaffoldVue(),
132132
NewScaffoldReact(),
133+
NewScaffoldChainRegistry(),
133134
)
134135

135136
return c

ignite/cmd/scaffold_chain_registry.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package ignitecmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/ignite/cli/v28/ignite/pkg/cliui"
7+
"github.com/ignite/cli/v28/ignite/services/chain"
8+
"github.com/ignite/cli/v28/ignite/services/scaffolder"
9+
)
10+
11+
// NewScaffoldChainRegistry returns the command to scaffold the chain registry chain.json and assets.json files.
12+
func NewScaffoldChainRegistry() *cobra.Command {
13+
c := &cobra.Command{
14+
Use: "chain-registry",
15+
Short: "Configs for the chain registry",
16+
Long: `Scaffold the chain registry chain.json and assets.json files.
17+
18+
The chain registry is a GitHub repo, hosted at https://github.com/cosmos/cosmos-registry, that
19+
contains the chain.json and assets.json files of most of chains in the Cosmos ecosystem.
20+
It is good practices, when creating a new chain, and about to launch a testnet or mainnet, to
21+
publish the chain's metadata in the chain registry.
22+
23+
Read more about the chain.json at https://github.com/cosmos/chain-registry?tab=readme-ov-file#chainjson
24+
Read more about the assets.json at https://github.com/cosmos/chain-registry?tab=readme-ov-file#assetlists`,
25+
Args: cobra.NoArgs,
26+
PreRunE: migrationPreRunHandler,
27+
RunE: scaffoldChainRegistryFiles,
28+
}
29+
30+
flagSetPath(c)
31+
flagSetClearCache(c)
32+
33+
c.Flags().AddFlagSet(flagSetYes())
34+
35+
return c
36+
}
37+
38+
func scaffoldChainRegistryFiles(cmd *cobra.Command, _ []string) error {
39+
session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
40+
defer session.End()
41+
42+
c, err := chain.NewWithHomeFlags(cmd)
43+
if err != nil {
44+
return err
45+
}
46+
47+
cfg, err := c.Config()
48+
if err != nil {
49+
return err
50+
}
51+
52+
appPath := flagGetPath(cmd)
53+
sc, err := scaffolder.New(appPath)
54+
if err != nil {
55+
return err
56+
}
57+
58+
if err = sc.AddChainRegistryFiles(c, cfg); err != nil {
59+
return err
60+
}
61+
62+
// no need for post scaffolding, as we are just creating two files
63+
// that are not part of the build process
64+
65+
session.Printf("🎉 chain-registry files successfully scaffolded\n")
66+
67+
return nil
68+
}

ignite/pkg/xgit/xgit.go

+20
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,23 @@ func IsRepository(path string) (bool, error) {
159159
}
160160
return true, nil
161161
}
162+
163+
// RepositoryURL returns the URL of the origin remote of a Git repository.
164+
func RepositoryURL(path string) (string, error) {
165+
repo, err := git.PlainOpenWithOptions(path, &defaultOpenOpts)
166+
if err != nil {
167+
return "", err
168+
}
169+
170+
cfg, err := repo.Config()
171+
if err != nil {
172+
return "", err
173+
}
174+
175+
origin, ok := cfg.Remotes["origin"]
176+
if !ok {
177+
return "", errors.Errorf("no origin remote found in %s", path)
178+
}
179+
180+
return origin.URLs[0], nil
181+
}

0 commit comments

Comments
 (0)