From 624133ad929f986e35f69b0b437bf6f0ff5745be Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 20 Oct 2017 20:27:18 +0200 Subject: [PATCH] Fix lot more lightclient imports --- client/commands/common.go | 2 +- client/commands/init.go | 16 ++++++++-------- client/commands/query/get.go | 2 ++ client/commands/seeds/export.go | 6 ++++-- client/commands/seeds/import.go | 12 ++++++------ client/commands/seeds/show.go | 25 +++++++++++++------------ client/commands/seeds/update.go | 16 ++++++++-------- 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/client/commands/common.go b/client/commands/common.go index ef8827a990..c51dbb469b 100644 --- a/client/commands/common.go +++ b/client/commands/common.go @@ -74,7 +74,7 @@ func GetProviders() (trusted certifiers.Provider, source certifiers.Provider) { } // GetCertifier constructs a dynamic certifier from the config info -func GetCertifier() (*certifiers.InquiringCertifier, error) { +func GetCertifier() (*certifiers.Inquiring, error) { // load up the latest store.... trust := GetTrustedProvider() source := GetSourceProvider() diff --git a/client/commands/init.go b/client/commands/init.go index a54dbb6993..dc3b002104 100644 --- a/client/commands/init.go +++ b/client/commands/init.go @@ -280,14 +280,14 @@ func initSeed() (err error) { trust, source := GetProviders() // load a seed file, or get data from the provider - var seed certifiers.Seed + var seed certifiers.FullCommit seedFile := viper.GetString(SeedFlag) if seedFile == "" { fmt.Println("Loading validator set from tendermint rpc...") - seed, err = certifiers.LatestSeed(source) + seed, err = source.LatestCommit() } else { fmt.Printf("Loading validators from file %s\n", seedFile) - seed, err = certifiers.LoadSeed(seedFile) + seed, err = files.LoadFullCommit(seedFile) } // can't load the seed? abort! if err != nil { @@ -305,8 +305,8 @@ func initSeed() (err error) { if hash != "" { var hashb []byte hashb, err = hex.DecodeString(hash) - if err == nil && !bytes.Equal(hashb, seed.Hash()) { - err = errors.Errorf("Seed hash doesn't match expectation: %X", seed.Hash()) + if err == nil && !bytes.Equal(hashb, seed.ValidatorsHash()) { + err = errors.Errorf("Seed hash doesn't match expectation: %X", seed.ValidatorsHash()) } } else { err = validateHash(seed) @@ -317,14 +317,14 @@ func initSeed() (err error) { } // if accepted, store seed as current state - trust.StoreSeed(seed) + trust.StoreCommit(seed) return nil } -func validateHash(seed certifiers.Seed) error { +func validateHash(seed certifiers.FullCommit) error { // ask the user to verify the validator hash fmt.Println("\nImportant: if this is incorrect, all interaction with the chain will be insecure!") - fmt.Printf(" Given validator hash valid: %X\n", seed.Hash()) + fmt.Printf(" Given validator hash valid: %X\n", seed.ValidatorsHash()) fmt.Println("Is this valid (y/n)?") valid := askForConfirmation() if !valid { diff --git a/client/commands/query/get.go b/client/commands/query/get.go index 8e1284c48d..f597cd8bb1 100644 --- a/client/commands/query/get.go +++ b/client/commands/query/get.go @@ -14,6 +14,8 @@ import ( "github.com/tendermint/light-client/proofs" rpcclient "github.com/tendermint/tendermint/rpc/client" + rpcclient "github.com/tendermint/tendermint/rpc/client" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/commands" ) diff --git a/client/commands/seeds/export.go b/client/commands/seeds/export.go index ec381246bd..0eeaed01f2 100644 --- a/client/commands/seeds/export.go +++ b/client/commands/seeds/export.go @@ -5,6 +5,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/tendermint/light-client/certifiers/files" + "github.com/cosmos/cosmos-sdk/client/commands" ) @@ -34,11 +36,11 @@ func exportSeed(cmd *cobra.Command, args []string) error { trust, _ := commands.GetProviders() h := viper.GetInt(heightFlag) hash := viper.GetString(hashFlag) - seed, err := loadSeed(trust, h, hash, "") + fc, err := loadCommit(trust, h, hash, "") if err != nil { return err } // now get the output file and write it - return seed.WriteJSON(path) + return files.SaveFullCommitJSON(fc, path) } diff --git a/client/commands/seeds/import.go b/client/commands/seeds/import.go index d231f4c3b5..d115463c83 100644 --- a/client/commands/seeds/import.go +++ b/client/commands/seeds/import.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/tendermint/light-client/certifiers" + "github.com/tendermint/light-client/certifiers/files" "github.com/cosmos/cosmos-sdk/client/commands" ) @@ -42,18 +42,18 @@ func importSeed(cmd *cobra.Command, args []string) error { // parse the input file path := args[0] - seed, err := certifiers.LoadSeedJSON(path) + fc, err := files.LoadFullCommitJSON(path) if err != nil { return err } // just do simple checks in --dry-run if viper.GetBool(dryFlag) { - fmt.Printf("Testing seed %d/%X\n", seed.Height(), seed.Hash()) - err = seed.ValidateBasic(cert.ChainID()) + fmt.Printf("Testing commit %d/%X\n", fc.Height(), fc.ValidatorsHash()) + err = fc.ValidateBasic(cert.ChainID()) } else { - fmt.Printf("Importing seed %d/%X\n", seed.Height(), seed.Hash()) - err = cert.Update(seed.Checkpoint, seed.Validators) + fmt.Printf("Importing commit %d/%X\n", fc.Height(), fc.ValidatorsHash()) + err = cert.Update(fc) } return err } diff --git a/client/commands/seeds/show.go b/client/commands/seeds/show.go index 852cb0b82c..953548a1a0 100644 --- a/client/commands/seeds/show.go +++ b/client/commands/seeds/show.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/viper" "github.com/tendermint/light-client/certifiers" + "github.com/tendermint/light-client/certifiers/files" "github.com/cosmos/cosmos-sdk/client/commands" ) @@ -21,11 +22,11 @@ const ( var showCmd = &cobra.Command{ Use: "show", - Short: "Show the details of one selected seed", + Short: "Show the details of one selected commit", Long: `Shows the most recent downloaded key by default. If desired, you can select by height, validator hash, or a file. `, - RunE: commands.RequireInit(showSeed), + RunE: commands.RequireInit(showCommit), SilenceUsage: true, } @@ -36,38 +37,38 @@ func init() { RootCmd.AddCommand(showCmd) } -func loadSeed(p certifiers.Provider, h int, hash, file string) (seed certifiers.Seed, err error) { - // load the seed from the proper place +func loadCommit(p certifiers.Provider, h int, hash, file string) (fc certifiers.FullCommit, err error) { + // load the commit from the proper place if h != 0 { - seed, err = p.GetByHeight(h) + fc, err = p.GetByHeight(h) } else if hash != "" { var vhash []byte vhash, err = hex.DecodeString(hash) if err == nil { - seed, err = p.GetByHash(vhash) + fc, err = p.GetByHash(vhash) } } else if file != "" { - seed, err = certifiers.LoadSeedJSON(file) + fc, err = files.LoadFullCommitJSON(file) } else { - // default is latest seed - seed, err = certifiers.LatestSeed(p) + // default is latest commit + fc, err = p.LatestCommit() } return } -func showSeed(cmd *cobra.Command, args []string) error { +func showCommit(cmd *cobra.Command, args []string) error { trust, _ := commands.GetProviders() h := viper.GetInt(heightFlag) hash := viper.GetString(hashFlag) file := viper.GetString(fileFlag) - seed, err := loadSeed(trust, h, hash, file) + fc, err := loadCommit(trust, h, hash, file) if err != nil { return err } // now render it! - data, err := json.MarshalIndent(seed, "", " ") + data, err := json.MarshalIndent(fc, "", " ") fmt.Println(string(data)) return err } diff --git a/client/commands/seeds/update.go b/client/commands/seeds/update.go index df2a962108..4d99c59bd1 100644 --- a/client/commands/seeds/update.go +++ b/client/commands/seeds/update.go @@ -13,8 +13,8 @@ import ( var updateCmd = &cobra.Command{ Use: "update", - Short: "Update seed to current height if possible", - RunE: commands.RequireInit(updateSeed), + Short: "Update commit to current height if possible", + RunE: commands.RequireInit(updateCommit), SilenceUsage: true, } @@ -23,27 +23,27 @@ func init() { RootCmd.AddCommand(updateCmd) } -func updateSeed(cmd *cobra.Command, args []string) error { +func updateCommit(cmd *cobra.Command, args []string) error { cert, err := commands.GetCertifier() if err != nil { return err } h := viper.GetInt(heightFlag) - var seed certifiers.Seed + var fc certifiers.FullCommit if h <= 0 { // get the lastest from our source - seed, err = certifiers.LatestSeed(cert.SeedSource) + fc, err = cert.Source.LatestCommit() } else { - seed, err = cert.SeedSource.GetByHeight(h) + fc, err = cert.Source.GetByHeight(h) } if err != nil { return err } // 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) + fmt.Printf("Trying to update to height: %d...\n", fc.Height()) + err = cert.Update(fc) if err != nil { return err }