forked from cerc-io/laconicd-deprecated
284c2a0333
- Introduces rpc command to cli (rest-server) - Moves server/rpc to rpc/ - Enables module selection (eg. "web3" or "eth" or "web3,eth"), however there is no CLI flag to configure these (See #74) - Adds CLI context to eth API
39 lines
960 B
Go
39 lines
960 B
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
)
|
|
|
|
// StartHTTPEndpoint starts the Tendermint Web3-compatible RPC layer. Consumes
|
|
// a Context for cancellation, a config struct, and a list of rpc.API interfaces
|
|
// that will be automatically wired into a JSON-RPC webserver.
|
|
func StartHTTPEndpoint(ctx context.Context, config *Config, apis []rpc.API, timeouts rpc.HTTPTimeouts) (*rpc.Server, error) {
|
|
uniqModules := make(map[string]string)
|
|
for _, api := range apis {
|
|
uniqModules[api.Namespace] = api.Namespace
|
|
}
|
|
|
|
modules := make([]string, len(uniqModules))
|
|
i := 0
|
|
for k := range uniqModules {
|
|
modules[i] = k
|
|
i++
|
|
}
|
|
|
|
endpoint := fmt.Sprintf("%s:%d", config.RPCAddr, config.RPCPort)
|
|
_, server, err := rpc.StartHTTPEndpoint(
|
|
endpoint, apis, modules, config.RPCCORSDomains, config.RPCVHosts, timeouts,
|
|
)
|
|
|
|
go func() {
|
|
<-ctx.Done()
|
|
fmt.Println("Shutting down server.")
|
|
server.Stop()
|
|
}()
|
|
|
|
return server, err
|
|
}
|