Update seed to a given height

This commit is contained in:
Ethan Frey
2017-07-27 16:41:13 -04:00
parent d0920ac1cf
commit e90d6db516
3 changed files with 52 additions and 34 deletions
+12 -4
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/light-client/certifiers"
@@ -12,12 +13,13 @@ import (
var updateCmd = &cobra.Command{
Use: "update",
Short: "Update seed to current chain state if possible",
Short: "Update seed to current height if possible",
RunE: commands.RequireInit(updateSeed),
SilenceUsage: true,
}
func init() {
updateCmd.Flags().Int(heightFlag, 0, "Update to this height, not latest")
RootCmd.AddCommand(updateCmd)
}
@@ -27,14 +29,20 @@ func updateSeed(cmd *cobra.Command, args []string) error {
return err
}
// get the lastest from our source
seed, err := certifiers.LatestSeed(cert.SeedSource)
h := viper.GetInt(heightFlag)
var seed certifiers.Seed
if h <= 0 {
// get the lastest from our source
seed, err = certifiers.LatestSeed(cert.SeedSource)
} else {
seed, err = cert.SeedSource.GetByHeight(h)
}
if err != nil {
return err
}
fmt.Printf("Trying to update to height: %d...\n", seed.Height())
// let the certifier do it's magic to update....
fmt.Printf("Trying to update to height: %d...\n", seed.Height())
err = cert.Update(seed.Checkpoint, seed.Validators)
if err != nil {
return err