From 28ccbeb7de18212954310588994058874fb180af Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Tue, 27 Oct 2020 14:04:01 -0400 Subject: Parse config to set enabled APIs --- plugin/evm/config.go | 19 ++++++++++--------- plugin/evm/service.go | 13 +++---------- plugin/evm/vm.go | 13 ++++++++++--- 3 files changed, 23 insertions(+), 22 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/config.go b/plugin/evm/config.go index 4669807..c38a798 100644 --- a/plugin/evm/config.go +++ b/plugin/evm/config.go @@ -3,19 +3,20 @@ package evm // CommandLineConfig ... type CommandLineConfig struct { // Coreth APIs - SnowmanAPIEnabled bool `json:"snowmanAPIEnabled"` - Web3APIEnabled bool `json:"web3APIEnabled"` - CorethAdminAPIEnabled bool `json:"corethAdminAPIEnabled"` + SnowmanAPIEnabled bool `json:"snowman-api-enabled"` + CorethAdminAPIEnabled bool `json:"coreth-admin-api-enabled"` // Coreth API Gas/Price Caps - RPCGasCap uint64 `json:"rpcGasCap"` - RPCTxFeeCap float64 `json:"rpcTxFeeCap"` + RPCGasCap uint64 `json:"rpc-gas-cap"` + RPCTxFeeCap float64 `json:"rpc-tx-fee-cap"` // Eth APIs - EthAPIEnabled bool `json:"ethAPIEnabled"` - PersonalAPIEnabled bool `json:"personalAPIEnabled"` - TxPoolAPIEnabled bool `json:"txPoolAPIEnabled"` - DebugAPIEnabled bool `json:"debugAPIEnabled"` + EthAPIEnabled bool `json:"eth-api-enabled"` + PersonalAPIEnabled bool `json:"personal-api-enabled"` + TxPoolAPIEnabled bool `json:"tx-pool-api-enabled"` + DebugAPIEnabled bool `json:"debug-api-enabled"` + + ParsingError error } // EthAPIs returns an array of strings representing the Eth APIs that should be enabled diff --git a/plugin/evm/service.go b/plugin/evm/service.go index 128b98e..148a3c3 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -19,7 +19,6 @@ import ( "github.com/ava-labs/avalanchego/utils/json" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" ) @@ -39,15 +38,6 @@ type SnowmanAPI struct{ vm *VM } // AvaxAPI offers Avalanche network related API methods type AvaxAPI struct{ vm *VM } -// Web3API offers helper API methods -type Web3API struct{} - -// ClientVersion returns the version of the vm running -func (s *Web3API) ClientVersion() string { return version } - -// Sha3 returns the bytes returned by hashing [input] with Keccak256 -func (s *Web3API) Sha3(input hexutil.Bytes) hexutil.Bytes { return ethcrypto.Keccak256(input) } - // GetAcceptedFrontReply defines the reply that will be sent from the // GetAcceptedFront API call type GetAcceptedFrontReply struct { @@ -71,6 +61,9 @@ func (api *SnowmanAPI) IssueBlock(ctx context.Context) error { return api.vm.tryBlockGen() } +// ClientVersion returns the version of the vm running +func (service *AvaxAPI) ClientVersion() string { return version } + // ExportKeyArgs are arguments for ExportKey type ExportKeyArgs struct { api.UserPass diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c429bca..1f7e501 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -10,6 +10,7 @@ import ( "errors" "fmt" "math/big" + "strings" "sync" "sync/atomic" "time" @@ -231,6 +232,10 @@ func (vm *VM) Initialize( toEngine chan<- commonEng.Message, fxs []*commonEng.Fx, ) error { + if vm.CLIConfig.ParsingError != nil { + return vm.CLIConfig.ParsingError + } + if len(fxs) > 0 { return errUnsupportedFXs } @@ -514,18 +519,20 @@ func newHandler(name string, service interface{}, lockOption ...commonEng.LockOp // CreateHandlers makes new http handlers that can handle API calls func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler { handler := vm.chain.NewRPCHandler() + enabledAPIs := vm.CLIConfig.EthAPIs() vm.chain.AttachEthService(handler, vm.CLIConfig.EthAPIs()) if vm.CLIConfig.SnowmanAPIEnabled { handler.RegisterName("snowman", &SnowmanAPI{vm}) - } - if vm.CLIConfig.Web3APIEnabled { - handler.RegisterName("web3", &Web3API{}) + enabledAPIs = append(enabledAPIs, "snowman") } if vm.CLIConfig.CorethAdminAPIEnabled { handler.RegisterName("admin", &admin.Performance{}) + enabledAPIs = append(enabledAPIs, "coreth-admin") } + log.Info(fmt.Sprintf("Enabled APIs: %s", strings.Join(enabledAPIs, ", "))) + return map[string]*commonEng.HTTPHandler{ "/rpc": {LockOptions: commonEng.NoLock, Handler: handler}, "/avax": newHandler("avax", &AvaxAPI{vm}), -- cgit v1.2.3-70-g09d2