2021-04-18 16:39:15 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2021-06-29 17:02:21 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/server/config"
|
2021-04-18 16:39:15 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
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.
|
2021-06-29 07:05:23 +00:00
|
|
|
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.
|
2021-06-29 07:05:23 +00:00
|
|
|
DefaultEVMWSAddress = "0.0.0.0:8546"
|
2021-04-18 16:39:15 +00:00
|
|
|
)
|
|
|
|
|
2021-07-26 11:15:55 +00:00
|
|
|
// GetDefaultAPINamespaces returns the default list of JSON-RPC namespaces that should be enabled
|
|
|
|
func GetDefaultAPINamespaces() []string {
|
2021-08-03 16:35:04 +00:00
|
|
|
return []string{"eth", "net", "web3"}
|
2021-07-26 11:15:55 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
// AppConfig helps to override default appConfig template and configs.
|
|
|
|
// return "", nil if no custom configuration is required for the application.
|
2021-07-28 09:47:29 +00:00
|
|
|
func AppConfig(denom string) (string, interface{}) {
|
2021-06-29 17:02:21 +00:00
|
|
|
// Optionally allow the chain developer to overwrite the SDK's default
|
|
|
|
// server config.
|
|
|
|
srvCfg := config.DefaultConfig()
|
|
|
|
|
|
|
|
// The SDK's default minimum gas price is set to "" (empty value) inside
|
|
|
|
// app.toml. If left empty by validators, the node will halt on startup.
|
|
|
|
// However, the chain developer can set a default app.toml value for their
|
|
|
|
// validators here.
|
|
|
|
//
|
|
|
|
// In summary:
|
|
|
|
// - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their
|
|
|
|
// own app.toml config,
|
|
|
|
// - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their
|
|
|
|
// own app.toml to override, or use this default value.
|
|
|
|
//
|
|
|
|
// In ethermint, we set the min gas prices to 0.
|
2021-07-28 09:47:29 +00:00
|
|
|
if denom != "" {
|
|
|
|
srvCfg.MinGasPrices = "0" + denom
|
|
|
|
}
|
2021-06-29 17:02:21 +00:00
|
|
|
|
|
|
|
customAppConfig := Config{
|
|
|
|
Config: *srvCfg,
|
|
|
|
EVMRPC: *DefaultEVMConfig(),
|
|
|
|
}
|
|
|
|
|
|
|
|
customAppTemplate := config.DefaultConfigTemplate + DefaultConfigTemplate
|
|
|
|
|
|
|
|
return customAppTemplate, customAppConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultConfig returns server's default configuration.
|
|
|
|
func DefaultConfig() *Config {
|
|
|
|
return &Config{
|
|
|
|
Config: *config.DefaultConfig(),
|
|
|
|
EVMRPC: *DefaultEVMConfig(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 16:39:15 +00:00
|
|
|
// EVMRPCConfig defines configuration for the EVM RPC server.
|
|
|
|
type EVMRPCConfig struct {
|
2021-07-23 12:31:59 +00:00
|
|
|
// RPCAddress defines the HTTP server to listen on
|
2021-05-10 16:34:00 +00:00
|
|
|
RPCAddress string `mapstructure:"address"`
|
2021-07-23 12:31:59 +00:00
|
|
|
// WsAddress defines the WebSocket server to listen on
|
2021-04-18 16:39:15 +00:00
|
|
|
WsAddress string `mapstructure:"ws-address"`
|
2021-07-26 11:15:55 +00:00
|
|
|
// API defines a list of JSON-RPC namespaces that should be enabled
|
|
|
|
API []string `mapstructure:"api"`
|
2021-07-23 12:31:59 +00:00
|
|
|
// Enable defines if the EVM RPC server should be enabled.
|
|
|
|
Enable bool `mapstructure:"enable"`
|
|
|
|
// EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk)
|
|
|
|
EnableUnsafeCORS bool `mapstructure:"enable-unsafe-cors"`
|
2021-04-18 16:39:15 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 11:15:55 +00:00
|
|
|
// DefaultEVMConfig returns an EVM config with the JSON-RPC API enabled by default
|
|
|
|
func DefaultEVMConfig() *EVMRPCConfig {
|
|
|
|
return &EVMRPCConfig{
|
2021-07-28 09:47:29 +00:00
|
|
|
Enable: true,
|
|
|
|
API: GetDefaultAPINamespaces(),
|
|
|
|
RPCAddress: DefaultEVMAddress,
|
|
|
|
WsAddress: DefaultEVMWSAddress,
|
|
|
|
EnableUnsafeCORS: false,
|
2021-07-26 11:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
// Config defines the server's top level configuration. It includes the default app config
|
|
|
|
// from the SDK as well as the EVM configuration to enable the JSON-RPC APIs.
|
2021-04-18 16:39:15 +00:00
|
|
|
type Config struct {
|
2021-06-29 17:02:21 +00:00
|
|
|
config.Config
|
2021-06-25 09:18:37 +00:00
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
EVMRPC EVMRPCConfig `mapstructure:"evm-rpc"`
|
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-29 17:02:21 +00:00
|
|
|
Config: cfg,
|
2021-04-18 16:39:15 +00:00
|
|
|
EVMRPC: EVMRPCConfig{
|
2021-07-28 09:47:29 +00:00
|
|
|
Enable: v.GetBool("evm-rpc.enable"),
|
|
|
|
API: v.GetStringSlice("evm-rpc.api"),
|
|
|
|
RPCAddress: v.GetString("evm-rpc.address"),
|
|
|
|
WsAddress: v.GetString("evm-rpc.ws-address"),
|
|
|
|
EnableUnsafeCORS: v.GetBool("evm-rpc.enable-unsafe-cors"),
|
2021-04-18 16:39:15 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|