From 31cbaec567bf82dd89b9c626dd32923406218dae Mon Sep 17 00:00:00 2001 From: ramil Date: Fri, 16 Apr 2021 16:56:02 +0300 Subject: [PATCH] fix serve command for ipld graphql server --- cmd/serve.go | 16 +++++++++------- pkg/serve/config.go | 5 ++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index 760b53cb..8c8881f8 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -164,14 +164,18 @@ func startIpldGraphQL(settings *s.Config) error { return err } - ethClients, err := parseRpcAddresses(viper.GetString("ethereum.httpPath")) + ethClients, err := parseRpcAddresses(settings.EthHttpEndpoint) if err != nil { return err } - tracingClients, err := parseRpcAddresses(viper.GetString("tracing.httpPath")) - if err != nil { - return err + var tracingClients []*rpc.Client + tracingEndpoint := viper.GetString("tracing.httpPath") + if tracingEndpoint != "" { + tracingClients, err = parseRpcAddresses(tracingEndpoint) + if err != nil { + return err + } } router, err := mux.NewServeMux(&mux.Options{ @@ -190,9 +194,7 @@ func startIpldGraphQL(settings *s.Config) error { return err } - if err := http.ListenAndServe(settings.IpldGraphqlEndpoint, router); err != nil { - logWithCommand.Fatal(err) - } + go http.ListenAndServe(settings.IpldGraphqlEndpoint, router) } else { logWithCommand.Info("IPLD GraphQL server is disabled") } diff --git a/pkg/serve/config.go b/pkg/serve/config.go index e69b4ade..772bb834 100644 --- a/pkg/serve/config.go +++ b/pkg/serve/config.go @@ -79,6 +79,7 @@ type Config struct { ChainConfig *params.ChainConfig DefaultSender *common.Address RPCGasCap *big.Int + EthHttpEndpoint string Client *rpc.Client SupportStateDiff bool } @@ -97,12 +98,14 @@ func NewConfig() (*Config, error) { c.DBConfig.Init() ethHTTP := viper.GetString("ethereum.httpPath") - nodeInfo, cli, err := shared.GetEthNodeAndClient(fmt.Sprintf("http://%s", ethHTTP)) + ethHTTPEndpoint := fmt.Sprintf("http://%s", ethHTTP) + nodeInfo, cli, err := shared.GetEthNodeAndClient(ethHTTPEndpoint) if err != nil { return nil, err } c.Client = cli c.SupportStateDiff = viper.GetBool("ethereum.supportsStateDiff") + c.EthHttpEndpoint = ethHTTPEndpoint // websocket server wsEnabled := viper.GetBool("eth.server.ws")