DRY: Use RootDir from main config (#155)

Usually passed by `--home`.

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2023-10-23 10:45:10 +02:00 committed by GitHub
parent 6472d7693f
commit 0b6b1e120a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 12 deletions

View File

@ -77,7 +77,7 @@ func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) {
return err
}
customAppTemplate, customAppConfig := initAppConfig()
customAppTemplate, customAppConfig := initAppConfig(initClientCtx)
customTMConfig := initTendermintConfig()
return server.InterceptConfigsPreRunHandler(
cmd, customAppTemplate, customAppConfig, customTMConfig,
@ -345,7 +345,7 @@ func (a appCreator) appExport(
// initAppConfig helps to override default appConfig template and configs.
// 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.
type CustomAppConfig struct {
@ -371,6 +371,7 @@ func initAppConfig() (string, interface{}) {
srvCfg.MinGasPrices = "0stake"
plmntCfg := planetmintconfig.DefaultConfig()
plmntCfg.SetRoot(clientCtx.HomeDir)
customAppConfig := CustomAppConfig{
Config: *srvCfg,

View File

@ -2,8 +2,6 @@ package config
import (
"encoding/json"
"os/user"
"path/filepath"
"sync"
)
@ -18,7 +16,6 @@ asset-registry-endpoint = "{{ .PlmntConfig.AssetRegistryEndpoint }}"
token-denom = "{{ .PlmntConfig.TokenDenom }}"
stake-denom = "{{ .PlmntConfig.StakeDenom }}"
fee-denom = "{{ .PlmntConfig.FeeDenom }}"
config-root-dir = "{{ .PlmntConfig.ConfigRootDir }}"
pop-epochs = {{ .PlmntConfig.PoPEpochs }}
rpc-host = "{{ .PlmntConfig.RPCHost }}"
rpc-port = {{ .PlmntConfig.RPCPort }}
@ -37,7 +34,7 @@ type Config struct {
TokenDenom string `mapstructure:"token-denom" json:"token-denom"`
StakeDenom string `mapstructure:"stake-denom" json:"stake-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"`
RPCHost string `mapstructure:"rpc-host" json:"rpc-host"`
RPCPort int `mapstructure:"rpc-port" json:"rpc-port"`
@ -57,17 +54,12 @@ var (
// DefaultConfig returns planetmint's default configuration.
func DefaultConfig() *Config {
currentUser, err := user.Current()
if err != nil {
panic(err)
}
return &Config{
AssetRegistryEndpoint: "https://assets.rddl.io/register_asset",
TokenDenom: "plmnt",
StakeDenom: "plmntstake",
FeeDenom: "plmnt",
ConfigRootDir: filepath.Join(currentUser.HomeDir, ".planetmint-go"),
ConfigRootDir: "",
PoPEpochs: 24, // 24 CometBFT epochs of 5s equate 120s
RPCHost: "localhost",
RPCPort: 18884,
@ -88,6 +80,11 @@ func GetConfig() *Config {
return plmntConfig
}
func (config *Config) SetRoot(root string) *Config {
config.ConfigRootDir = root
return config
}
// SetWatchmenConfig sets Planetmint's configuration
func (config *Config) SetPlanetmintConfig(planetmintconfig interface{}) {
jsonConfig, err := json.Marshal(planetmintconfig)