aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-06-12 16:24:24 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-06-20 14:40:26 +0800
commite3ec77f50e7e11c7f38bc87b1981afe9df240a2a (patch)
treedc838ad2a2df25cff20e00ee699e229d4d7e0be1 /cmd
parent2b546660187e8b693b6bbe5ec0fc74bfc008d1d3 (diff)
downloadgo-tangerine-e3ec77f50e7e11c7f38bc87b1981afe9df240a2a.tar
go-tangerine-e3ec77f50e7e11c7f38bc87b1981afe9df240a2a.tar.gz
go-tangerine-e3ec77f50e7e11c7f38bc87b1981afe9df240a2a.tar.bz2
go-tangerine-e3ec77f50e7e11c7f38bc87b1981afe9df240a2a.tar.lz
go-tangerine-e3ec77f50e7e11c7f38bc87b1981afe9df240a2a.tar.xz
go-tangerine-e3ec77f50e7e11c7f38bc87b1981afe9df240a2a.tar.zst
go-tangerine-e3ec77f50e7e11c7f38bc87b1981afe9df240a2a.zip
cmd, graphql, node: graphql flag polishes, les integration
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/config.go9
-rw-r--r--cmd/geth/usage.go13
-rw-r--r--cmd/utils/flags.go90
3 files changed, 67 insertions, 45 deletions
diff --git a/cmd/geth/config.go b/cmd/geth/config.go
index 8f0bae822..3b63d6913 100644
--- a/cmd/geth/config.go
+++ b/cmd/geth/config.go
@@ -30,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/dashboard"
"github.com/ethereum/go-ethereum/eth"
- "github.com/ethereum/go-ethereum/graphql"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
@@ -177,14 +176,10 @@ func makeFullNode(ctx *cli.Context) *node.Node {
}
utils.RegisterShhService(stack, &cfg.Shh)
}
-
- // Configure GraphQL if required
+ // Configure GraphQL if requested
if ctx.GlobalIsSet(utils.GraphQLEnabledFlag.Name) {
- if err := graphql.RegisterGraphQLService(stack, cfg.Node.GraphQLEndpoint(), cfg.Node.GraphQLCors, cfg.Node.GraphQLVirtualHosts, cfg.Node.HTTPTimeouts); err != nil {
- utils.Fatalf("Failed to register the Ethereum service: %v", err)
- }
+ utils.RegisterGraphQLService(stack, cfg.Node.GraphQLEndpoint(), cfg.Node.GraphQLCors, cfg.Node.GraphQLVirtualHosts, cfg.Node.HTTPTimeouts)
}
-
// Add the Ethereum Stats daemon if requested.
if cfg.Ethstats.URL != "" {
utils.RegisterEthStatsService(stack, cfg.Ethstats.URL)
diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go
index 4cc77b912..58a3b87a4 100644
--- a/cmd/geth/usage.go
+++ b/cmd/geth/usage.go
@@ -156,20 +156,25 @@ var AppHelpFlagGroups = []flagGroup{
{
Name: "API AND CONSOLE",
Flags: []cli.Flag{
+ utils.IPCDisabledFlag,
+ utils.IPCPathFlag,
utils.RPCEnabledFlag,
utils.RPCListenAddrFlag,
utils.RPCPortFlag,
utils.RPCApiFlag,
utils.RPCGlobalGasCap,
+ utils.RPCCORSDomainFlag,
+ utils.RPCVirtualHostsFlag,
utils.WSEnabledFlag,
utils.WSListenAddrFlag,
utils.WSPortFlag,
utils.WSApiFlag,
utils.WSAllowedOriginsFlag,
- utils.IPCDisabledFlag,
- utils.IPCPathFlag,
- utils.RPCCORSDomainFlag,
- utils.RPCVirtualHostsFlag,
+ utils.GraphQLEnabledFlag,
+ utils.GraphQLListenAddrFlag,
+ utils.GraphQLPortFlag,
+ utils.GraphQLCORSDomainFlag,
+ utils.GraphQLVirtualHostsFlag,
utils.JSpathFlag,
utils.ExecFlag,
utils.PreloadJSFlag,
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 973e47ea0..8c5a0c99a 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -20,6 +20,7 @@ package utils
import (
"crypto/ecdsa"
"encoding/json"
+ "errors"
"fmt"
"io/ioutil"
"math/big"
@@ -45,6 +46,7 @@ import (
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethstats"
+ "github.com/ethereum/go-ethereum/graphql"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
@@ -57,6 +59,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/p2p/netutil"
"github.com/ethereum/go-ethereum/params"
+ "github.com/ethereum/go-ethereum/rpc"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
pcsclite "github.com/gballet/go-libpcsclite"
cli "gopkg.in/urfave/cli.v1"
@@ -474,6 +477,14 @@ var (
Usage: "Disables db compaction after import",
}
// RPC settings
+ IPCDisabledFlag = cli.BoolFlag{
+ Name: "ipcdisable",
+ Usage: "Disable the IPC-RPC server",
+ }
+ IPCPathFlag = DirectoryFlag{
+ Name: "ipcpath",
+ Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
+ }
RPCEnabledFlag = cli.BoolFlag{
Name: "rpc",
Usage: "Enable the HTTP-RPC server",
@@ -488,30 +499,6 @@ var (
Usage: "HTTP-RPC server listening port",
Value: node.DefaultHTTPPort,
}
- GraphQLEnabledFlag = cli.BoolFlag{
- Name: "graphql",
- Usage: "Enable the GraphQL server",
- }
- GraphQLListenAddrFlag = cli.StringFlag{
- Name: "graphql.addr",
- Usage: "GraphQL server listening interface",
- Value: node.DefaultGraphQLHost,
- }
- GraphQLPortFlag = cli.IntFlag{
- Name: "graphql.port",
- Usage: "GraphQL server listening port",
- Value: node.DefaultGraphQLPort,
- }
- GraphQLCORSDomainFlag = cli.StringFlag{
- Name: "graphql.rpccorsdomain",
- Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
- Value: "",
- }
- GraphQLVirtualHostsFlag = cli.StringFlag{
- Name: "graphql.rpcvhosts",
- Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
- Value: strings.Join(node.DefaultConfig.HTTPVirtualHosts, ","),
- }
RPCCORSDomainFlag = cli.StringFlag{
Name: "rpccorsdomain",
Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
@@ -527,14 +514,6 @@ var (
Usage: "API's offered over the HTTP-RPC interface",
Value: "",
}
- IPCDisabledFlag = cli.BoolFlag{
- Name: "ipcdisable",
- Usage: "Disable the IPC-RPC server",
- }
- IPCPathFlag = DirectoryFlag{
- Name: "ipcpath",
- Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
- }
WSEnabledFlag = cli.BoolFlag{
Name: "ws",
Usage: "Enable the WS-RPC server",
@@ -559,6 +538,30 @@ var (
Usage: "Origins from which to accept websockets requests",
Value: "",
}
+ GraphQLEnabledFlag = cli.BoolFlag{
+ Name: "graphql",
+ Usage: "Enable the GraphQL server",
+ }
+ GraphQLListenAddrFlag = cli.StringFlag{
+ Name: "graphql.addr",
+ Usage: "GraphQL server listening interface",
+ Value: node.DefaultGraphQLHost,
+ }
+ GraphQLPortFlag = cli.IntFlag{
+ Name: "graphql.port",
+ Usage: "GraphQL server listening port",
+ Value: node.DefaultGraphQLPort,
+ }
+ GraphQLCORSDomainFlag = cli.StringFlag{
+ Name: "graphql.corsdomain",
+ Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
+ Value: "",
+ }
+ GraphQLVirtualHostsFlag = cli.StringFlag{
+ Name: "graphql.vhosts",
+ Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
+ Value: strings.Join(node.DefaultConfig.GraphQLVirtualHosts, ","),
+ }
ExecFlag = cli.StringFlag{
Name: "exec",
Usage: "Execute JavaScript statement",
@@ -874,7 +877,6 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
cfg.HTTPHost = ctx.GlobalString(RPCListenAddrFlag.Name)
}
}
-
if ctx.GlobalIsSet(RPCPortFlag.Name) {
cfg.HTTPPort = ctx.GlobalInt(RPCPortFlag.Name)
}
@@ -916,7 +918,6 @@ func setWS(ctx *cli.Context, cfg *node.Config) {
cfg.WSHost = ctx.GlobalString(WSListenAddrFlag.Name)
}
}
-
if ctx.GlobalIsSet(WSPortFlag.Name) {
cfg.WSPort = ctx.GlobalInt(WSPortFlag.Name)
}
@@ -1546,12 +1547,33 @@ func RegisterEthStatsService(stack *node.Node, url string) {
var lesServ *les.LightEthereum
ctx.Service(&lesServ)
+ // Let ethstats use whichever is not nil
return ethstats.New(url, ethServ, lesServ)
}); err != nil {
Fatalf("Failed to register the Ethereum Stats service: %v", err)
}
}
+// RegisterGraphQLService is a utility function to construct a new service and register it against a node.
+func RegisterGraphQLService(stack *node.Node, endpoint string, cors, vhosts []string, timeouts rpc.HTTPTimeouts) {
+ if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
+ // Try to construct the GraphQL service backed by a full node
+ var ethServ *eth.Ethereum
+ if err := ctx.Service(&ethServ); err == nil {
+ return graphql.New(ethServ.APIBackend, endpoint, cors, vhosts, timeouts)
+ }
+ // Try to construct the GraphQL service backed by a light node
+ var lesServ *les.LightEthereum
+ if err := ctx.Service(&lesServ); err == nil {
+ return graphql.New(lesServ.ApiBackend, endpoint, cors, vhosts, timeouts)
+ }
+ // Well, this should not have happened, bail out
+ return nil, errors.New("no Ethereum service")
+ }); err != nil {
+ Fatalf("Failed to register the GraphQL service: %v", err)
+ }
+}
+
func SetupMetrics(ctx *cli.Context) {
if metrics.Enabled {
log.Info("Enabling metrics collection")