diff --git a/cmd/emintcli/main.go b/cmd/emintcli/main.go index 1795cbf4..576e077a 100644 --- a/cmd/emintcli/main.go +++ b/cmd/emintcli/main.go @@ -60,8 +60,7 @@ func main() { client.ConfigCmd(emintapp.DefaultCLIHome), queryCmd(cdc), txCmd(cdc), - // TODO: Set up rest routes (if included, different from web3 api) - rpc.Web3RpcCmd(cdc), + rpc.EmintServeCmd(cdc), client.LineBreak, keyCommands(), client.LineBreak, diff --git a/rpc/config.go b/rpc/config.go index c060d472..a13c543d 100644 --- a/rpc/config.go +++ b/rpc/config.go @@ -5,11 +5,14 @@ import ( "fmt" "os" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/input" emintkeys "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/lcd" "github.com/cosmos/cosmos-sdk/codec" + authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" + "github.com/cosmos/ethermint/app" emintcrypto "github.com/cosmos/ethermint/crypto" "github.com/ethereum/go-ethereum/rpc" @@ -36,8 +39,9 @@ type Config struct { RPCVHosts []string } -// Web3RpcCmd creates a CLI command to start RPC server -func Web3RpcCmd(cdc *codec.Codec) *cobra.Command { +// EmintServeCmd creates a CLI command to start Cosmos LCD server with web3 RPC API and +// Cosmos rest-server endpoints +func EmintServeCmd(cdc *codec.Codec) *cobra.Command { cmd := lcd.ServeCommand(cdc, registerRoutes) cmd.Flags().String(flagUnlockKey, "", "Select a key to unlock on the RPC server") cmd.Flags().StringP(flags.FlagBroadcastMode, "b", flags.BroadcastSync, "Transaction broadcasting mode (sync|async|block)") @@ -86,7 +90,13 @@ func registerRoutes(rs *lcd.RestServer) { } } + // Web3 RPC API route rs.Mux.HandleFunc("/", s.ServeHTTP).Methods("POST", "OPTIONS") + + // Register all other Cosmos routes + client.RegisterRoutes(rs.CliCtx, rs.Mux) + authrest.RegisterTxRoutes(rs.CliCtx, rs.Mux) + app.ModuleBasics.RegisterRESTRoutes(rs.CliCtx, rs.Mux) } func unlockKeyFromNameAndPassphrase(accountName, passphrase string) (emintKey emintcrypto.PrivKeySecp256k1, err error) {