laconicd/cmd/ethermintd/config/config.go

120 lines
3.1 KiB
Go
Raw Normal View History

2021-04-18 16:39:15 +00:00
package config
import (
"fmt"
"strings"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/telemetry"
"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:8545"
2021-04-18 16:39:15 +00:00
// DefaultEVMWSAddress is the default address the EVM WebSocket server binds to.
DefaultEVMWSAddress = "0.0.0.0:8546"
2021-04-18 16:39:15 +00:00
)
// 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
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 {
config.BaseConfig `mapstructure:",squash"`
2021-04-18 16:39:15 +00:00
// Telemetry defines the application telemetry configuration
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 {
cfg := config.DefaultConfig()
2021-04-18 16:39:15 +00:00
return &Config{
BaseConfig: cfg.BaseConfig,
Telemetry: cfg.Telemetry,
API: cfg.API,
GRPC: cfg.GRPC,
2021-04-18 16:39:15 +00:00
EVMRPC: EVMRPCConfig{
Enable: true,
RPCAddress: DefaultEVMAddress,
2021-04-18 16:39:15 +00:00
WsAddress: DefaultEVMWSAddress,
},
StateSync: cfg.StateSync,
2021-04-18 16:39:15 +00:00
}
}
// GetConfig returns a fully parsed Config object.
func GetConfig(v *viper.Viper) Config {
cfg := config.GetConfig(v)
2021-04-18 16:39:15 +00:00
return Config{
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"),
RPCAddress: v.GetString("evm-rpc.address"),
2021-04-18 16:39:15 +00:00
WsAddress: v.GetString("evm-rpc.ws-address"),
},
StateSync: cfg.StateSync,
2021-04-18 16:39:15 +00:00
}
}