Skip to content

Commit

Permalink
feat: scaffold chain-registry files
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Nov 19, 2024
1 parent 0ff34e9 commit 8673fcb
Show file tree
Hide file tree
Showing 3 changed files with 351 additions and 0 deletions.
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
81 changes: 81 additions & 0 deletions ignite/cmd/scaffold_chain_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package ignitecmd

import (
"github.com/spf13/cobra"

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"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.MinimumNArgs(1),
PreRunE: migrationPreRunHandler,
RunE: scaffoldChainRegistryFiles,
}

flagSetPath(c)
flagSetClearCache(c)

c.Flags().AddFlagSet(flagSetYes())

return c
}

func scaffoldChainRegistryFiles(cmd *cobra.Command, args []string) error {

Check failure on line 37 in ignite/cmd/scaffold_chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
var appPath = flagGetPath(cmd)

session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
defer session.End()

cfg, _, err := getChainConfig(cmd)
if err != nil {
return err
}

cacheStorage, err := newCache(cmd)
if err != nil {
return err
}

sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path)
if err != nil {
return err
}

err = sc.CreateChainRegistryFiles()
if err != nil {
return err
}

sm, err := sc.ApplyModifications()
if err != nil {
return err
}

if err := sc.PostScaffold(cmd.Context(), cacheStorage, false); err != nil {
return err
}

modificationsStr, err := sm.String()
if err != nil {
return err
}

session.Println(modificationsStr)
session.Printf("\n🎉 Chain Registry files (assets.json and chain.json) succesfully scaffolded.\n")

Check failure on line 78 in ignite/cmd/scaffold_chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

`succesfully` is a misspelling of `successfully` (misspell)

return nil
}
269 changes: 269 additions & 0 deletions ignite/services/scaffolder/chain_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
package scaffolder

// https://raw.githubusercontent.com/cosmos/chain-registry/master/chain.schema.json
// https://github.com/cosmos/chain-registry?tab=readme-ov-file#sample
type chainJSON struct {

Check failure on line 5 in ignite/services/scaffolder/chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

type `chainJSON` is unused (unused)
Schema string `json:"$schema"`
ChainName string `json:"chain_name"`
ChainType string `json:"chain_type"`
ChainID string `json:"chain_id"`
Website string `json:"website"`
PrettyName string `json:"pretty_name"`
Status string `json:"status"`
NetworkType string `json:"network_type"`
Bech32Prefix string `json:"bech32_prefix"`
DaemonName string `json:"daemon_name"`
NodeHome string `json:"node_home"`
KeyAlgos []string `json:"key_algos"`
Slip44 int `json:"slip44"`
Fees struct {
FeeTokens []struct {
Denom string `json:"denom"`
FixedMinGasPrice float64 `json:"fixed_min_gas_price"`
LowGasPrice float64 `json:"low_gas_price"`
AverageGasPrice float64 `json:"average_gas_price"`
HighGasPrice float64 `json:"high_gas_price"`
} `json:"fee_tokens"`
} `json:"fees"`
Staking struct {
StakingTokens []struct {
Denom string `json:"denom"`
} `json:"staking_tokens"`
} `json:"staking"`
Codebase struct {
GitRepo string `json:"git_repo"`
RecommendedVersion string `json:"recommended_version"`
CompatibleVersions []string `json:"compatible_versions"`
Consensus struct {
Type string `json:"type"`
Version string `json:"version"`
} `json:"consensus"`
Binaries struct {
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
} `json:"binaries"`
Genesis struct {
GenesisURL string `json:"genesis_url"`
} `json:"genesis"`
Versions []struct {
Name string `json:"name"`
Tag string `json:"tag"`
RecommendedVersion string `json:"recommended_version"`
CompatibleVersions []string `json:"compatible_versions"`
Consensus struct {
Type string `json:"type"`
Version string `json:"version"`
} `json:"consensus"`
Height int `json:"height"`
Binaries struct {
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
WindowsAmd64 string `json:"windows/amd64"`
} `json:"binaries,omitempty"`
NextVersionName string `json:"next_version_name"`
Sdk struct {
Type string `json:"type"`
Version string `json:"version"`
Tag string `json:"tag"`
} `json:"sdk"`
Ibc struct {
Type string `json:"type"`
Version string `json:"version"`
} `json:"ibc"`
Proposal int `json:"proposal,omitempty"`
Binaries0 struct {

Check failure on line 78 in ignite/services/scaffolder/chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

structtag: struct field Binaries0 repeats json tag "binaries" also at chain_registry.go:60 (govet)
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
WindowsAmd64 string `json:"windows/amd64"`
WindowsArm64 string `json:"windows/arm64"`
} `json:"binaries,omitempty"`
Binaries1 struct {

Check failure on line 86 in ignite/services/scaffolder/chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

structtag: struct field Binaries1 repeats json tag "binaries" also at chain_registry.go:60 (govet)
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
WindowsAmd64 string `json:"windows/amd64"`
WindowsArm64 string `json:"windows/arm64"`
} `json:"binaries,omitempty"`
Binaries2 struct {

Check failure on line 94 in ignite/services/scaffolder/chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

structtag: struct field Binaries2 repeats json tag "binaries" also at chain_registry.go:60 (govet)
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
WindowsAmd64 string `json:"windows/amd64"`
WindowsArm64 string `json:"windows/arm64"`
} `json:"binaries,omitempty"`
Binaries3 struct {

Check failure on line 102 in ignite/services/scaffolder/chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

structtag: struct field Binaries3 repeats json tag "binaries" also at chain_registry.go:60 (govet)
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
WindowsAmd64 string `json:"windows/amd64"`
WindowsArm64 string `json:"windows/arm64"`
} `json:"binaries,omitempty"`
Binaries4 struct {

Check failure on line 110 in ignite/services/scaffolder/chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

structtag: struct field Binaries4 repeats json tag "binaries" also at chain_registry.go:60 (govet)
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
WindowsAmd64 string `json:"windows/amd64"`
WindowsArm64 string `json:"windows/arm64"`
} `json:"binaries,omitempty"`
Binaries5 struct {

Check failure on line 118 in ignite/services/scaffolder/chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

structtag: struct field Binaries5 repeats json tag "binaries" also at chain_registry.go:60 (govet)
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
WindowsAmd64 string `json:"windows/amd64"`
WindowsArm64 string `json:"windows/arm64"`
} `json:"binaries,omitempty"`
Binaries6 struct {
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
WindowsAmd64 string `json:"windows/amd64"`
WindowsArm64 string `json:"windows/arm64"`
} `json:"binaries,omitempty"`
Binaries7 struct {
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
WindowsAmd64 string `json:"windows/amd64"`
WindowsArm64 string `json:"windows/arm64"`
} `json:"binaries,omitempty"`
Cosmwasm struct {
Version string `json:"version"`
Repo string `json:"repo"`
Tag string `json:"tag"`
} `json:"cosmwasm,omitempty"`
Binaries8 struct {
LinuxAmd64 string `json:"linux/amd64"`
LinuxArm64 string `json:"linux/arm64"`
DarwinAmd64 string `json:"darwin/amd64"`
DarwinArm64 string `json:"darwin/arm64"`
} `json:"binaries,omitempty"`
} `json:"versions"`
Sdk struct {
Type string `json:"type"`
Version string `json:"version"`
Tag string `json:"tag"`
} `json:"sdk"`
Ibc struct {
Type string `json:"type"`
Version string `json:"version"`
} `json:"ibc"`
Cosmwasm struct {
Version string `json:"version"`
Repo string `json:"repo"`
Tag string `json:"tag"`
} `json:"cosmwasm"`
} `json:"codebase"`
LogoURIs struct {
Png string `json:"png"`
Svg string `json:"svg"`
} `json:"logo_URIs"`
Description string `json:"description"`
Peers struct {
Seeds []struct {
ID string `json:"id"`
Address string `json:"address"`
Provider string `json:"provider"`
} `json:"seeds"`
PersistentPeers []struct {
ID string `json:"id"`
Address string `json:"address"`
Provider string `json:"provider,omitempty"`
} `json:"persistent_peers"`
} `json:"peers"`
Apis struct {
RPC []struct {
Address string `json:"address"`
Provider string `json:"provider"`
} `json:"rpc"`
Rest []struct {
Address string `json:"address"`
Provider string `json:"provider"`
} `json:"rest"`
Grpc []struct {
Address string `json:"address"`
Provider string `json:"provider"`
} `json:"grpc"`
} `json:"apis"`
Explorers []struct {
Kind string `json:"kind"`
URL string `json:"url"`
TxPage string `json:"tx_page,omitempty"`
AccountPage string `json:"account_page,omitempty"`
ValidatorPage string `json:"validator_page,omitempty"`
ProposalPage string `json:"proposal_page,omitempty"`
BlockPage string `json:"block_page,omitempty"`
} `json:"explorers"`
Images []struct {
Png string `json:"png"`
Svg string `json:"svg"`
Theme struct {
PrimaryColorHex string `json:"primary_color_hex"`
} `json:"theme"`
} `json:"images"`
}

