laconicd-deprecated/rpc/rpc.go
David Ansermino 284c2a0333
Enable RPC Server (#75)
- 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
2019-07-15 10:13:59 -04:00

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
}