mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-07-10 14:32:31 +00:00
DRY: Use RootDir from main config (#155)
Usually passed by `--home`. Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
parent
6472d7693f
commit
0b6b1e120a
@ -77,7 +77,7 @@ func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
customAppTemplate, customAppConfig := initAppConfig()
|
customAppTemplate, customAppConfig := initAppConfig(initClientCtx)
|
||||||
customTMConfig := initTendermintConfig()
|
customTMConfig := initTendermintConfig()
|
||||||
return server.InterceptConfigsPreRunHandler(
|
return server.InterceptConfigsPreRunHandler(
|
||||||
cmd, customAppTemplate, customAppConfig, customTMConfig,
|
cmd, customAppTemplate, customAppConfig, customTMConfig,
|
||||||
@ -345,7 +345,7 @@ func (a appCreator) appExport(
|
|||||||
|
|
||||||
// initAppConfig helps to override default appConfig template and configs.
|
// initAppConfig helps to override default appConfig template and configs.
|
||||||
// return "", nil if no custom configuration is required for the application.
|
// return "", nil if no custom configuration is required for the application.
|
||||||
func initAppConfig() (string, interface{}) {
|
func initAppConfig(clientCtx client.Context) (string, interface{}) {
|
||||||
// The following code snippet is just for reference.
|
// The following code snippet is just for reference.
|
||||||
|
|
||||||
type CustomAppConfig struct {
|
type CustomAppConfig struct {
|
||||||
@ -371,6 +371,7 @@ func initAppConfig() (string, interface{}) {
|
|||||||
srvCfg.MinGasPrices = "0stake"
|
srvCfg.MinGasPrices = "0stake"
|
||||||
|
|
||||||
plmntCfg := planetmintconfig.DefaultConfig()
|
plmntCfg := planetmintconfig.DefaultConfig()
|
||||||
|
plmntCfg.SetRoot(clientCtx.HomeDir)
|
||||||
|
|
||||||
customAppConfig := CustomAppConfig{
|
customAppConfig := CustomAppConfig{
|
||||||
Config: *srvCfg,
|
Config: *srvCfg,
|
||||||
|
@ -2,8 +2,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os/user"
|
|
||||||
"path/filepath"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +16,6 @@ asset-registry-endpoint = "{{ .PlmntConfig.AssetRegistryEndpoint }}"
|
|||||||
token-denom = "{{ .PlmntConfig.TokenDenom }}"
|
token-denom = "{{ .PlmntConfig.TokenDenom }}"
|
||||||
stake-denom = "{{ .PlmntConfig.StakeDenom }}"
|
stake-denom = "{{ .PlmntConfig.StakeDenom }}"
|
||||||
fee-denom = "{{ .PlmntConfig.FeeDenom }}"
|
fee-denom = "{{ .PlmntConfig.FeeDenom }}"
|
||||||
config-root-dir = "{{ .PlmntConfig.ConfigRootDir }}"
|
|
||||||
pop-epochs = {{ .PlmntConfig.PoPEpochs }}
|
pop-epochs = {{ .PlmntConfig.PoPEpochs }}
|
||||||
rpc-host = "{{ .PlmntConfig.RPCHost }}"
|
rpc-host = "{{ .PlmntConfig.RPCHost }}"
|
||||||
rpc-port = {{ .PlmntConfig.RPCPort }}
|
rpc-port = {{ .PlmntConfig.RPCPort }}
|
||||||
@ -37,7 +34,7 @@ type Config struct {
|
|||||||
TokenDenom string `mapstructure:"token-denom" json:"token-denom"`
|
TokenDenom string `mapstructure:"token-denom" json:"token-denom"`
|
||||||
StakeDenom string `mapstructure:"stake-denom" json:"stake-denom"`
|
StakeDenom string `mapstructure:"stake-denom" json:"stake-denom"`
|
||||||
FeeDenom string `mapstructure:"fee-denom" json:"fee-denom"`
|
FeeDenom string `mapstructure:"fee-denom" json:"fee-denom"`
|
||||||
ConfigRootDir string `mapstructure:"config-root-dir" json:"config-root-dir"`
|
ConfigRootDir string
|
||||||
PoPEpochs int `mapstructure:"pop-epochs" json:"pop-epochs"`
|
PoPEpochs int `mapstructure:"pop-epochs" json:"pop-epochs"`
|
||||||
RPCHost string `mapstructure:"rpc-host" json:"rpc-host"`
|
RPCHost string `mapstructure:"rpc-host" json:"rpc-host"`
|
||||||
RPCPort int `mapstructure:"rpc-port" json:"rpc-port"`
|
RPCPort int `mapstructure:"rpc-port" json:"rpc-port"`
|
||||||
@ -57,17 +54,12 @@ var (
|
|||||||
|
|
||||||
// DefaultConfig returns planetmint's default configuration.
|
// DefaultConfig returns planetmint's default configuration.
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
currentUser, err := user.Current()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Config{
|
return &Config{
|
||||||
AssetRegistryEndpoint: "https://assets.rddl.io/register_asset",
|
AssetRegistryEndpoint: "https://assets.rddl.io/register_asset",
|
||||||
TokenDenom: "plmnt",
|
TokenDenom: "plmnt",
|
||||||
StakeDenom: "plmntstake",
|
StakeDenom: "plmntstake",
|
||||||
FeeDenom: "plmnt",
|
FeeDenom: "plmnt",
|
||||||
ConfigRootDir: filepath.Join(currentUser.HomeDir, ".planetmint-go"),
|
ConfigRootDir: "",
|
||||||
PoPEpochs: 24, // 24 CometBFT epochs of 5s equate 120s
|
PoPEpochs: 24, // 24 CometBFT epochs of 5s equate 120s
|
||||||
RPCHost: "localhost",
|
RPCHost: "localhost",
|
||||||
RPCPort: 18884,
|
RPCPort: 18884,
|
||||||
@ -88,6 +80,11 @@ func GetConfig() *Config {
|
|||||||
return plmntConfig
|
return plmntConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (config *Config) SetRoot(root string) *Config {
|
||||||
|
config.ConfigRootDir = root
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
// SetWatchmenConfig sets Planetmint's configuration
|
// SetWatchmenConfig sets Planetmint's configuration
|
||||||
func (config *Config) SetPlanetmintConfig(planetmintconfig interface{}) {
|
func (config *Config) SetPlanetmintConfig(planetmintconfig interface{}) {
|
||||||
jsonConfig, err := json.Marshal(planetmintconfig)
|
jsonConfig, err := json.Marshal(planetmintconfig)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user