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
|
||||
}
|
||||
|
||||
// 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),
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue