2021-04-18 16:39:15 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2021-05-10 16:34:00 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/telemetry"
|
|
|
|
|
2021-06-25 09:18:37 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/server/config"
|
2021-04-18 16:39:15 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// DefaultGRPCAddress is the default address the gRPC server binds to.
|
|
|
|
DefaultGRPCAddress = "0.0.0.0:9900"
|
|
|
|
|
|
|
|
// DefaultEVMAddress is the default address the EVM JSON-RPC server binds to.
|
|
|
|
DefaultEVMAddress = "0.0.0.0:1317"
|
|
|
|
|
|
|
|
// DefaultEVMWSAddress is the default address the EVM WebSocket server binds to.
|
|
|
|
DefaultEVMWSAddress = "0.0.0.0:1318"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EVMRPCConfig defines configuration for the EVM RPC server.
|
|
|
|
type EVMRPCConfig struct {
|
|
|
|
// Enable defines if the EVM RPC server should be enabled.
|
|
|
|
Enable bool `mapstructure:"enable"`
|
|
|
|
// Address defines the HTTP server to listen on
|
2021-05-10 16:34:00 +00:00
|
|
|
RPCAddress string `mapstructure:"address"`
|
2021-04-18 16:39:15 +00:00
|
|
|
// Address defines the WebSocket server to listen on
|
|
|
|
WsAddress string `mapstructure:"ws-address"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config defines the server's top level configuration
|
|
|
|
type Config struct {
|
2021-06-25 09:18:37 +00:00
|
|
|
config.BaseConfig `mapstructure:",squash"`
|
2021-04-18 16:39:15 +00:00
|
|
|
|
|
|
|
// Telemetry defines the application telemetry configuration
|
2021-06-25 09:18:37 +00:00
|
|
|
Telemetry telemetry.Config `mapstructure:"telemetry"`
|
|
|
|
API config.APIConfig `mapstructure:"api"`
|
|
|
|
GRPC config.GRPCConfig `mapstructure:"grpc"`
|
|
|
|
EVMRPC EVMRPCConfig `mapstructure:"evm-rpc"`
|
|
|
|
StateSync config.StateSyncConfig `mapstructure:"state-sync"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) ToSDKConfig() *config.Config {
|
|
|
|
return &config.Config{
|
|
|
|
BaseConfig: c.BaseConfig,
|
|
|
|
Telemetry: c.Telemetry,
|
|
|
|
API: c.API,
|
|
|
|
GRPC: c.GRPC,
|
|
|
|
StateSync: c.StateSync,
|
|
|
|
}
|
2021-04-18 16:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetMinGasPrices sets the validator's minimum gas prices.
|
|
|
|
func (c *Config) SetMinGasPrices(gasPrices sdk.DecCoins) {
|
|
|
|
c.MinGasPrices = gasPrices.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMinGasPrices returns the validator's minimum gas prices based on the set
|
|
|
|
// configuration.
|
|
|
|
func (c *Config) GetMinGasPrices() sdk.DecCoins {
|
|
|
|
if c.MinGasPrices == "" {
|
|
|
|
return sdk.DecCoins{}
|
|
|
|
}
|
|
|
|
|
|
|
|
gasPricesStr := strings.Split(c.MinGasPrices, ";")
|
|
|
|
gasPrices := make(sdk.DecCoins, len(gasPricesStr))
|
|
|
|
|
|
|
|
for i, s := range gasPricesStr {
|
|
|
|
gasPrice, err := sdk.ParseDecCoin(s)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("failed to parse minimum gas price coin (%s): %s", s, err))
|
|
|
|
}
|
|
|
|
|
|
|
|
gasPrices[i] = gasPrice
|
|
|
|
}
|
|
|
|
|
|
|
|
return gasPrices
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultConfig returns server's default configuration.
|
|
|
|
func DefaultConfig() *Config {
|
2021-06-25 09:18:37 +00:00
|
|
|
cfg := config.DefaultConfig()
|
2021-04-18 16:39:15 +00:00
|
|
|
return &Config{
|
2021-06-25 09:18:37 +00:00
|
|
|
BaseConfig: cfg.BaseConfig,
|
|
|
|
Telemetry: cfg.Telemetry,
|
|
|
|
API: cfg.API,
|
|
|
|
GRPC: cfg.GRPC,
|
2021-04-18 16:39:15 +00:00
|
|
|
EVMRPC: EVMRPCConfig{
|
|
|
|
Enable: true,
|
2021-05-10 16:34:00 +00:00
|
|
|
RPCAddress: DefaultEVMAddress,
|
2021-04-18 16:39:15 +00:00
|
|
|
WsAddress: DefaultEVMWSAddress,
|
|
|
|
},
|
2021-06-25 09:18:37 +00:00
|
|
|
StateSync: cfg.StateSync,
|
2021-04-18 16:39:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetConfig returns a fully parsed Config object.
|
|
|
|
func GetConfig(v *viper.Viper) Config {
|
2021-06-25 09:18:37 +00:00
|
|
|
|
|
|
|
cfg := config.GetConfig(v)
|
2021-04-18 16:39:15 +00:00
|
|
|
|
|
|
|
return Config{
|
2021-06-25 09:18:37 +00:00
|
|
|
BaseConfig: cfg.BaseConfig,
|
|
|
|
Telemetry: cfg.Telemetry,
|
|
|
|
API: cfg.API,
|
|
|
|
GRPC: cfg.GRPC,
|
2021-04-18 16:39:15 +00:00
|
|
|
EVMRPC: EVMRPCConfig{
|
|
|
|
Enable: v.GetBool("evm-rpc.enable"),
|
2021-05-10 16:34:00 +00:00
|
|
|
RPCAddress: v.GetString("evm-rpc.address"),
|
2021-04-18 16:39:15 +00:00
|
|
|
WsAddress: v.GetString("evm-rpc.ws-address"),
|
|
|
|
},
|
2021-06-25 09:18:37 +00:00
|
|
|
StateSync: cfg.StateSync,
|
2021-04-18 16:39:15 +00:00
|
|
|
}
|
|
|
|
}
|