// https://raw.githubusercontent.com/cosmos/chain-registry/master/assetlist.schema.json
// https://github.com/cosmos/chain-registry?tab=readme-ov-file#assetlists
type assetlistJson struct {

Check failure on line 220 in ignite/services/scaffolder/chain_registry.go

View workflow job for this annotation

GitHub Actions / Lint Go code

var-naming: type assetlistJson should be assetlistJSON (revive)
Schema string `json:"$schema"`
ChainName string `json:"chain_name"`
Assets []struct {
Description string `json:"description"`
ExtendedDescription string `json:"extended_description,omitempty"`
DenomUnits []struct {
Denom string `json:"denom"`
Exponent int `json:"exponent"`
} `json:"denom_units"`
Base string `json:"base"`
Name string `json:"name"`
Display string `json:"display"`
Symbol string `json:"symbol"`
LogoURIs struct {
Png string `json:"png"`
Svg string `json:"svg"`
} `json:"logo_URIs"`
CoingeckoID string `json:"coingecko_id,omitempty"`
Images []struct {
Png string `json:"png"`
Svg string `json:"svg"`
Theme struct {
PrimaryColorHex string `json:"primary_color_hex"`
} `json:"theme"`
} `json:"images"`
Socials struct {
Website string `json:"website"`
Twitter string `json:"twitter"`
} `json:"socials,omitempty"`
TypeAsset string `json:"type_asset"`
Traces []struct {
Type string `json:"type"`
Counterparty struct {
ChainName string `json:"chain_name"`
BaseDenom string `json:"base_denom"`
ChannelID string `json:"channel_id"`
} `json:"counterparty"`
Chain struct {
ChannelID string `json:"channel_id"`
Path string `json:"path"`
} `json:"chain"`
} `json:"traces,omitempty"`
} `json:"assets"`
}

// CreateChainRegistryFiles creates a the chain registry files in the scaffolded chains.
func (s Scaffolder) CreateChainRegistryFiles() error {
return nil
}

0 comments on commit 8673fcb

Please sign in to comment.