Refactor Gaia Lite bootstrapping
This commit is contained in:
parent
71aec4688b
commit
155c553456
|
@ -145,15 +145,19 @@ func (rs *RestServer) Start(listenAddr string, sslHosts string,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeCommand will generate a long-running rest server
|
// ServeCommand will start a Gaia Lite REST service as a blocking process. It
|
||||||
// (aka Light Client Daemon) that exposes functionality similar
|
// takes a codec to create a RestServer object and a function to register all
|
||||||
// to the cli, but over rest
|
// necessary routes.
|
||||||
func (rs *RestServer) ServeCommand() *cobra.Command {
|
func ServeCommand(cdc *codec.Codec, registerRoutesFn func(*RestServer)) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "rest-server",
|
Use: "rest-server",
|
||||||
Short: "Start LCD (light-client daemon), a local REST server",
|
Short: "Start LCD (light-client daemon), a local REST server",
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
rs := NewRestServer(cdc)
|
||||||
|
|
||||||
rs.setKeybase(nil)
|
rs.setKeybase(nil)
|
||||||
|
registerRoutesFn(rs)
|
||||||
|
|
||||||
// Start the rest server and return error if one exists
|
// Start the rest server and return error if one exists
|
||||||
err = rs.Start(
|
err = rs.Start(
|
||||||
viper.GetString(client.FlagListenAddr),
|
viper.GetString(client.FlagListenAddr),
|
||||||
|
|
|
@ -60,12 +60,6 @@ func main() {
|
||||||
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
|
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
|
||||||
config.Seal()
|
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
|
// TODO: setup keybase, viper object, etc. to be passed into
|
||||||
// the below functions and eliminate global vars, like we do
|
// the below functions and eliminate global vars, like we do
|
||||||
// with the cdc
|
// with the cdc
|
||||||
|
@ -92,7 +86,7 @@ func main() {
|
||||||
queryCmd(cdc, mc),
|
queryCmd(cdc, mc),
|
||||||
txCmd(cdc, mc),
|
txCmd(cdc, mc),
|
||||||
client.LineBreak,
|
client.LineBreak,
|
||||||
rs.ServeCommand(),
|
lcd.ServeCommand(cdc, registerRoutes),
|
||||||
client.LineBreak,
|
client.LineBreak,
|
||||||
keys.Commands(),
|
keys.Commands(),
|
||||||
client.LineBreak,
|
client.LineBreak,
|
||||||
|
|
Loading…
Reference in New Issue