support custom chain config #36
@ -137,6 +137,7 @@ func init() {
|
||||
serveCmd.PersistentFlags().String("eth-chain-id", "1", "eth chain id")
|
||||
serveCmd.PersistentFlags().String("eth-default-sender", "", "default sender address")
|
||||
serveCmd.PersistentFlags().String("eth-rpc-gas-cap", "", "rpc gas cap (for eth_Call execution)")
|
||||
serveCmd.PersistentFlags().String("eth-chain-config", "", "json chain config file location")
|
||||
|
||||
// and their bindings
|
||||
viper.BindPFlag("server.graphql", serveCmd.PersistentFlags().Lookup("server-graphql"))
|
||||
@ -153,4 +154,5 @@ func init() {
|
||||
viper.BindPFlag("ethereum.chainID", serveCmd.PersistentFlags().Lookup("eth-chain-id"))
|
||||
viper.BindPFlag("ethereum.defaultSender", serveCmd.PersistentFlags().Lookup("eth-default-sender"))
|
||||
viper.BindPFlag("ethereum.rpcGasCap", serveCmd.PersistentFlags().Lookup("eth-rpc-gas-cap"))
|
||||
viper.BindPFlag("ethereum.chainConfig", serveCmd.PersistentFlags().Lookup("eth-chain-config"))
|
||||
}
|
||||
|
@ -17,7 +17,11 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os"
|
||||
|
||||
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
|
||||
|
||||
@ -40,7 +44,28 @@ func ResolveToNodeType(nodeType int) sdtypes.NodeType {
|
||||
}
|
||||
|
||||
// ChainConfig returns the appropriate ethereum chain config for the provided chain id
|
||||
func ChainConfig(chainID uint64) (*params.ChainConfig, error) {
|
||||
func ChainConfig(chainID uint64, chainConfigPath string) (*params.ChainConfig, error) {
|
||||
if chainConfigPath != "" {
|
||||
file, err := os.Open(chainConfigPath)
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to read chain config file: %v", err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
chainConfig := new(params.ChainConfig)
|
||||
if err := json.NewDecoder(file).Decode(chainConfig); err != nil {
|
||||
utils.Fatalf("invalid chain config file: %v", err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Infof("Using chain config from %s file. Content %+v", chainConfigPath, chainConfig)
|
||||
|
||||
return chainConfig, nil
|
||||
}
|
||||
|
||||
switch chainID {
|
||||
case 1:
|
||||
return params.MainnetChainConfig, nil
|
||||
|
@ -48,6 +48,7 @@ const (
|
||||
|
||||
ETH_DEFAULT_SENDER_ADDR = "ETH_DEFAULT_SENDER_ADDR"
|
||||
ETH_RPC_GAS_CAP = "ETH_RPC_GAS_CAP"
|
||||
ETH_CHAIN_CONFIG = "ETH_CHAIN_CONFIG"
|
||||
ETH_SUPPORTS_STATEDIFF = "ETH_SUPPORTS_STATEDIFF"
|
||||
)
|
||||
|
||||
@ -76,6 +77,7 @@ func NewConfig() (*Config, error) {
|
||||
viper.BindEnv("ethereum.httpPath", shared.ETH_HTTP_PATH)
|
||||
viper.BindEnv("ethereum.defaultSender", ETH_DEFAULT_SENDER_ADDR)
|
||||
viper.BindEnv("ethereum.rpcGasCap", ETH_RPC_GAS_CAP)
|
||||
viper.BindEnv("ethereum.chainConfig", ETH_CHAIN_CONFIG)
|
||||
viper.BindEnv("ethereum.supportsStateDiff", ETH_SUPPORTS_STATEDIFF)
|
||||
|
||||
c.DBConfig.Init()
|
||||
@ -123,7 +125,7 @@ func NewConfig() (*Config, error) {
|
||||
c.RPCGasCap = rpcGasCap
|
||||
}
|
||||
}
|
||||
c.ChainConfig, err = eth.ChainConfig(nodeInfo.ChainID)
|
||||
c.ChainConfig, err = eth.ChainConfig(nodeInfo.ChainID, viper.GetString("ethereum.chainConfig"))
|
||||
return c, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user