diff --git a/PENDING.md b/PENDING.md index b129bfcbb..ae07da0bd 100644 --- a/PENDING.md +++ b/PENDING.md @@ -87,7 +87,8 @@ IMPROVEMENTS BUG FIXES * Gaia REST API (`gaiacli advanced rest-server`) - - [gaia-lite] #2868 Added handler for governance tally endpoit + - [gaia-lite] #2868 Added handler for governance tally endpoint + * #2907 Refactor and fix the way Gaia Lite is started. * Gaia CLI (`gaiacli`) diff --git a/client/lcd/root.go b/client/lcd/root.go index 986e53006..67639b8a2 100644 --- a/client/lcd/root.go +++ b/client/lcd/root.go @@ -145,15 +145,19 @@ func (rs *RestServer) Start(listenAddr string, sslHosts string, return nil } -// ServeCommand will generate a long-running rest server -// (aka Light Client Daemon) that exposes functionality similar -// to the cli, but over rest -func (rs *RestServer) ServeCommand() *cobra.Command { +// ServeCommand will start a Gaia Lite REST service as a blocking process. It +// takes a codec to create a RestServer object and a function to register all +// necessary routes. +func ServeCommand(cdc *codec.Codec, registerRoutesFn func(*RestServer)) *cobra.Command { cmd := &cobra.Command{ Use: "rest-server", Short: "Start LCD (light-client daemon), a local REST server", RunE: func(cmd *cobra.Command, args []string) (err error) { + rs := NewRestServer(cdc) + rs.setKeybase(nil) + registerRoutesFn(rs) + // Start the rest server and return error if one exists err = rs.Start( viper.GetString(client.FlagListenAddr), diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index 05c7bc4ec..354de8c5d 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -60,12 +60,6 @@ func main() { config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub) config.Seal() - // Create a new RestServer instance to serve the light client routes - rs := lcd.NewRestServer(cdc) - - // registerRoutes registers the routes on the rest server - registerRoutes(rs) - // TODO: setup keybase, viper object, etc. to be passed into // the below functions and eliminate global vars, like we do // with the cdc @@ -92,7 +86,7 @@ func main() { queryCmd(cdc, mc), txCmd(cdc, mc), client.LineBreak, - rs.ServeCommand(), + lcd.ServeCommand(cdc, registerRoutes), client.LineBreak, keys.Commands(), client.LineBreak, diff --git a/docs/examples/basecoin/cmd/basecli/main.go b/docs/examples/basecoin/cmd/basecli/main.go index 8093dd3b1..6e274123e 100644 --- a/docs/examples/basecoin/cmd/basecli/main.go +++ b/docs/examples/basecoin/cmd/basecli/main.go @@ -52,10 +52,6 @@ func main() { config.SetBech32PrefixForConsensusNode("basecons", "baseconspub") config.Seal() - rs := lcd.NewRestServer(cdc) - - registerRoutes(rs) - // TODO: Setup keybase, viper object, etc. to be passed into // the below functions and eliminate global vars, like we do // with the cdc. @@ -104,7 +100,7 @@ func main() { // add proxy, version and key info rootCmd.AddCommand( client.LineBreak, - rs.ServeCommand(), + lcd.ServeCommand(cdc, registerRoutes), keys.Commands(), client.LineBreak, version.VersionCmd, diff --git a/docs/examples/democoin/cmd/democli/main.go b/docs/examples/democoin/cmd/democli/main.go index a001ee8b5..d3d0e5ff0 100644 --- a/docs/examples/democoin/cmd/democli/main.go +++ b/docs/examples/democoin/cmd/democli/main.go @@ -48,10 +48,6 @@ func main() { config.SetBech32PrefixForConsensusNode("democons", "democonspub") config.Seal() - rs := lcd.NewRestServer(cdc) - - registerRoutes(rs) - // TODO: setup keybase, viper object, etc. to be passed into // the below functions and eliminate global vars, like we do // with the cdc @@ -94,7 +90,7 @@ func main() { // add proxy, version and key info rootCmd.AddCommand( client.LineBreak, - rs.ServeCommand(), + lcd.ServeCommand(cdc, registerRoutes), keys.Commands(), client.LineBreak, version.VersionCmd,