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 From 4023ae20cb2b7cd228a68670bc55a6c9cdbabc36 Mon Sep 17 00:00:00 2001 From: StephenButtolph Date: Wed, 28 Oct 2020 17:47:15 -0400 Subject: fixed api.Json.* --- plugin/evm/service.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/service.go b/plugin/evm/service.go index 148a3c3..f1c30c5 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -109,7 +109,7 @@ type ImportKeyArgs struct { } // ImportKey adds a private key to the provided user -func (service *AvaxAPI) ImportKey(r *http.Request, args *ImportKeyArgs, reply *api.JsonAddress) error { +func (service *AvaxAPI) ImportKey(r *http.Request, args *ImportKeyArgs, reply *api.JSONAddress) error { log.Info(fmt.Sprintf("EVM: ImportKey called for user '%s'", args.Username)) if !strings.HasPrefix(args.PrivateKey, constants.SecretKeyPrefix) { @@ -157,13 +157,13 @@ type ImportArgs struct { } // ImportAVAX is a deprecated name for Import. -func (service *AvaxAPI) ImportAVAX(_ *http.Request, args *ImportArgs, response *api.JsonTxID) error { +func (service *AvaxAPI) ImportAVAX(_ *http.Request, args *ImportArgs, response *api.JSONTxID) error { return service.Import(nil, args, response) } // Import issues a transaction to import AVAX from the X-chain. The AVAX // must have already been exported from the X-Chain. -func (service *AvaxAPI) Import(_ *http.Request, args *ImportArgs, response *api.JsonTxID) error { +func (service *AvaxAPI) Import(_ *http.Request, args *ImportArgs, response *api.JSONTxID) error { log.Info("EVM: ImportAVAX called") chainID, err := service.vm.ctx.BCLookup.Lookup(args.SourceChain) @@ -214,7 +214,7 @@ type ExportAVAXArgs struct { // ExportAVAX exports AVAX from the C-Chain to the X-Chain // It must be imported on the X-Chain to complete the transfer -func (service *AvaxAPI) ExportAVAX(_ *http.Request, args *ExportAVAXArgs, response *api.JsonTxID) error { +func (service *AvaxAPI) ExportAVAX(_ *http.Request, args *ExportAVAXArgs, response *api.JSONTxID) error { return service.Export(nil, &ExportArgs{ ExportAVAXArgs: *args, AssetID: service.vm.ctx.AVAXAssetID, @@ -230,7 +230,7 @@ type ExportArgs struct { // Export exports an asset from the C-Chain to the X-Chain // It must be imported on the X-Chain to complete the transfer -func (service *AvaxAPI) Export(_ *http.Request, args *ExportArgs, response *api.JsonTxID) error { +func (service *AvaxAPI) Export(_ *http.Request, args *ExportArgs, response *api.JSONTxID) error { log.Info("EVM: Export called") if args.AssetID.IsZero() { return fmt.Errorf("assetID is required") -- cgit v1.2.3 From 4862c2d3a6c18855fee72137db54ed62a0ce6704 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Fri, 30 Oct 2020 11:33:41 -0400 Subject: Add back net API --- plugin/evm/config.go | 1 + plugin/evm/service.go | 12 ++++++++++++ plugin/evm/vm.go | 4 ++++ 3 files changed, 17 insertions(+) (limited to 'plugin/evm') diff --git a/plugin/evm/config.go b/plugin/evm/config.go index c38a798..4d6650a 100644 --- a/plugin/evm/config.go +++ b/plugin/evm/config.go @@ -5,6 +5,7 @@ type CommandLineConfig struct { // Coreth APIs SnowmanAPIEnabled bool `json:"snowman-api-enabled"` CorethAdminAPIEnabled bool `json:"coreth-admin-api-enabled"` + NetAPIEnabled bool `json:"net-api-enabled"` // Coreth API Gas/Price Caps RPCGasCap uint64 `json:"rpc-gas-cap"` diff --git a/plugin/evm/service.go b/plugin/evm/service.go index f1c30c5..a934941 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -38,6 +38,18 @@ type SnowmanAPI struct{ vm *VM } // AvaxAPI offers Avalanche network related API methods type AvaxAPI struct{ vm *VM } +// NetAPI offers network related API methods +type NetAPI struct{ vm *VM } + +// Listening returns an indication if the node is listening for network connections. +func (s *NetAPI) Listening() bool { return true } // always listening + +// PeerCount returns the number of connected peers +func (s *NetAPI) PeerCount() hexutil.Uint { return hexutil.Uint(0) } // TODO: report number of connected peers + +// Version returns the current ethereum protocol version. +func (s *NetAPI) Version() string { return fmt.Sprintf("%d", s.vm.networkID) } + // GetAcceptedFrontReply defines the reply that will be sent from the // GetAcceptedFront API call type GetAcceptedFrontReply struct { diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 1f7e501..c902f85 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -530,6 +530,10 @@ func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler { handler.RegisterName("admin", &admin.Performance{}) enabledAPIs = append(enabledAPIs, "coreth-admin") } + if vm.CLIConfig.NetAPIEnabled { + handler.RegisterName("net", &NetAPI{vm}) + enabledAPIs = append(enabledAPIs, "net") + } log.Info(fmt.Sprintf("Enabled APIs: %s", strings.Join(enabledAPIs, ", "))) -- cgit v1.2.3