|
|
|
@ -53,6 +53,7 @@ var ( |
|
|
|
|
wsListener net.Listener |
|
|
|
|
wsHandler *rpc.Server |
|
|
|
|
httpEndpoint = "" |
|
|
|
|
httpAuthEndpoint = "" |
|
|
|
|
wsEndpoint = "" |
|
|
|
|
httpVirtualHosts = []string{"*"} |
|
|
|
|
httpTimeouts = rpc.DefaultHTTPTimeouts |
|
|
|
@ -71,12 +72,18 @@ func (n Version) Namespace() string { |
|
|
|
|
// StartServers starts the http & ws servers
|
|
|
|
|
func StartServers(hmy *hmy.Harmony, apis []rpc.API, config nodeconfig.RPCServerConfig) error { |
|
|
|
|
apis = append(apis, getAPIs(hmy, config.DebugEnabled, config.RateLimiterEnabled, config.RequestsPerSecond)...) |
|
|
|
|
authApis := getAuthAPIs(hmy, config.DebugEnabled, config.RateLimiterEnabled, config.RequestsPerSecond) |
|
|
|
|
|
|
|
|
|
if config.HTTPEnabled { |
|
|
|
|
httpEndpoint = fmt.Sprintf("%v:%v", config.HTTPIp, config.HTTPPort) |
|
|
|
|
if err := startHTTP(apis); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
httpAuthEndpoint = fmt.Sprintf("%v:%v", config.HTTPIp, config.HTTPAuthPort) |
|
|
|
|
if err := startAuthHTTP(authApis); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if config.WSEnabled { |
|
|
|
@ -120,6 +127,13 @@ func StopServers() error { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getAuthAPIs(hmy *hmy.Harmony, debugEnable bool, rateLimiterEnable bool, ratelimit int) []rpc.API { |
|
|
|
|
return []rpc.API{ |
|
|
|
|
NewPublicTraceAPI(hmy, Debug), // Debug version means geth trace rpc
|
|
|
|
|
NewPublicTraceAPI(hmy, Trace), // Trace version means parity trace rpc
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// getAPIs returns all the API methods for the RPC interface
|
|
|
|
|
func getAPIs(hmy *hmy.Harmony, debugEnable bool, rateLimiterEnable bool, ratelimit int) []rpc.API { |
|
|
|
|
publicAPIs := []rpc.API{ |
|
|
|
@ -141,10 +155,10 @@ func getAPIs(hmy *hmy.Harmony, debugEnable bool, rateLimiterEnable bool, ratelim |
|
|
|
|
NewPublicPoolAPI(hmy, Eth), |
|
|
|
|
NewPublicStakingAPI(hmy, V1), |
|
|
|
|
NewPublicStakingAPI(hmy, V2), |
|
|
|
|
NewPublicTraceAPI(hmy, Debug), // Debug version means geth trace rpc
|
|
|
|
|
NewPublicTraceAPI(hmy, Trace), // Trace version means parity trace rpc
|
|
|
|
|
NewPublicDebugAPI(hmy, V1), |
|
|
|
|
NewPublicDebugAPI(hmy, V2), |
|
|
|
|
NewPublicTraceAPI(hmy, Debug), // Debug version means geth trace rpc
|
|
|
|
|
NewPublicTraceAPI(hmy, Trace), // Trace version means parity trace rpc
|
|
|
|
|
// Legacy methods (subject to removal)
|
|
|
|
|
v1.NewPublicLegacyAPI(hmy, "hmy"), |
|
|
|
|
eth.NewPublicEthService(hmy, "eth"), |
|
|
|
@ -179,6 +193,23 @@ func startHTTP(apis []rpc.API) (err error) { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func startAuthHTTP(apis []rpc.API) (err error) { |
|
|
|
|
httpListener, httpHandler, err = rpc.StartHTTPEndpoint( |
|
|
|
|
httpAuthEndpoint, apis, HTTPModules, httpOrigins, httpVirtualHosts, httpTimeouts, |
|
|
|
|
) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
utils.Logger().Info(). |
|
|
|
|
Str("url", fmt.Sprintf("http://%s", httpAuthEndpoint)). |
|
|
|
|
Str("cors", strings.Join(httpOrigins, ",")). |
|
|
|
|
Str("vhosts", strings.Join(httpVirtualHosts, ",")). |
|
|
|
|
Msg("HTTP endpoint opened") |
|
|
|
|
fmt.Printf("Started Auth-RPC server at: %v\n", httpAuthEndpoint) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func startWS(apis []rpc.API) (err error) { |
|
|
|
|
wsListener, wsHandler, err = rpc.StartWSEndpoint(wsEndpoint, apis, WSModules, wsOrigins, true) |
|
|
|
|
if err != nil { |
|
|
|
|