From 874f6f2df60bbcd0711b0fcfb40350e90138e6d5 Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Tue, 6 Aug 2024 07:12:23 -0500 Subject: [PATCH 1/9] node home, general parser + test, defaults --- spawn/cfg.go | 18 ++++++++++++++++ spawn/general_parser.go | 48 +++++++++++++++++++++++++++++++++++++++++ spawn/metadata.go | 30 ++++++++++++++++++++------ spawn/metadata_test.go | 19 ++++++++++++++++ 4 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 spawn/general_parser.go create mode 100644 spawn/metadata_test.go diff --git a/spawn/cfg.go b/spawn/cfg.go index f0b14974..2065d216 100644 --- a/spawn/cfg.go +++ b/spawn/cfg.go @@ -62,6 +62,12 @@ type NewChainConfig struct { isUsingICS bool } +// NodeHome returns the full path to the node home directory +// ex: $HOME/.simapp +func (cfg NewChainConfig) NodeHome() string { + return path.Join("$HOME", cfg.HomeDir) +} + func (cfg NewChainConfig) ValidateAndRun(doAnnounce bool) error { if err := cfg.Validate(); err != nil { return fmt.Errorf("error validating config: %w", err) @@ -393,6 +399,18 @@ func GetFileContent(logger *slog.Logger, newFilePath string, fs embed.FS, relPat return fc, nil } +func (cfg *NewChainConfig) IsCosmWasmEnabled() bool { + isDisabled := false + for _, d := range cfg.DisabledModules { + if AliasName(d) == CosmWasm { + isDisabled = true + break + } + } + + return !isDisabled +} + // debugErrorFile saves the errored file to a debug directory for easier debugging. // Returning the path to the file. func debugErrorFile(logger *slog.Logger, newDirname string) string { diff --git a/spawn/general_parser.go b/spawn/general_parser.go new file mode 100644 index 00000000..bd1e76ed --- /dev/null +++ b/spawn/general_parser.go @@ -0,0 +1,48 @@ +package spawn + +import ( + "fmt" + "os" + "path" + + modfile "golang.org/x/mod/modfile" +) + +// ParseVersionFromGoMod parses out the versions for a given goPath +// Ex: ParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", false) returns v0.50.X +// Ex: ParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", true) returns 0.50.X +func ParseVersionFromGoMod(goPath string, removePrefixedV bool) (string, error) { + // open ../simapp/go.mod + goModPath := path.Join("..", "simapp", "go.mod") + + c, err := os.ReadFile(goModPath) + if err != nil { + return "", fmt.Errorf("error reading go.mod file: %w", err) + } + + f, err := modfile.Parse(goModPath, c, nil) + if err != nil { + return "", fmt.Errorf("error parsing go.mod file: %w", err) + } + + for _, r := range f.Require { + if r.Mod.Path == goPath { + v := r.Mod.Version + if removePrefixedV && len(v) > 0 && v[0] == 'v' { + v = v[1:] + } + return v, nil + } + } + + // no error if not found, we just return nothing + return "", fmt.Errorf("module %s not found in go.mod", goPath) +} + +func MustParseVersionFromGoMod(goPath string, removePrefixedV bool) string { + v, err := ParseVersionFromGoMod(goPath, removePrefixedV) + if err != nil { + panic(err) + } + return v +} diff --git a/spawn/metadata.go b/spawn/metadata.go index e8b7836f..d10abb01 100644 --- a/spawn/metadata.go +++ b/spawn/metadata.go @@ -7,6 +7,24 @@ import ( "time" ) +const ( + DefaultWebsite = "https://example.com" + DefaultLogo = "https://www.shutterstock.com/image-illustration/colourful-business-logo-company-name-260nw-1779060299.jpg" + DefaultDescription = "A short description of your project" + DefaultChainID = "newchain-1" + DefaultNetworkType = "testnet" // or mainnet + DefaultSlip44CoinType = 118 + DefaultChainRegistrySchema = "https://raw.githubusercontent.com/cosmos/chain-registry/master/chain.schema.json" +) + +var ( + DefaultSDKVersion = MustParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", true) + DefaultTendermintVersion = MustParseVersionFromGoMod("github.com/cometbft/cometbft", true) + DefaultIBCGoVersion = MustParseVersionFromGoMod("github.com/cosmos/ibc-go/v8", true) + // TODO: sometimes this will be non existent + DefaultCosmWasmVersion = MustParseVersionFromGoMod("github.com/CosmWasm/wasmd", true) +) + func (cfg *NewChainConfig) MetadataFile() MetadataFile { now := time.Now().UTC() now = now.Round(time.Minute) @@ -23,10 +41,10 @@ func (cfg *NewChainConfig) MetadataFile() MetadataFile { Project: ProjectMeta{ Github: cfg.GithubPath(), TargetLaunchDate: now, - Logo: "https://example.com/logo.png", - Website: "https://example.com", - Description: "A short description of your project", - ShortDescription: "A short description of your project", + Logo: DefaultLogo, + Website: DefaultWebsite, + Description: DefaultDescription, + ShortDescription: DefaultDescription, Whitepaper: "https://example.com/whitepaper.pdf", Contact: ContactMeta{ Email: "", @@ -43,8 +61,8 @@ func (cfg *NewChainConfig) MetadataFile() MetadataFile { mf.ICS = ICSMeta{ SpawnTime: now, Title: cfg.BinDaemon, - Summary: ".md description of your chain and all other relevant information", - ChainID: "newchain-1", + Summary: DefaultDescription + " ( in .md format)", + ChainID: DefaultChainID, InitialHeight: ICSClientTypes{ RevisionHeight: 0, RevisionNumber: 1, diff --git a/spawn/metadata_test.go b/spawn/metadata_test.go new file mode 100644 index 00000000..f46fd369 --- /dev/null +++ b/spawn/metadata_test.go @@ -0,0 +1,19 @@ +package spawn + +import ( + "testing" + + "github.com/stretchr/testify/require" + "golang.org/x/mod/semver" +) + +func TestLoadingValues(t *testing.T) { + // fmt.Println(DefaultSDKVersion) + // fmt.Println(DefaultCosmWasmVersion) + // fmt.Println(DefaultTendermintVersion) + // fmt.Println(DefaultIBCGoVersion) + require.True(t, semver.Compare(DefaultSDKVersion, "0.50.0") >= 0) + require.True(t, semver.Compare(DefaultCosmWasmVersion, "0.50.0") >= 0) + require.True(t, semver.Compare(DefaultTendermintVersion, "0.38.0") >= 0) + require.True(t, semver.Compare(DefaultIBCGoVersion, "8.2.0") >= 0) +} From 4a1afb4b4ff435bbb430231b51433bfc33be442d Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Tue, 6 Aug 2024 07:28:30 -0500 Subject: [PATCH 2/9] chain registry basic --- spawn/cfg.go | 17 +++-- spawn/cfg_registry_schema.go | 109 ++++++++++++++++++++++++++ spawn/cfg_test.go | 32 +++++--- spawn/proto_parser.go | 56 ++++++++++++++ spawn/proto_types.go | 58 -------------- spawn/types/chain_registry.go | 139 ++++++++++++++++++++++++++++++++++ spawn/{ => types}/errors.go | 2 +- 7 files changed, 334 insertions(+), 79 deletions(-) create mode 100644 spawn/cfg_registry_schema.go delete mode 100644 spawn/proto_types.go create mode 100644 spawn/types/chain_registry.go rename spawn/{ => types}/errors.go (98%) diff --git a/spawn/cfg.go b/spawn/cfg.go index 2065d216..517aa9ba 100644 --- a/spawn/cfg.go +++ b/spawn/cfg.go @@ -12,6 +12,7 @@ import ( "time" "github.com/rollchains/spawn/simapp" + "github.com/rollchains/spawn/spawn/types" localictypes "github.com/strangelove-ventures/interchaintest/local-interchain/interchain/types" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v8/ibc" @@ -118,39 +119,39 @@ func (cfg *NewChainConfig) IsFeatureDisabled(featName string) bool { func (cfg *NewChainConfig) Validate() error { if cfg.ProjectName == "" { - return ErrCfgEmptyProject + return types.ErrCfgEmptyProject } if strings.ContainsAny(cfg.ProjectName, `~!@#$%^&*()_+{}|:"<>?/.,;'[]\=-`) { - return ErrCfgProjSpecialChars + return types.ErrCfgProjSpecialChars } if cfg.GithubOrg == "" { - return ErrCfgEmptyOrg + return types.ErrCfgEmptyOrg } minDenomLen := 3 if len(cfg.Denom) < minDenomLen { - return ErrExpectedRange(ErrCfgDenomTooShort, minDenomLen, len(cfg.Denom)) + return types.ErrExpectedRange(types.ErrCfgDenomTooShort, minDenomLen, len(cfg.Denom)) } minBinLen := 2 if len(cfg.BinDaemon) < minBinLen { - return ErrExpectedRange(ErrCfgBinTooShort, minBinLen, len(cfg.BinDaemon)) + return types.ErrExpectedRange(types.ErrCfgBinTooShort, minBinLen, len(cfg.BinDaemon)) } if cfg.Bech32Prefix == "" { - return ErrCfgEmptyBech32 + return types.ErrCfgEmptyBech32 } cfg.Bech32Prefix = strings.ToLower(cfg.Bech32Prefix) if !isAlphaFn(cfg.Bech32Prefix) { - return ErrCfgBech32Alpha + return types.ErrCfgBech32Alpha } minHomeLen := 2 if len(cfg.HomeDir) < minHomeLen { - return ErrExpectedRange(ErrCfgHomeDirTooShort, minHomeLen, len(cfg.HomeDir)) + return types.ErrExpectedRange(types.ErrCfgHomeDirTooShort, minHomeLen, len(cfg.HomeDir)) } if cfg.Logger == nil { diff --git a/spawn/cfg_registry_schema.go b/spawn/cfg_registry_schema.go new file mode 100644 index 00000000..9c6bfc74 --- /dev/null +++ b/spawn/cfg_registry_schema.go @@ -0,0 +1,109 @@ +package spawn + +import ( + "fmt" + + "golang.org/x/text/cases" + "golang.org/x/text/language" + + "github.com/rollchains/spawn/spawn/types" +) + +var caser = cases.Title(language.English) + +func (cfg NewChainConfig) ChainRegistryFile() types.ChainRegistryFormat { + return types.ChainRegistryFormat{ + Schema: DefaultChainRegistrySchema, + ChainName: cfg.ProjectName, + Status: "live", + Website: DefaultWebsite, + NetworkType: DefaultNetworkType, + PrettyName: caser.String(cfg.ProjectName), + ChainID: DefaultChainID, + Bech32Prefix: cfg.Bech32Prefix, + DaemonName: cfg.BinDaemon, + NodeHome: cfg.NodeHome(), + KeyAlgos: []string{"secp256k1"}, + Slip44: DefaultSlip44CoinType, + Fees: types.Fees{ + FeeTokens: []types.FeeTokens{ + { + Denom: cfg.Denom, + FixedMinGasPrice: 0, + LowGasPrice: 0, + AverageGasPrice: 0.025, + HighGasPrice: 0.04, + }, + }, + }, + Codebase: types.Codebase{ + // TODO: versions should be fetched from the repo go.mod + GitRepo: "https://" + cfg.GithubPath(), + RecommendedVersion: "v1.0.0", + CompatibleVersions: []string{"v0.9.0"}, + CosmosSdkVersion: DefaultSDKVersion, + Consensus: types.Consensus{ + Type: "tendermint", // TODO: gordian in the future on gen + Version: DefaultTendermintVersion, + }, + CosmwasmVersion: DefaultCosmWasmVersion, + CosmwasmEnabled: cfg.IsCosmWasmEnabled(), + IbcGoVersion: DefaultIBCGoVersion, + IcsEnabled: []string{"ics20-1"}, + Genesis: types.Genesis{ + Name: "v1", + GenesisURL: fmt.Sprintf("https://%s/%s", cfg.GithubPath(), "networks/raw/main/genesis.json"), + }, + Versions: []types.Versions{ + { + Name: "v1.0.0", + Tag: "v1.0.0", + Height: 0, + NextVersionName: "v2", + }, + }, + }, + Staking: types.Staking{ + StakingTokens: []types.StakingTokens{ + { + Denom: cfg.Denom, + }, + }, + LockDuration: types.LockDuration{ + Time: "1814400s", // 21 days + }, + }, + Images: []types.Images{ + { + Png: DefaultLogo, + Theme: types.Theme{ + PrimaryColorHex: "#FF2D00", + }, + }, + }, + Peers: types.Peers{}, + Apis: types.Apis{ + RPC: []types.RPC{ + { + Address: "tcp://127.0.0.1:26657", + Provider: "localhost", + }, + }, + Rest: []types.Rest{ + { + Address: "tcp://127.0.0.1:1317", + Provider: "localhost", + }, + }, + }, + Explorers: []types.Explorers{ + { + Kind: "cosmos", + URL: "https://example.com", + TxPage: "https://example.com/tx", + AccountPage: "https://example.com/account", + }, + }, + Keywords: []string{"cosmos", "spawn"}, + } +} diff --git a/spawn/cfg_test.go b/spawn/cfg_test.go index 8a38c5f5..fcacc059 100644 --- a/spawn/cfg_test.go +++ b/spawn/cfg_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/rollchains/spawn/spawn" + "github.com/rollchains/spawn/spawn/types" "github.com/stretchr/testify/require" ) @@ -208,22 +209,22 @@ func goodCfg() spawn.NewChainConfig { func TestBadConfigInputs(t *testing.T) { chainCases := []cfgCase{ NewCfgCase("valid config", goodCfg(), nil), - NewCfgCase("no github org", goodCfg().WithOrg(""), spawn.ErrCfgEmptyOrg), - NewCfgCase("no project name", goodCfg().WithProjectName(""), spawn.ErrCfgEmptyProject), - NewCfgCase("project special chars -", goodCfg().WithProjectName("my-project"), spawn.ErrCfgProjSpecialChars), - NewCfgCase("project special chars /", goodCfg().WithProjectName("my/project"), spawn.ErrCfgProjSpecialChars), - NewCfgCase("binary name to short len 1", goodCfg().WithBinDaemon("a"), spawn.ErrCfgBinTooShort), + NewCfgCase("no github org", goodCfg().WithOrg(""), types.ErrCfgEmptyOrg), + NewCfgCase("no project name", goodCfg().WithProjectName(""), types.ErrCfgEmptyProject), + NewCfgCase("project special chars -", goodCfg().WithProjectName("my-project"), types.ErrCfgProjSpecialChars), + NewCfgCase("project special chars /", goodCfg().WithProjectName("my/project"), types.ErrCfgProjSpecialChars), + NewCfgCase("binary name to short len 1", goodCfg().WithBinDaemon("a"), types.ErrCfgBinTooShort), NewCfgCase("success: binary name len 2", goodCfg().WithBinDaemon("ad"), nil), - NewCfgCase("token denom too short len 1", goodCfg().WithDenom("a"), spawn.ErrCfgDenomTooShort), - NewCfgCase("token denom too short len 2", goodCfg().WithDenom("ab"), spawn.ErrCfgDenomTooShort), + NewCfgCase("token denom too short len 1", goodCfg().WithDenom("a"), types.ErrCfgDenomTooShort), + NewCfgCase("token denom too short len 2", goodCfg().WithDenom("ab"), types.ErrCfgDenomTooShort), NewCfgCase("success: token denom special chars", goodCfg().WithDenom("my-cool/token"), nil), NewCfgCase("success: token denom 3", goodCfg().WithDenom("abc"), nil), - NewCfgCase("home dir too short", goodCfg().WithHomeDir("."), spawn.ErrCfgHomeDirTooShort), + NewCfgCase("home dir too short", goodCfg().WithHomeDir("."), types.ErrCfgHomeDirTooShort), NewCfgCase("success: home dir valid", goodCfg().WithHomeDir(".a"), nil), - NewCfgCase("bech32 prefix to short", goodCfg().WithBech32Prefix(""), spawn.ErrCfgEmptyBech32), - NewCfgCase("bech32 not alpha", goodCfg().WithBech32Prefix("c919"), spawn.ErrCfgBech32Alpha), - NewCfgCase("bech32 not alpha", goodCfg().WithBech32Prefix("1"), spawn.ErrCfgBech32Alpha), - NewCfgCase("bech32 not alpha", goodCfg().WithBech32Prefix("---"), spawn.ErrCfgBech32Alpha), + NewCfgCase("bech32 prefix to short", goodCfg().WithBech32Prefix(""), types.ErrCfgEmptyBech32), + NewCfgCase("bech32 not alpha", goodCfg().WithBech32Prefix("c919"), types.ErrCfgBech32Alpha), + NewCfgCase("bech32 not alpha", goodCfg().WithBech32Prefix("1"), types.ErrCfgBech32Alpha), + NewCfgCase("bech32 not alpha", goodCfg().WithBech32Prefix("---"), types.ErrCfgBech32Alpha), NewCfgCase("success: bech32 prefix", goodCfg().WithBech32Prefix("c"), nil), } @@ -242,3 +243,10 @@ func TestBadConfigInputs(t *testing.T) { }) } } + +func TestChainRegistry(t *testing.T) { + cfg := goodCfg() + cr := cfg.ChainRegistryFile() + require.Equal(t, cfg.ProjectName, cr.ChainName) + // cr.SaveJSON("test.json") +} diff --git a/spawn/proto_parser.go b/spawn/proto_parser.go index 547d4d6d..889025fe 100644 --- a/spawn/proto_parser.go +++ b/spawn/proto_parser.go @@ -9,6 +9,62 @@ import ( "strings" ) +/// --- types --- + +// FileType tells the application which type of proto file is it so we can sort Txs from Queries +type FileType string + +const ( + Tx FileType = "tx" + Query FileType = "query" + None FileType = "none" +) + +// get the str of FileType +func (ft FileType) String() string { + return string(ft) +} + +// ModuleMapping a map of the module name to a list of ProtoRPCs +type ModuleMapping map[string][]*ProtoRPC + +func (mm ModuleMapping) Print(logger *slog.Logger) { + for name, v := range mm { + v := v + name := name + + for _, rpc := range v { + logger.Debug("module", "module", name, "rpc", rpc.Name, "req", rpc.Req, "res", rpc.Res, "module", rpc.Module, "ftype", rpc.FType, "fileloc", rpc.FileLoc) + } + } +} + +// A Proto server RPC method. +type ProtoRPC struct { + // The name of the proto RPC service (i.e. rpc Params would be Params for the name) + Name string + // The request object, such as QueryParamsRequest (queries) or MsgUpdateParams (txs) + Req string + // The response object, such as QueryParamsResponse (queries) or MsgUpdateParamsResponse (txs) + Res string + + // The name of the cosmos extension (x/module) + Module string + // The type of file this proto service is (tx, query, none) + FType FileType + // Where there Query/Msg Server is located (querier.go, msgserver.gom, etc.) + FileLoc string +} + +func (pr *ProtoRPC) String() string { + return fmt.Sprintf( + "Name: %s, Req: %s, Res: %s, Module: %s, FType: %s, FileLoc: %s", + pr.Name, pr.Req, pr.Res, pr.Module, pr.FType, pr.FileLoc, + ) +} + +// -------------- + // BuildProtoInterfaceStub returns the string to save to the file for the msgServer or Querier. func (pr ProtoRPC) BuildProtoInterfaceStub() string { if pr.FType == Tx { diff --git a/spawn/proto_types.go b/spawn/proto_types.go deleted file mode 100644 index 414598f1..00000000 --- a/spawn/proto_types.go +++ /dev/null @@ -1,58 +0,0 @@ -package spawn - -import ( - "fmt" - "log/slog" -) - -// FileType tells the application which type of proto file is it so we can sort Txs from Queries -type FileType string - -const ( - Tx FileType = "tx" - Query FileType = "query" - None FileType = "none" -) - -// get the str of FileType -func (ft FileType) String() string { - return string(ft) -} - -// ModuleMapping a map of the module name to a list of ProtoRPCs -type ModuleMapping map[string][]*ProtoRPC - -func (mm ModuleMapping) Print(logger *slog.Logger) { - for name, v := range mm { - v := v - name := name - - for _, rpc := range v { - logger.Debug("module", "module", name, "rpc", rpc.Name, "req", rpc.Req, "res", rpc.Res, "module", rpc.Module, "ftype", rpc.FType, "fileloc", rpc.FileLoc) - } - } -} - -// A Proto server RPC method. -type ProtoRPC struct { - // The name of the proto RPC service (i.e. rpc Params would be Params for the name) - Name string - // The request object, such as QueryParamsRequest (queries) or MsgUpdateParams (txs) - Req string - // The response object, such as QueryParamsResponse (queries) or MsgUpdateParamsResponse (txs) - Res string - - // The name of the cosmos extension (x/module) - Module string - // The type of file this proto service is (tx, query, none) - FType FileType - // Where there Query/Msg Server is located (querier.go, msgserver.gom, etc.) - FileLoc string -} - -func (pr *ProtoRPC) String() string { - return fmt.Sprintf( - "Name: %s, Req: %s, Res: %s, Module: %s, FType: %s, FileLoc: %s", - pr.Name, pr.Req, pr.Res, pr.Module, pr.FType, pr.FileLoc, - ) -} diff --git a/spawn/types/chain_registry.go b/spawn/types/chain_registry.go new file mode 100644 index 00000000..de96b638 --- /dev/null +++ b/spawn/types/chain_registry.go @@ -0,0 +1,139 @@ +package types + +import ( + "encoding/json" + "os" +) + +// TOOL: https://mholt.github.io/json-to-go/ +// Manual Modifications: +// - Consensus: add omitempty +// - Codebase.Consensus: add omitempty +// - Peers: add omitempty + +type ChainRegistryFormat struct { + Schema string `json:"$schema"` + ChainName string `json:"chain_name"` + Status string `json:"status"` + Website string `json:"website"` + NetworkType string `json:"network_type"` + PrettyName string `json:"pretty_name"` + ChainID string `json:"chain_id"` + 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 Fees `json:"fees"` + Staking Staking `json:"staking"` + Codebase Codebase `json:"codebase"` + Images []Images `json:"images"` + Peers Peers `json:"peers"` + Apis Apis `json:"apis"` + Explorers []Explorers `json:"explorers"` + Keywords []string `json:"keywords"` +} +type FeeTokens struct { + Denom string `json:"denom"` + FixedMinGasPrice int `json:"fixed_min_gas_price"` + LowGasPrice int `json:"low_gas_price"` + AverageGasPrice float64 `json:"average_gas_price"` + HighGasPrice float64 `json:"high_gas_price"` +} +type Fees struct { + FeeTokens []FeeTokens `json:"fee_tokens"` +} +type StakingTokens struct { + Denom string `json:"denom"` +} +type LockDuration struct { + Time string `json:"time"` +} +type Staking struct { + StakingTokens []StakingTokens `json:"staking_tokens"` + LockDuration LockDuration `json:"lock_duration"` +} +type Consensus struct { + Type string `json:"type,omitempty"` + Version string `json:"version,omitempty"` +} +type Genesis struct { + Name string `json:"name"` + GenesisURL string `json:"genesis_url"` +} +type Versions struct { + Name string `json:"name"` + Tag string `json:"tag"` + Height int `json:"height"` + NextVersionName string `json:"next_version_name"` + Proposal int `json:"proposal,omitempty"` + RecommendedVersion string `json:"recommended_version,omitempty"` + CompatibleVersions []string `json:"compatible_versions,omitempty"` + CosmosSdkVersion string `json:"cosmos_sdk_version,omitempty"` + Consensus Consensus `json:"consensus,omitempty"` + CosmwasmVersion string `json:"cosmwasm_version,omitempty"` + CosmwasmEnabled bool `json:"cosmwasm_enabled,omitempty"` + IbcGoVersion string `json:"ibc_go_version,omitempty"` + IcsEnabled []string `json:"ics_enabled,omitempty"` +} +type Codebase struct { + GitRepo string `json:"git_repo"` + RecommendedVersion string `json:"recommended_version"` + CompatibleVersions []string `json:"compatible_versions"` + CosmosSdkVersion string `json:"cosmos_sdk_version"` + Consensus Consensus `json:"consensus,omitempty"` + CosmwasmVersion string `json:"cosmwasm_version"` + CosmwasmEnabled bool `json:"cosmwasm_enabled"` + IbcGoVersion string `json:"ibc_go_version"` + IcsEnabled []string `json:"ics_enabled"` + Genesis Genesis `json:"genesis"` + Versions []Versions `json:"versions"` +} +type Theme struct { + PrimaryColorHex string `json:"primary_color_hex"` +} +type Images struct { + Png string `json:"png"` + Theme Theme `json:"theme"` +} +type Seeds struct { + ID string `json:"id"` + Address string `json:"address"` + Provider string `json:"provider"` +} +type PersistentPeers struct { + ID string `json:"id"` + Address string `json:"address"` + Provider string `json:"provider"` +} +type Peers struct { + Seeds []Seeds `json:"seeds,omitempty"` + PersistentPeers []PersistentPeers `json:"persistent_peers,omitempty"` +} +type RPC struct { + Address string `json:"address"` + Provider string `json:"provider"` +} +type Rest struct { + Address string `json:"address"` + Provider string `json:"provider"` +} +type Apis struct { + RPC []RPC `json:"rpc"` + Rest []Rest `json:"rest"` +} +type Explorers struct { + Kind string `json:"kind"` + URL string `json:"url"` + TxPage string `json:"tx_page"` + AccountPage string `json:"account_page"` +} + +func (v ChainRegistryFormat) SaveJSON(loc string) error { + bz, err := json.MarshalIndent(v, "", " ") + if err != nil { + return err + } + + return os.WriteFile(loc, bz, 0644) +} diff --git a/spawn/errors.go b/spawn/types/errors.go similarity index 98% rename from spawn/errors.go rename to spawn/types/errors.go index 26500c3f..a47832ee 100644 --- a/spawn/errors.go +++ b/spawn/types/errors.go @@ -1,4 +1,4 @@ -package spawn +package types import ( "errors" From d588b96301de794c585d1c4932798b383d55bc7f Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Tue, 6 Aug 2024 07:40:43 -0500 Subject: [PATCH 3/9] fix: testing --- spawn/cfg.go | 1 + spawn/general_parser.go | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/spawn/cfg.go b/spawn/cfg.go index 517aa9ba..794099e4 100644 --- a/spawn/cfg.go +++ b/spawn/cfg.go @@ -203,6 +203,7 @@ func (cfg *NewChainConfig) CreateNewChain() error { } cfg.MetadataFile().SaveJSON(fmt.Sprintf("%s/chain_metadata.json", NewDirName)) + cfg.ChainRegistryFile().SaveJSON(fmt.Sprintf("%s/chain_registry.json", NewDirName)) // setup local-interchain testnets // *testnet.json (chains/ directory) diff --git a/spawn/general_parser.go b/spawn/general_parser.go index bd1e76ed..4645e96b 100644 --- a/spawn/general_parser.go +++ b/spawn/general_parser.go @@ -8,12 +8,28 @@ import ( modfile "golang.org/x/mod/modfile" ) +func getModPath() string { + // used when you `spawn new` + goModPath := path.Join("simapp", "go.mod") + + // testing mode: + if _, err := os.Stat(goModPath); os.IsNotExist(err) { + // specific unit test run + goModPath = path.Join("..", "simapp", "go.mod") + // go test ./... + if _, err := os.Stat(goModPath); os.IsNotExist(err) { + goModPath = path.Join("..", "..", "simapp", "go.mod") + } + } + + return goModPath +} + // ParseVersionFromGoMod parses out the versions for a given goPath // Ex: ParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", false) returns v0.50.X // Ex: ParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", true) returns 0.50.X func ParseVersionFromGoMod(goPath string, removePrefixedV bool) (string, error) { - // open ../simapp/go.mod - goModPath := path.Join("..", "simapp", "go.mod") + goModPath := getModPath() c, err := os.ReadFile(goModPath) if err != nil { From 774a8629cd8a7e176dc943409ddbc6144987c5b0 Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Tue, 6 Aug 2024 07:46:47 -0500 Subject: [PATCH 4/9] fix: dont init() version catch --- spawn/cfg_registry_schema.go | 9 +++++++++ spawn/general_parser.go | 5 +++++ spawn/metadata.go | 6 +----- spawn/metadata_test.go | 19 ------------------- 4 files changed, 15 insertions(+), 24 deletions(-) delete mode 100644 spawn/metadata_test.go diff --git a/spawn/cfg_registry_schema.go b/spawn/cfg_registry_schema.go index 9c6bfc74..af9e0def 100644 --- a/spawn/cfg_registry_schema.go +++ b/spawn/cfg_registry_schema.go @@ -12,6 +12,15 @@ import ( var caser = cases.Title(language.English) func (cfg NewChainConfig) ChainRegistryFile() types.ChainRegistryFormat { + DefaultSDKVersion := MustParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", true) + DefaultTendermintVersion := MustParseVersionFromGoMod("github.com/cometbft/cometbft", true) + DefaultIBCGoVersion := MustParseVersionFromGoMod("github.com/cosmos/ibc-go/v8", true) + + DefaultCosmWasmVersion, err := ParseVersionFromGoMod("github.com/CosmWasm/wasmd", true) + if err != nil { + DefaultCosmWasmVersion = "" + } + return types.ChainRegistryFormat{ Schema: DefaultChainRegistrySchema, ChainName: cfg.ProjectName, diff --git a/spawn/general_parser.go b/spawn/general_parser.go index 4645e96b..9d3d4cad 100644 --- a/spawn/general_parser.go +++ b/spawn/general_parser.go @@ -22,6 +22,11 @@ func getModPath() string { } } + // everything errored (i.e. spawn completion command), give up. + if _, err := os.Stat(goModPath); os.IsNotExist(err) { + return "" + } + return goModPath } diff --git a/spawn/metadata.go b/spawn/metadata.go index d10abb01..d3b9afc8 100644 --- a/spawn/metadata.go +++ b/spawn/metadata.go @@ -18,11 +18,7 @@ const ( ) var ( - DefaultSDKVersion = MustParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", true) - DefaultTendermintVersion = MustParseVersionFromGoMod("github.com/cometbft/cometbft", true) - DefaultIBCGoVersion = MustParseVersionFromGoMod("github.com/cosmos/ibc-go/v8", true) - // TODO: sometimes this will be non existent - DefaultCosmWasmVersion = MustParseVersionFromGoMod("github.com/CosmWasm/wasmd", true) + ) func (cfg *NewChainConfig) MetadataFile() MetadataFile { diff --git a/spawn/metadata_test.go b/spawn/metadata_test.go deleted file mode 100644 index f46fd369..00000000 --- a/spawn/metadata_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package spawn - -import ( - "testing" - - "github.com/stretchr/testify/require" - "golang.org/x/mod/semver" -) - -func TestLoadingValues(t *testing.T) { - // fmt.Println(DefaultSDKVersion) - // fmt.Println(DefaultCosmWasmVersion) - // fmt.Println(DefaultTendermintVersion) - // fmt.Println(DefaultIBCGoVersion) - require.True(t, semver.Compare(DefaultSDKVersion, "0.50.0") >= 0) - require.True(t, semver.Compare(DefaultCosmWasmVersion, "0.50.0") >= 0) - require.True(t, semver.Compare(DefaultTendermintVersion, "0.38.0") >= 0) - require.True(t, semver.Compare(DefaultIBCGoVersion, "8.2.0") >= 0) -} From 052966291fe1e93c2ef9288ff38536ddf6860d96 Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Tue, 6 Aug 2024 08:02:01 -0500 Subject: [PATCH 5/9] nits --- spawn/general_parser.go | 5 ----- spawn/metadata.go | 4 ---- spawn/proto_parser.go | 2 +- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/spawn/general_parser.go b/spawn/general_parser.go index 9d3d4cad..4645e96b 100644 --- a/spawn/general_parser.go +++ b/spawn/general_parser.go @@ -22,11 +22,6 @@ func getModPath() string { } } - // everything errored (i.e. spawn completion command), give up. - if _, err := os.Stat(goModPath); os.IsNotExist(err) { - return "" - } - return goModPath } diff --git a/spawn/metadata.go b/spawn/metadata.go index d3b9afc8..759fa8d1 100644 --- a/spawn/metadata.go +++ b/spawn/metadata.go @@ -17,10 +17,6 @@ const ( DefaultChainRegistrySchema = "https://raw.githubusercontent.com/cosmos/chain-registry/master/chain.schema.json" ) -var ( - -) - func (cfg *NewChainConfig) MetadataFile() MetadataFile { now := time.Now().UTC() now = now.Round(time.Minute) diff --git a/spawn/proto_parser.go b/spawn/proto_parser.go index 889025fe..0753bdf4 100644 --- a/spawn/proto_parser.go +++ b/spawn/proto_parser.go @@ -406,7 +406,7 @@ func ApplyMissingRPCMethodsToGoSourceFiles(logger *slog.Logger, missingRPCMethod content = append(content, []byte("\n"+code)...) if err := os.WriteFile(fileLoc, content, 0644); err != nil { - logger.Error("Error: ", err) + logger.Error("error", "err", err) return err } } From 702f974ecf3a7f718ed5ab3242b40381e596c0a6 Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Tue, 6 Aug 2024 08:23:54 -0500 Subject: [PATCH 6/9] assets generation --- spawn/cfg.go | 1 + spawn/cfg_registry_schema.go | 49 ++++++++++++++++++++- spawn/metadata.go | 17 +++++--- spawn/types/chain_registry_assets_list.go | 53 +++++++++++++++++++++++ 4 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 spawn/types/chain_registry_assets_list.go diff --git a/spawn/cfg.go b/spawn/cfg.go index 794099e4..51b31ccb 100644 --- a/spawn/cfg.go +++ b/spawn/cfg.go @@ -204,6 +204,7 @@ func (cfg *NewChainConfig) CreateNewChain() error { cfg.MetadataFile().SaveJSON(fmt.Sprintf("%s/chain_metadata.json", NewDirName)) cfg.ChainRegistryFile().SaveJSON(fmt.Sprintf("%s/chain_registry.json", NewDirName)) + cfg.ChainRegistryAssetsFile().SaveJSON(fmt.Sprintf("%s/chain_registry_assets.json", NewDirName)) // setup local-interchain testnets // *testnet.json (chains/ directory) diff --git a/spawn/cfg_registry_schema.go b/spawn/cfg_registry_schema.go index af9e0def..e35695d1 100644 --- a/spawn/cfg_registry_schema.go +++ b/spawn/cfg_registry_schema.go @@ -2,6 +2,7 @@ package spawn import ( "fmt" + "strings" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -86,7 +87,7 @@ func (cfg NewChainConfig) ChainRegistryFile() types.ChainRegistryFormat { { Png: DefaultLogo, Theme: types.Theme{ - PrimaryColorHex: "#FF2D00", + PrimaryColorHex: DefaultThemeHexColor, }, }, }, @@ -116,3 +117,49 @@ func (cfg NewChainConfig) ChainRegistryFile() types.ChainRegistryFormat { Keywords: []string{"cosmos", "spawn"}, } } + +// The ICS MetadataFile is similar to this. +func (cfg NewChainConfig) ChainRegistryAssetsFile() types.ChainRegistryAssetsList { + display := strings.TrimPrefix(strings.ToUpper(cfg.Denom), "U") + + return types.ChainRegistryAssetsList{ + Schema: DefaultChainRegistryAssetsSchema, + ChainName: cfg.ProjectName, + Assets: []types.Assets{ + { + Description: "The native token of " + cfg.ProjectName, + DenomUnits: []types.DenomUnits{ + { + Denom: cfg.Denom, // utoken + Exponent: 0, + }, + { + Denom: display, // TOKEN + Exponent: 6, + }, + }, + Base: cfg.Denom, // utoken + Name: fmt.Sprintf("%s %s", cfg.ProjectName, display), + Display: strings.ToLower(display), // token + Symbol: display, // TOKEN + LogoURIs: types.LogoURIs{ + Png: DefaultLogo, + Svg: DefaultLogoSVG, + }, + Images: []types.ImagesAssetLists{ + { + Png: DefaultLogo, + Svg: DefaultLogoSVG, + Theme: types.Theme{ + PrimaryColorHex: DefaultThemeHexColor, + }, + }, + }, + Socials: types.Socials{ + Website: DefaultWebsite, + Twitter: "https://x.com/cosmoshub", + }, + }, + }, + } +} diff --git a/spawn/metadata.go b/spawn/metadata.go index 759fa8d1..bded0136 100644 --- a/spawn/metadata.go +++ b/spawn/metadata.go @@ -8,13 +8,16 @@ import ( ) const ( - DefaultWebsite = "https://example.com" - DefaultLogo = "https://www.shutterstock.com/image-illustration/colourful-business-logo-company-name-260nw-1779060299.jpg" - DefaultDescription = "A short description of your project" - DefaultChainID = "newchain-1" - DefaultNetworkType = "testnet" // or mainnet - DefaultSlip44CoinType = 118 - DefaultChainRegistrySchema = "https://raw.githubusercontent.com/cosmos/chain-registry/master/chain.schema.json" + DefaultWebsite = "https://example.com" + DefaultLogo = "https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.png" + DefaultLogoSVG = "https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/images/atom.svg" + DefaultDescription = "A short description of your project" + DefaultChainID = "newchain-1" + DefaultNetworkType = "testnet" // or mainnet + DefaultSlip44CoinType = 118 + DefaultChainRegistrySchema = "https://raw.githubusercontent.com/cosmos/chain-registry/master/chain.schema.json" + DefaultChainRegistryAssetsSchema = "https://github.com/cosmos/chain-registry/blob/master/assetlist.schema.json" + DefaultThemeHexColor = "#FF2D00" ) func (cfg *NewChainConfig) MetadataFile() MetadataFile { diff --git a/spawn/types/chain_registry_assets_list.go b/spawn/types/chain_registry_assets_list.go new file mode 100644 index 00000000..318bafd2 --- /dev/null +++ b/spawn/types/chain_registry_assets_list.go @@ -0,0 +1,53 @@ +package types + +import ( + "encoding/json" + "os" +) + +// Update: Images -> ImagesAssetLists +// - Fix: Assets.Images -> new type ImagesAssetLists + +type ChainRegistryAssetsList struct { + Schema string `json:"$schema"` + ChainName string `json:"chain_name"` + Assets []Assets `json:"assets"` +} +type DenomUnits struct { + Denom string `json:"denom"` + Exponent int `json:"exponent"` +} +type LogoURIs struct { + Png string `json:"png"` + Svg string `json:"svg"` +} +type ImagesAssetLists struct { + Png string `json:"png"` + Svg string `json:"svg"` + Theme Theme `json:"theme,omitempty"` +} +type Assets struct { + Description string `json:"description"` + DenomUnits []DenomUnits `json:"denom_units"` + Base string `json:"base"` + Name string `json:"name"` + Display string `json:"display"` + Symbol string `json:"symbol"` + LogoURIs LogoURIs `json:"logo_URIs"` + Images []ImagesAssetLists `json:"images"` + Socials Socials `json:"socials,omitempty"` +} + +type Socials struct { + Website string `json:"website,omitempty"` + Twitter string `json:"twitter,omitempty"` +} + +func (v ChainRegistryAssetsList) SaveJSON(loc string) error { + bz, err := json.MarshalIndent(v, "", " ") + if err != nil { + return err + } + + return os.WriteFile(loc, bz, 0644) +} From a153077dddf0cda7c45d9c6b786b02066350504c Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Wed, 14 Aug 2024 12:18:08 -0500 Subject: [PATCH 7/9] feat: reduce complexity --- spawn/cfg.go | 6 ++-- spawn/cfg_registry_schema.go | 21 ++++++------ spawn/cfg_test.go | 4 ++- spawn/general_parser.go | 64 ----------------------------------- spawn/types/chain_registry.go | 2 ++ 5 files changed, 20 insertions(+), 77 deletions(-) delete mode 100644 spawn/general_parser.go diff --git a/spawn/cfg.go b/spawn/cfg.go index 51b31ccb..848f18c1 100644 --- a/spawn/cfg.go +++ b/spawn/cfg.go @@ -402,10 +402,12 @@ func GetFileContent(logger *slog.Logger, newFilePath string, fs embed.FS, relPat return fc, nil } -func (cfg *NewChainConfig) IsCosmWasmEnabled() bool { +func (cfg *NewChainConfig) IsModuleEnabled(module string) bool { + moduleAlias := AliasName(module) + isDisabled := false for _, d := range cfg.DisabledModules { - if AliasName(d) == CosmWasm { + if AliasName(d) == moduleAlias { isDisabled = true break } diff --git a/spawn/cfg_registry_schema.go b/spawn/cfg_registry_schema.go index e35695d1..8c8c9573 100644 --- a/spawn/cfg_registry_schema.go +++ b/spawn/cfg_registry_schema.go @@ -13,18 +13,20 @@ import ( var caser = cases.Title(language.English) func (cfg NewChainConfig) ChainRegistryFile() types.ChainRegistryFormat { - DefaultSDKVersion := MustParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", true) - DefaultTendermintVersion := MustParseVersionFromGoMod("github.com/cometbft/cometbft", true) - DefaultIBCGoVersion := MustParseVersionFromGoMod("github.com/cosmos/ibc-go/v8", true) - - DefaultCosmWasmVersion, err := ParseVersionFromGoMod("github.com/CosmWasm/wasmd", true) - if err != nil { - DefaultCosmWasmVersion = "" + // TODO: update as needed + DefaultSDKVersion := "0.50" + DefaultTendermintVersion := "0.38" + DefaultIBCGoVersion := "8" + DefaultCosmWasmVersion := "" + if cfg.IsModuleEnabled(CosmWasm) { + DefaultCosmWasmVersion = "0.50" } + DefaultConsensus := "tendermint" // TODO: gordian in the future on gen return types.ChainRegistryFormat{ Schema: DefaultChainRegistrySchema, ChainName: cfg.ProjectName, + ChainType: "cosmos", Status: "live", Website: DefaultWebsite, NetworkType: DefaultNetworkType, @@ -47,17 +49,16 @@ func (cfg NewChainConfig) ChainRegistryFile() types.ChainRegistryFormat { }, }, Codebase: types.Codebase{ - // TODO: versions should be fetched from the repo go.mod GitRepo: "https://" + cfg.GithubPath(), RecommendedVersion: "v1.0.0", CompatibleVersions: []string{"v0.9.0"}, CosmosSdkVersion: DefaultSDKVersion, Consensus: types.Consensus{ - Type: "tendermint", // TODO: gordian in the future on gen + Type: DefaultConsensus, Version: DefaultTendermintVersion, }, CosmwasmVersion: DefaultCosmWasmVersion, - CosmwasmEnabled: cfg.IsCosmWasmEnabled(), + CosmwasmEnabled: cfg.IsModuleEnabled(CosmWasm), IbcGoVersion: DefaultIBCGoVersion, IcsEnabled: []string{"ics20-1"}, Genesis: types.Genesis{ diff --git a/spawn/cfg_test.go b/spawn/cfg_test.go index fcacc059..0d4a51d4 100644 --- a/spawn/cfg_test.go +++ b/spawn/cfg_test.go @@ -248,5 +248,7 @@ func TestChainRegistry(t *testing.T) { cfg := goodCfg() cr := cfg.ChainRegistryFile() require.Equal(t, cfg.ProjectName, cr.ChainName) - // cr.SaveJSON("test.json") + require.Equal(t, bech, cr.Bech32Prefix) + require.Equal(t, bin, cr.DaemonName) + require.Equal(t, denom, cr.Fees.FeeTokens[0].Denom) } diff --git a/spawn/general_parser.go b/spawn/general_parser.go deleted file mode 100644 index 4645e96b..00000000 --- a/spawn/general_parser.go +++ /dev/null @@ -1,64 +0,0 @@ -package spawn - -import ( - "fmt" - "os" - "path" - - modfile "golang.org/x/mod/modfile" -) - -func getModPath() string { - // used when you `spawn new` - goModPath := path.Join("simapp", "go.mod") - - // testing mode: - if _, err := os.Stat(goModPath); os.IsNotExist(err) { - // specific unit test run - goModPath = path.Join("..", "simapp", "go.mod") - // go test ./... - if _, err := os.Stat(goModPath); os.IsNotExist(err) { - goModPath = path.Join("..", "..", "simapp", "go.mod") - } - } - - return goModPath -} - -// ParseVersionFromGoMod parses out the versions for a given goPath -// Ex: ParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", false) returns v0.50.X -// Ex: ParseVersionFromGoMod("github.com/cosmos/cosmos-sdk", true) returns 0.50.X -func ParseVersionFromGoMod(goPath string, removePrefixedV bool) (string, error) { - goModPath := getModPath() - - c, err := os.ReadFile(goModPath) - if err != nil { - return "", fmt.Errorf("error reading go.mod file: %w", err) - } - - f, err := modfile.Parse(goModPath, c, nil) - if err != nil { - return "", fmt.Errorf("error parsing go.mod file: %w", err) - } - - for _, r := range f.Require { - if r.Mod.Path == goPath { - v := r.Mod.Version - if removePrefixedV && len(v) > 0 && v[0] == 'v' { - v = v[1:] - } - return v, nil - } - } - - // no error if not found, we just return nothing - return "", fmt.Errorf("module %s not found in go.mod", goPath) -} - -func MustParseVersionFromGoMod(goPath string, removePrefixedV bool) string { - v, err := ParseVersionFromGoMod(goPath, removePrefixedV) - if err != nil { - panic(err) - } - return v -} diff --git a/spawn/types/chain_registry.go b/spawn/types/chain_registry.go index de96b638..f2ffbe77 100644 --- a/spawn/types/chain_registry.go +++ b/spawn/types/chain_registry.go @@ -10,10 +10,12 @@ import ( // - Consensus: add omitempty // - Codebase.Consensus: add omitempty // - Peers: add omitempty +// - added: ChainRegistryFormat ChainType string type ChainRegistryFormat struct { Schema string `json:"$schema"` ChainName string `json:"chain_name"` + ChainType string `json:"chain_type"` Status string `json:"status"` Website string `json:"website"` NetworkType string `json:"network_type"` From d03763cc02b5597a6ec68bc10e557a4750f0ac54 Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Wed, 14 Aug 2024 12:23:09 -0500 Subject: [PATCH 8/9] `IsFeatureEnabled` instead of bool values --- spawn/cfg.go | 40 ++++++++---------------------------- spawn/cfg_registry_schema.go | 4 ++-- spawn/metadata.go | 2 +- spawn/remove_features.go | 4 ++-- 4 files changed, 14 insertions(+), 36 deletions(-) diff --git a/spawn/cfg.go b/spawn/cfg.go index 848f18c1..370de7d1 100644 --- a/spawn/cfg.go +++ b/spawn/cfg.go @@ -60,7 +60,6 @@ type NewChainConfig struct { IgnoreGitInit bool DisabledModules []string Logger *slog.Logger - isUsingICS bool } // NodeHome returns the full path to the node home directory @@ -91,16 +90,8 @@ func (cfg NewChainConfig) ValidateAndRun(doAnnounce bool) error { func (cfg *NewChainConfig) SetProperFeaturePairs() { d := RemoveDuplicates(cfg.DisabledModules) - isUsingICS := true - for _, name := range d { - if AliasName(name) == InterchainSecurity { - isUsingICS = false - } - } - cfg.isUsingICS = isUsingICS - // remove POA if it is being used - if isUsingICS { + if cfg.IsFeatureEnabled(InterchainSecurity) { d = append(d, POA) } @@ -108,15 +99,6 @@ func (cfg *NewChainConfig) SetProperFeaturePairs() { cfg.Logger.Debug("SetProperFeaturePairs Disabled features", "features", cfg.DisabledModules) } -func (cfg *NewChainConfig) IsFeatureDisabled(featName string) bool { - for _, feat := range cfg.DisabledModules { - if AliasName(feat) == AliasName(featName) { - return true - } - } - return false -} - func (cfg *NewChainConfig) Validate() error { if cfg.ProjectName == "" { return types.ErrCfgEmptyProject @@ -216,7 +198,7 @@ func (cfg *NewChainConfig) CreateNewChain() error { cfg.GitInitNewProjectRepo() } - if !cfg.IsFeatureDisabled("block-explorer") { + if cfg.IsFeatureEnabled("block-explorer") { cfg.NewPingPubExplorer() } @@ -331,7 +313,7 @@ func (cfg *NewChainConfig) SetupLocalInterchainJSON() { cosmos.NewGenesisKV("app_state.gov.params.min_deposit.0.amount", "1"), } - if cfg.isUsingICS { + if cfg.IsFeatureEnabled(InterchainSecurity) { c.SetICSConsumerLink("localcosmos-1") } else { // make this is an IBC testnet for POA/POS chains @@ -402,18 +384,14 @@ func GetFileContent(logger *slog.Logger, newFilePath string, fs embed.FS, relPat return fc, nil } -func (cfg *NewChainConfig) IsModuleEnabled(module string) bool { - moduleAlias := AliasName(module) - - isDisabled := false - for _, d := range cfg.DisabledModules { - if AliasName(d) == moduleAlias { - isDisabled = true - break +func (cfg *NewChainConfig) IsFeatureEnabled(feat string) bool { + featAlias := AliasName(feat) + for _, disabledFeat := range cfg.DisabledModules { + if AliasName(disabledFeat) == featAlias { + return false } } - - return !isDisabled + return true } // debugErrorFile saves the errored file to a debug directory for easier debugging. diff --git a/spawn/cfg_registry_schema.go b/spawn/cfg_registry_schema.go index 8c8c9573..23ba9467 100644 --- a/spawn/cfg_registry_schema.go +++ b/spawn/cfg_registry_schema.go @@ -18,7 +18,7 @@ func (cfg NewChainConfig) ChainRegistryFile() types.ChainRegistryFormat { DefaultTendermintVersion := "0.38" DefaultIBCGoVersion := "8" DefaultCosmWasmVersion := "" - if cfg.IsModuleEnabled(CosmWasm) { + if cfg.IsFeatureEnabled(CosmWasm) { DefaultCosmWasmVersion = "0.50" } DefaultConsensus := "tendermint" // TODO: gordian in the future on gen @@ -58,7 +58,7 @@ func (cfg NewChainConfig) ChainRegistryFile() types.ChainRegistryFormat { Version: DefaultTendermintVersion, }, CosmwasmVersion: DefaultCosmWasmVersion, - CosmwasmEnabled: cfg.IsModuleEnabled(CosmWasm), + CosmwasmEnabled: cfg.IsFeatureEnabled(CosmWasm), IbcGoVersion: DefaultIBCGoVersion, IcsEnabled: []string{"ics20-1"}, Genesis: types.Genesis{ diff --git a/spawn/metadata.go b/spawn/metadata.go index bded0136..5ed42878 100644 --- a/spawn/metadata.go +++ b/spawn/metadata.go @@ -52,7 +52,7 @@ func (cfg *NewChainConfig) MetadataFile() MetadataFile { ICS: ICSMeta{}, } - if cfg.isUsingICS { + if cfg.IsFeatureEnabled(InterchainSecurity) { mf.ICS = ICSMeta{ SpawnTime: now, Title: cfg.BinDaemon, diff --git a/spawn/remove_features.go b/spawn/remove_features.go index e5f73cf6..30858310 100644 --- a/spawn/remove_features.go +++ b/spawn/remove_features.go @@ -88,7 +88,7 @@ func (fc *FileContent) RemoveDisabledFeatures(cfg *NewChainConfig) { case GlobalFee: fc.RemoveGlobalFee() case CosmWasm: - fc.RemoveCosmWasm(cfg.IsFeatureDisabled(WasmLC)) + fc.RemoveCosmWasm(cfg.IsFeatureEnabled(WasmLC)) case WasmLC: fc.RemoveWasmLightClient() case PacketForward: @@ -107,7 +107,7 @@ func (fc *FileContent) RemoveDisabledFeatures(cfg *NewChainConfig) { } } - if cfg.isUsingICS { + if cfg.IsFeatureEnabled(InterchainSecurity) { fc.RemoveStandardTestNodeScript() fc.HandleAllTagged("not-ics") // interchaintest fc.removePacketForwardTestOnly() From 47466d66b1f67b366ac63a62f74628d2fb9848ac Mon Sep 17 00:00:00 2001 From: Reece Williams Date: Wed, 14 Aug 2024 12:34:20 -0500 Subject: [PATCH 9/9] fix: logic --- spawn/cfg.go | 1 - spawn/remove_features.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/spawn/cfg.go b/spawn/cfg.go index 370de7d1..41c0cd4e 100644 --- a/spawn/cfg.go +++ b/spawn/cfg.go @@ -90,7 +90,6 @@ func (cfg NewChainConfig) ValidateAndRun(doAnnounce bool) error { func (cfg *NewChainConfig) SetProperFeaturePairs() { d := RemoveDuplicates(cfg.DisabledModules) - // remove POA if it is being used if cfg.IsFeatureEnabled(InterchainSecurity) { d = append(d, POA) } diff --git a/spawn/remove_features.go b/spawn/remove_features.go index 30858310..7a22da8a 100644 --- a/spawn/remove_features.go +++ b/spawn/remove_features.go @@ -88,7 +88,7 @@ func (fc *FileContent) RemoveDisabledFeatures(cfg *NewChainConfig) { case GlobalFee: fc.RemoveGlobalFee() case CosmWasm: - fc.RemoveCosmWasm(cfg.IsFeatureEnabled(WasmLC)) + fc.RemoveCosmWasm(!cfg.IsFeatureEnabled(WasmLC)) case WasmLC: fc.RemoveWasmLightClient() case PacketForward: