|
|
@@ -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(ðServ); 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")
|