|
| 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 | +} |
0 commit comments