This repository has been archived by the owner on Jul 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from tendermint/proofsubcmd
Reorganize how app-specific proof commands are customized
- Loading branch information
Showing
6 changed files
with
127 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.swp | ||
vendor | ||
.keys | ||
tmcli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,49 @@ | ||
package proofs | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/tendermint/tendermint/rpc/client" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
data "github.com/tendermint/go-wire/data" | ||
lc "github.com/tendermint/light-client" | ||
"github.com/tendermint/light-client/commands" | ||
"github.com/tendermint/tendermint/rpc/client" | ||
) | ||
|
||
func (p ProofCommander) GetCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "get", | ||
Short: "Get a proof from the tendermint node", | ||
RunE: p.doGet, | ||
SilenceUsage: true, | ||
} | ||
cmd.Flags().Int(heightFlag, 0, "Height to query (skip to use latest block)") | ||
cmd.Flags().String(appFlag, "raw", "App to use to interpret data") | ||
cmd.Flags().String(keyFlag, "", "Key to query on") | ||
return cmd | ||
} | ||
|
||
func (p ProofCommander) doGet(cmd *cobra.Command, args []string) error { | ||
app := viper.GetString(appFlag) | ||
pres, err := p.Lookup(app) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rawkey := viper.GetString(keyFlag) | ||
if rawkey == "" { | ||
return errors.New("missing required flag: --" + keyFlag) | ||
} | ||
|
||
// prepare the query in an app-dependent manner | ||
key, err := pres.MakeKey(rawkey) | ||
// GetProof performs the get command directly from the proof (not from the CLI) | ||
func GetProof(node client.Client, prover lc.Prover, key []byte, height int) (proof lc.Proof, err error) { | ||
proof, err = prover.Get(key, uint64(height)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// instantiate the prover instance and get a proof from the server | ||
p.Init() | ||
h := viper.GetInt(heightFlag) | ||
proof, err := p.Get(key, uint64(h)) | ||
if err != nil { | ||
return err | ||
return | ||
} | ||
ph := int(proof.BlockHeight()) | ||
|
||
// here is the certifier, root of all knowledge | ||
cert, err := commands.GetCertifier() | ||
if err != nil { | ||
return err | ||
return | ||
} | ||
|
||
// get and validate a signed header for this proof | ||
|
||
// FIXME: cannot use cert.GetByHeight for now, as it also requires | ||
// Validators and will fail on querying tendermint for non-current height. | ||
// When this is supported, we should use it instead... | ||
client.WaitForHeight(p.node, ph, nil) | ||
commit, err := p.node.Commit(ph) | ||
client.WaitForHeight(node, ph, nil) | ||
commit, err := node.Commit(ph) | ||
if err != nil { | ||
return err | ||
return | ||
} | ||
check := lc.Checkpoint{ | ||
Header: commit.Header, | ||
Commit: commit.Commit, | ||
} | ||
check := lc.Checkpoint{commit.Header, commit.Commit} | ||
err = cert.Certify(check) | ||
if err != nil { | ||
return err | ||
return | ||
} | ||
|
||
// validate the proof against the certified header to ensure data integrity | ||
err = proof.Validate(check) | ||
if err != nil { | ||
return err | ||
return | ||
} | ||
|
||
// TODO: store the proof or do something more interesting than just printing | ||
// fmt.Println("Your data is 100% certified:") | ||
fmt.Printf("Height: %d\n", proof.BlockHeight()) | ||
info, err := pres.ParseData(proof.Data()) | ||
if err != nil { | ||
return err | ||
} | ||
data, err := data.ToJSON(info) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(data)) | ||
return nil | ||
return proof, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters