laconicd/rpc/config.go

34 lines
891 B
Go
Raw Normal View History

package rpc
import (
"strings"
2021-04-17 10:00:07 +00:00
"github.com/gorilla/mux"
"github.com/spf13/viper"
2021-04-17 10:00:07 +00:00
"github.com/cosmos/cosmos-sdk/client"
"github.com/ethereum/go-ethereum/rpc"
)
2021-04-17 10:00:07 +00:00
// RegisterEthereum creates a new ethereum JSON-RPC server and recreates a CLI command to start Cosmos REST server with web3 RPC API and
// Cosmos rest-server endpoints
func RegisterEthereum(clientCtx client.Context, r *mux.Router) {
server := rpc.NewServer()
2021-04-17 10:00:07 +00:00
r.HandleFunc("/", server.ServeHTTP).Methods("POST", "OPTIONS")
rpcapi := viper.GetString(flagRPCAPI)
rpcapi = strings.ReplaceAll(rpcapi, " ", "")
rpcapiArr := strings.Split(rpcapi, ",")
2021-04-17 10:00:07 +00:00
apis := GetAPIs(clientCtx, rpcapiArr)
// Register all the APIs exposed by the namespace services
// TODO: handle allowlist and private APIs
for _, api := range apis {
if err := server.RegisterName(api.Namespace, api.Service); err != nil {
panic(err)
}
}
}