mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-07 06:36:42 +00:00
Merge pull request #61 from planetmint/53-adjust-json-configuration-loading-for-node-setup
[config] Add planetmint section to `app.toml`
This commit is contained in:
commit
70b61372d2
@ -36,10 +36,12 @@ import (
|
|||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
// this line is used by starport scaffolding # root/moduleImport
|
// this line is used by starport scaffolding # root/moduleImport
|
||||||
|
|
||||||
"planetmint-go/app"
|
"planetmint-go/app"
|
||||||
appparams "planetmint-go/app/params"
|
appparams "planetmint-go/app/params"
|
||||||
|
planetmintconfig "planetmint-go/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewRootCmd creates a new root command for a Cosmos SDK application
|
// NewRootCmd creates a new root command for a Cosmos SDK application
|
||||||
@ -234,6 +236,10 @@ func (a appCreator) newApp(
|
|||||||
) servertypes.Application {
|
) servertypes.Application {
|
||||||
var cache sdk.MultiStorePersistentCache
|
var cache sdk.MultiStorePersistentCache
|
||||||
|
|
||||||
|
// Get [planetmint] section from app.toml
|
||||||
|
plmntConfig := planetmintconfig.GetConfig()
|
||||||
|
plmntConfig.SetWatchmenConfig(appOpts.Get("planetmint"))
|
||||||
|
|
||||||
if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
|
if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
|
||||||
cache = store.NewCommitKVStoreCacheManager()
|
cache = store.NewCommitKVStoreCacheManager()
|
||||||
}
|
}
|
||||||
@ -344,6 +350,7 @@ func initAppConfig() (string, interface{}) {
|
|||||||
|
|
||||||
type CustomAppConfig struct {
|
type CustomAppConfig struct {
|
||||||
serverconfig.Config
|
serverconfig.Config
|
||||||
|
PlmntConfig planetmintconfig.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally allow the chain developer to overwrite the SDK's default
|
// Optionally allow the chain developer to overwrite the SDK's default
|
||||||
@ -363,10 +370,13 @@ func initAppConfig() (string, interface{}) {
|
|||||||
// In simapp, we set the min gas prices to 0.
|
// In simapp, we set the min gas prices to 0.
|
||||||
srvCfg.MinGasPrices = "0stake"
|
srvCfg.MinGasPrices = "0stake"
|
||||||
|
|
||||||
|
plmntCfg := planetmintconfig.DefaultConfig()
|
||||||
|
|
||||||
customAppConfig := CustomAppConfig{
|
customAppConfig := CustomAppConfig{
|
||||||
Config: *srvCfg,
|
Config: *srvCfg,
|
||||||
|
PlmntConfig: *plmntCfg,
|
||||||
}
|
}
|
||||||
customAppTemplate := serverconfig.DefaultConfigTemplate
|
customAppTemplate := serverconfig.DefaultConfigTemplate + planetmintconfig.DefaultConfigTemplate
|
||||||
|
|
||||||
return customAppTemplate, customAppConfig
|
return customAppTemplate, customAppConfig
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"WATCHMEN_ENDPOINT": "localhost",
|
|
||||||
"WATCHMEN_PORT": 7401
|
|
||||||
}
|
|
@ -1,36 +1,65 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"encoding/json"
|
||||||
"path/filepath"
|
"fmt"
|
||||||
"runtime"
|
"sync"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/tkanos/gonfig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Configuration struct {
|
const DefaultConfigTemplate = `
|
||||||
WATCHMEN_ENDPOINT string
|
###############################################################################
|
||||||
WATCHMEN_PORT int
|
### Planetmint ###
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
[planetmint]
|
||||||
|
watchmen-endpoint = "{{ .PlmntConfig.WatchmenConfig.Endpoint }}"
|
||||||
|
watchmen-port = {{ .PlmntConfig.WatchmenConfig.Port }}
|
||||||
|
`
|
||||||
|
|
||||||
|
// Config defines Planetmint's top level configuration
|
||||||
|
type Config struct {
|
||||||
|
WatchmenConfig WatchmenConfig `mapstructure:"watchmen-config" json:"watchmen-config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfig(params ...string) Configuration {
|
// WatchmenConfig defines Planetmint's watchmen configuration
|
||||||
configuration := Configuration{}
|
type WatchmenConfig struct {
|
||||||
env := "dev"
|
Endpoint string `mapstructure:"watchmen-endpoint" json:"watchmen-endpoint"`
|
||||||
|
Port int `mapstructure:"watchmen-port" json:"watchmen-port"`
|
||||||
if len(params) > 0 {
|
|
||||||
env = params[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filename := []string{"config.", env, ".json"}
|
// cosmos-sdk wide global singleton
|
||||||
_, dirname, _, _ := runtime.Caller(0)
|
var (
|
||||||
filePath := path.Join(filepath.Dir(dirname), strings.Join(filename, ""))
|
plmntConfig *Config
|
||||||
|
initConfig sync.Once
|
||||||
|
)
|
||||||
|
|
||||||
err := gonfig.GetConf(filePath, &configuration)
|
// DefaultConfig returns planetmint's default configuration.
|
||||||
|
func DefaultConfig() *Config {
|
||||||
|
return &Config{
|
||||||
|
WatchmenConfig: WatchmenConfig{
|
||||||
|
Endpoint: "localhost",
|
||||||
|
Port: 7401,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConfig returns the config instance for the SDK.
|
||||||
|
func GetConfig() *Config {
|
||||||
|
initConfig.Do(func() {
|
||||||
|
plmntConfig = DefaultConfig()
|
||||||
|
})
|
||||||
|
return plmntConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWatchmenConfig sets Planetmint's watchmen configuration
|
||||||
|
func (config *Config) SetWatchmenConfig(watchmenConfig interface{}) {
|
||||||
|
jsonWatchmenConfig, err := json.Marshal(watchmenConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
err = json.Unmarshal(jsonWatchmenConfig, &config.WatchmenConfig)
|
||||||
return configuration
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("%+v\n", config.WatchmenConfig.Port)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"WATCHMEN_ENDPOINT": "localhost",
|
|
||||||
"WATCHMEN_PORT": 7401
|
|
||||||
}
|
|
1
go.mod
1
go.mod
@ -23,7 +23,6 @@ require (
|
|||||||
github.com/spf13/cobra v1.6.1
|
github.com/spf13/cobra v1.6.1
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
github.com/stretchr/testify v1.8.2
|
github.com/stretchr/testify v1.8.2
|
||||||
github.com/tkanos/gonfig v0.0.0-20210106201359-53e13348de2f
|
|
||||||
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
|
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
|
||||||
google.golang.org/grpc v1.55.0
|
google.golang.org/grpc v1.55.0
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
|
2
go.sum
2
go.sum
@ -960,8 +960,6 @@ github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2l
|
|||||||
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
|
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
|
||||||
github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
|
github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
|
||||||
github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
|
github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
|
||||||
github.com/tkanos/gonfig v0.0.0-20210106201359-53e13348de2f h1:xDFq4NVQD34ekH5UsedBSgfxsBuPU2aZf7v4t0tH2jY=
|
|
||||||
github.com/tkanos/gonfig v0.0.0-20210106201359-53e13348de2f/go.mod h1:DaZPBuToMc2eezA9R9nDAnmS2RMwL7yEa5YD36ESQdI=
|
|
||||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||||
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
|
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
|
||||||
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||||
|
@ -46,7 +46,7 @@ func validateIssuerLiquid(issuerLiquid string) bool {
|
|||||||
|
|
||||||
func (k msgServer) reissueMachine(machine *types.Machine) error {
|
func (k msgServer) reissueMachine(machine *types.Machine) error {
|
||||||
conf := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
client := osc.NewClient(conf.WATCHMEN_ENDPOINT, int(conf.WATCHMEN_PORT))
|
client := osc.NewClient(conf.WatchmenConfig.Endpoint, conf.WatchmenConfig.Port)
|
||||||
msg := osc.NewMessage("/rddl/*")
|
msg := osc.NewMessage("/rddl/*")
|
||||||
msg.Append(machine.Name)
|
msg.Append(machine.Name)
|
||||||
msg.Append(machine.Ticker)
|
msg.Append(machine.Ticker)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user