aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Buchwald <aaron.buchwald56@gmail.com>2020-10-27 14:04:01 -0400
committerAaron Buchwald <aaron.buchwald56@gmail.com>2020-10-27 15:52:20 -0400
commit28ccbeb7de18212954310588994058874fb180af (patch)
tree4bca4f77f74b31cc7948832ed45dd6b5a4bc8ef7
parent806d04e9aa4b6e22fc2a484ada6fecb0c9a348e3 (diff)
Parse config to set enabled APIsv0.3.8
-rw-r--r--plugin/evm/config.go19
-rw-r--r--plugin/evm/service.go13
-rw-r--r--plugin/evm/vm.go13
-rw-r--r--plugin/main.go5
-rw-r--r--plugin/params.go16
-rwxr-xr-xscripts/build_coreth.sh22
6 files changed, 50 insertions, 38 deletions
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}),
diff --git a/plugin/main.go b/plugin/main.go
index b42ba14..9c0a28a 100644
--- a/plugin/main.go
+++ b/plugin/main.go
@@ -1,8 +1,6 @@
package main
import (
- "fmt"
-
"github.com/hashicorp/go-plugin"
"github.com/ava-labs/avalanchego/vms/rpcchainvm"
@@ -11,9 +9,6 @@ import (
)
func main() {
- if errs.Errored() {
- panic(fmt.Sprintf("Errored while parsing Coreth CLI Config: %w", errs.Err))
- }
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: rpcchainvm.Handshake,
Plugins: map[string]plugin.Plugin{
diff --git a/plugin/params.go b/plugin/params.go
index 1810295..d780d00 100644
--- a/plugin/params.go
+++ b/plugin/params.go
@@ -5,37 +5,31 @@ import (
"flag"
"os"
- "github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/coreth/plugin/evm"
)
-const (
- name = "coreth"
-)
-
var (
cliConfig evm.CommandLineConfig
- errs wrappers.Errs
)
func init() {
- errs := wrappers.Errs{}
- fs := flag.NewFlagSet(name, flag.ContinueOnError)
+ fs := flag.NewFlagSet("coreth", flag.ContinueOnError)
- config := fs.String("coreth-config", "default", "Pass in CLI Config to set runtime attributes for Coreth")
+ config := fs.String("config", "default", "Pass in CLI Config to set runtime attributes for Coreth")
if err := fs.Parse(os.Args[1:]); err != nil {
- errs.Add(err)
+ cliConfig.ParsingError = err
return
}
if *config == "default" {
cliConfig.EthAPIEnabled = true
+ cliConfig.PersonalAPIEnabled = true
cliConfig.TxPoolAPIEnabled = true
cliConfig.RPCGasCap = 2500000000 // 25000000 x 100
cliConfig.RPCTxFeeCap = 100 // 100 AVAX
} else {
// TODO only overwrite values that were explicitly set
- errs.Add(json.Unmarshal([]byte(*config), &cliConfig))
+ cliConfig.ParsingError = json.Unmarshal([]byte(*config), &cliConfig)
}
}
diff --git a/scripts/build_coreth.sh b/scripts/build_coreth.sh
new file mode 100755
index 0000000..41fab1b
--- /dev/null
+++ b/scripts/build_coreth.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+# Set GOPATH
+GOPATH="$(go env GOPATH)"
+
+# Set default binary location
+BINARY_PATH="$GOPATH/src/github.com/ava-labs/avalanchego/build/plugins/evm"
+
+if [[ $# -eq 1 ]]; then
+ BINARY_PATH=$1
+elif [[ $# -ne 0 ]]; then
+ echo "Invalid arguments to build coreth. Requires either no arguments (default) or one arguments to specify binary location."
+ exit 1
+fi
+
+# Build Coreth, which is run as a subprocess
+echo "Building Coreth..."
+go build -o "$BINARY_PATH" "plugin/"*.go