forked from cerc-io/laconicd-deprecated
feat: import ethermint without forking (#378)
* cmd: cleanup * update gh action * lint * more cleanup * update config * register denom
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/server/config"
|
||||
"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.
|
||||
DefaultEVMAddress = "0.0.0.0:8545"
|
||||
|
||||
// DefaultEVMWSAddress is the default address the EVM WebSocket server binds to.
|
||||
DefaultEVMWSAddress = "0.0.0.0:8546"
|
||||
)
|
||||
|
||||
// GetDefaultAPINamespaces returns the default list of JSON-RPC namespaces that should be enabled
|
||||
func GetDefaultAPINamespaces() []string {
|
||||
return []string{"eth"}
|
||||
}
|
||||
|
||||
// AppConfig helps to override default appConfig template and configs.
|
||||
// return "", nil if no custom configuration is required for the application.
|
||||
func AppConfig(denom string) (string, interface{}) {
|
||||
// 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.
|
||||
if denom != "" {
|
||||
srvCfg.MinGasPrices = "0" + denom
|
||||
}
|
||||
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
||||
// EVMRPCConfig defines configuration for the EVM RPC server.
|
||||
type EVMRPCConfig struct {
|
||||
// RPCAddress defines the HTTP server to listen on
|
||||
RPCAddress string `mapstructure:"address"`
|
||||
// WsAddress defines the WebSocket server to listen on
|
||||
WsAddress string `mapstructure:"ws-address"`
|
||||
// API defines a list of JSON-RPC namespaces that should be enabled
|
||||
API []string `mapstructure:"api"`
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// DefaultEVMConfig returns an EVM config with the JSON-RPC API enabled by default
|
||||
func DefaultEVMConfig() *EVMRPCConfig {
|
||||
return &EVMRPCConfig{
|
||||
Enable: true,
|
||||
API: GetDefaultAPINamespaces(),
|
||||
RPCAddress: DefaultEVMAddress,
|
||||
WsAddress: DefaultEVMWSAddress,
|
||||
EnableUnsafeCORS: false,
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
type Config struct {
|
||||
config.Config
|
||||
|
||||
EVMRPC EVMRPCConfig `mapstructure:"evm-rpc"`
|
||||
}
|
||||
|
||||
// GetConfig returns a fully parsed Config object.
|
||||
func GetConfig(v *viper.Viper) Config {
|
||||
cfg := config.GetConfig(v)
|
||||
|
||||
return Config{
|
||||
Config: cfg,
|
||||
EVMRPC: EVMRPCConfig{
|
||||
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"),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDefaultConfig(t *testing.T) {
|
||||
cfg := DefaultEVMConfig()
|
||||
require.True(t, cfg.Enable)
|
||||
require.Equal(t, cfg.RPCAddress, DefaultEVMAddress)
|
||||
require.Equal(t, cfg.WsAddress, DefaultEVMWSAddress)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package config
|
||||
|
||||
// DefaultConfigTemplate defines the configuration template for the EVM RPC configuration
|
||||
const DefaultConfigTemplate = `
|
||||
###############################################################################
|
||||
### EVM RPC Configuration ###
|
||||
###############################################################################
|
||||
|
||||
[evm-rpc]
|
||||
|
||||
# Enable defines if the gRPC server should be enabled.
|
||||
enable = {{ .EVMRPC.Enable }}
|
||||
|
||||
# Address defines the EVM RPC HTTP server address to bind to.
|
||||
address = "{{ .EVMRPC.RPCAddress }}"
|
||||
|
||||
# Address defines the EVM WebSocket server address to bind to.
|
||||
ws-address = "{{ .EVMRPC.WsAddress }}"
|
||||
|
||||
# API defines a list of JSON-RPC namespaces that should be enabled
|
||||
api = "{{ .EVMRPC.API }}"
|
||||
|
||||
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk)
|
||||
enable-unsafe-cors = "{{ .EVMRPC.EnableUnsafeCORS }}"
|
||||
`
|
||||
+2
-1
@@ -12,8 +12,9 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/cosmos/cosmos-sdk/server/types"
|
||||
ethrpc "github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/tharsis/ethermint/cmd/ethermintd/config"
|
||||
"github.com/tharsis/ethermint/ethereum/rpc"
|
||||
|
||||
"github.com/tharsis/ethermint/server/config"
|
||||
)
|
||||
|
||||
// StartEVMRPC start evm rpc server
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// AddTxFlags adds common flags for commands to post tx
|
||||
func AddTxFlags(cmd *cobra.Command) *cobra.Command {
|
||||
cmd.PersistentFlags().String(flags.FlagChainID, "testnet", "Specify Chain ID for sending Tx")
|
||||
cmd.PersistentFlags().String(flags.FlagFrom, "", "Name or address of private key with which to sign")
|
||||
cmd.PersistentFlags().String(flags.FlagFees, "", "Fees to pay along with transaction; eg: 10aphoton")
|
||||
cmd.PersistentFlags().String(flags.FlagGasPrices, "", "Gas prices to determine the transaction fee (e.g. 10aphoton)")
|
||||
cmd.PersistentFlags().String(flags.FlagNode, "tcp://localhost:26657", "<host>:<port> to tendermint rpc interface for this chain")
|
||||
cmd.PersistentFlags().Float64(flags.FlagGasAdjustment, flags.DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ")
|
||||
cmd.PersistentFlags().StringP(flags.FlagBroadcastMode, "b", flags.BroadcastSync, "Transaction broadcasting mode (sync|async|block)")
|
||||
cmd.PersistentFlags().String(flags.FlagKeyringBackend, keyring.BackendFile, "Select keyring's backend")
|
||||
|
||||
// --gas can accept integers and "simulate"
|
||||
// cmd.PersistentFlags().Var(&flags.GasFlagVar, "gas", fmt.Sprintf(
|
||||
// "gas limit to set per-transaction; set to %q to calculate required gas automatically (default %d)",
|
||||
// flags.GasFlagAuto, flags.DefaultGasLimit,
|
||||
// ))
|
||||
|
||||
// viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
|
||||
|
||||
// TODO: we need to handle the errors for these, decide if we should return error upward and handle
|
||||
// nolint: errcheck
|
||||
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
|
||||
// nolint: errcheck
|
||||
viper.BindPFlag(flags.FlagKeyringBackend, cmd.Flags().Lookup(flags.FlagKeyringBackend))
|
||||
// nolint: errcheck
|
||||
cmd.MarkFlagRequired(flags.FlagChainID)
|
||||
return cmd
|
||||
}
|
||||
+1
-1
@@ -40,8 +40,8 @@ import (
|
||||
|
||||
ethlog "github.com/ethereum/go-ethereum/log"
|
||||
|
||||
"github.com/tharsis/ethermint/cmd/ethermintd/config"
|
||||
ethdebug "github.com/tharsis/ethermint/ethereum/rpc/namespaces/debug"
|
||||
"github.com/tharsis/ethermint/server/config"
|
||||
)
|
||||
|
||||
// Tendermint full-node start flags
|
||||
|
||||
Reference in New Issue
Block a user