Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
19f5106
Separate the struct definitions of the chainconfig from the parser
vinbrucelu May 28, 2022
fd2df4f
Move the struct Config into v0 package
vinbrucelu May 28, 2022
a888e94
Add and implement the interface Config
vinbrucelu May 28, 2022
9cf765d
Parse the yaml based on the version
vinbrucelu May 28, 2022
9fd917b
Move the filed Build into the common struct
vinbrucelu May 28, 2022
ed10e84
Create the interface for validator
vinbrucelu May 28, 2022
406892b
Change the parameter for parse
vinbrucelu May 28, 2022
0d55203
Add the conversion
vinbrucelu May 28, 2022
efd4cdd
Replace v0 with v1 after parsing
vinbrucelu May 28, 2022
ea5eb64
Fix the getInit for v1
vinbrucelu May 28, 2022
6b0a64a
Update the parser and the validator
vinbrucelu May 28, 2022
4d32b91
Replace v0 with v1 in env
vinbrucelu May 28, 2022
de14518
Change the template
vinbrucelu May 28, 2022
d226a4d
Fixes the issue with the GetHost interface
vinbrucelu May 28, 2022
8e95f25
Add the method to increment the port number
vinbrucelu May 28, 2022
075ca49
Move FaucetHost to the common package
vinbrucelu May 28, 2022
a0d5b67
Remove the default() in config
vinbrucelu May 28, 2022
e04345d
Type the Version
vinbrucelu May 28, 2022
03501b3
Refactor the function Parse
vinbrucelu May 28, 2022
459091b
Add the test to verify the Parse with migration
vinbrucelu May 28, 2022
e3b0326
Clean up the interface of Config
vinbrucelu May 28, 2022
7255760
Update the subcommands for ignite chain
vinbrucelu May 28, 2022
16f2a86
Add tests on the ConfigYaml an some comments
vinbrucelu May 28, 2022
1c59b08
Add the struct defining Gentx
vinbrucelu May 28, 2022
bfe0781
Remove the getters in BaseConfig
vinbrucelu May 31, 2022
3c2540f
Fix the function ConvertLatest
vinbrucelu May 31, 2022
482c7b0
Remove all getters
vinbrucelu May 31, 2022
3ab4c60
refactor createValidatorFromConfig
vinbrucelu May 31, 2022
9669aab
Refactor the common pkg
vinbrucelu May 31, 2022
953e8e7
Change FillValidatorsDefaults and add tests
vinbrucelu May 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions ignite/chainconfig/common/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package common

type Version int

// Account holds the options related to setting up Cosmos wallets.
type Account struct {
Name string `yaml:"name"`
Coins []string `yaml:"coins,omitempty"`
Mnemonic string `yaml:"mnemonic,omitempty"`
Address string `yaml:"address,omitempty"`
CoinType string `yaml:"cointype,omitempty"`

// The RPCAddress off the chain that account is issued at.
RPCAddress string `yaml:"rpc_address,omitempty"`
}

// Build holds build configs.
type Build struct {
Main string `yaml:"main"`
Binary string `yaml:"binary"`
LDFlags []string `yaml:"ldflags"`
Proto Proto `yaml:"proto"`
}

// Proto holds proto build configs.
type Proto struct {
// Path is the relative path of where app's proto files are located at.
Path string `yaml:"path"`

// ThirdPartyPath is the relative path of where the third party proto files are
// located that used by the app.
ThirdPartyPaths []string `yaml:"third_party_paths"`
}

// Client configures code generation for clients.
type Client struct {
// Vuex configures code generation for Vuex.
Vuex Vuex `yaml:"vuex"`

// Dart configures client code generation for Dart.
Dart Dart `yaml:"dart"`

// OpenAPI configures OpenAPI spec generation for API.
OpenAPI OpenAPI `yaml:"openapi"`
}

// Vuex configures code generation for Vuex.
type Vuex struct {
// Path configures out location for generated Vuex code.
Path string `yaml:"path"`
}

// Dart configures client code generation for Dart.
type Dart struct {
// Path configures out location for generated Dart code.
Path string `yaml:"path"`
}

// OpenAPI configures OpenAPI spec generation for API.
type OpenAPI struct {
Path string `yaml:"path"`
}

// Faucet configuration.
type Faucet struct {
// Name is faucet account's name.
Name *string `yaml:"name"`

// Coins holds type of coin denoms and amounts to distribute.
Coins []string `yaml:"coins"`

// CoinsMax holds of chain denoms and their max amounts that can be transferred
// to single user.
CoinsMax []string `yaml:"coins_max"`

// LimitRefreshTime sets the timeframe at the end of which the limit will be refreshed
RateLimitWindow string `yaml:"rate_limit_window"`

// Host is the host of the faucet server
Host string `yaml:"host"`

// Port number for faucet server to listen at.
Port int `yaml:"port"`
}

// Init overwrites sdk configurations with given values.
type Init struct {
// App overwrites appd's config/app.toml configs.
App map[string]interface{} `yaml:"app"`

// Client overwrites appd's config/client.toml configs.
Client map[string]interface{} `yaml:"client"`

// Config overwrites appd's config/config.toml configs.
Config map[string]interface{} `yaml:"config"`

// Home overwrites default home directory used for the app
Home string `yaml:"home"`

// KeyringBackend is the default keyring backend to use for blockchain initialization
KeyringBackend string `yaml:"keyring-backend"`
}

// Host keeps configuration related to started servers.
type Host struct {
RPC string `yaml:"rpc"`
P2P string `yaml:"p2p"`
Prof string `yaml:"prof"`
GRPC string `yaml:"grpc"`
GRPCWeb string `yaml:"grpc-web"`
API string `yaml:"api"`
}

// BaseConfig is the struct containing all the common fields for the config across all the versions.
type BaseConfig struct {
ConfigVersion Version `yaml:"version"`
Build Build `yaml:"build"`
Accounts []Account `yaml:"accounts"`
Faucet Faucet `yaml:"faucet"`
Client Client `yaml:"client"`
Genesis map[string]interface{} `yaml:"genesis"`
}

// GetVersion returns the version of the config.yaml file.
func (c BaseConfig) Version() Version {
return c.ConfigVersion
}

// AccountByName finds account by name.
func (c BaseConfig) AccountByName(name string) (acc Account, found bool) {
for _, acc := range c.Accounts {
if acc.Name == name {
return acc, true
}
}
return Account{}, false
}
12 changes: 12 additions & 0 deletions ignite/chainconfig/common/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package common

// Config is the interface defining all the common methods for the ConfigYaml struct across all supported versions
type Config interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to the chainconfig and remove this file?

Copy link
Contributor Author

@vinbrucelu vinbrucelu May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving into chainconfig can lead to the error "import cycle not allowed". That was the reason I created this interface in common package to avoid it.

Clone() Config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Clone() Config

Why do we need Clone()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time we retrieve the instance based on the version, but we need to keep the original in the map without any changes. That's why we only return a copy, so we just leverage the copy to parse, and nothing is changed in the map.


// Version returns the version of the Config
Version() Version

// ConvertNext converts the instance of Config from the current version to the next version.
ConvertNext() (Config, error)
}
Loading