Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

Commit

Permalink
ProofCommander integration
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Jun 7, 2017
1 parent 89d8cc6 commit 79b00d9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
vendor
.keys
tmcli
31 changes: 21 additions & 10 deletions commands/proofs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (
"github.com/tendermint/tendermint/rpc/client"
)

// GetCmd creates the get command for a proof
func (p ProofCommander) GetCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get",
Short: "Get a proof from the tendermint node",
RunE: p.doGet,
RunE: p.getCmd,
SilenceUsage: true,
}
cmd.Flags().Int(heightFlag, 0, "Height to query (skip to use latest block)")
Expand All @@ -26,18 +27,27 @@ func (p ProofCommander) GetCmd() *cobra.Command {
return cmd
}

func (p ProofCommander) doGet(cmd *cobra.Command, args []string) error {
func (p ProofCommander) getCmd(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)
}

height := viper.GetInt(heightFlag)

return DoGet(p, app, rawkey, height)
}

// DoGet performs the get command directly from the proof (not from the CLI)
func DoGet(p ProofCommander, app, rawkey string, height int) error {

pres, err := p.Lookup(app)
if err != nil {
return err
}

// prepare the query in an app-dependent manner
key, err := pres.MakeKey(rawkey)
if err != nil {
Expand All @@ -46,13 +56,11 @@ func (p ProofCommander) doGet(cmd *cobra.Command, args []string) error {

// instantiate the prover instance and get a proof from the server
p.Init()
h := viper.GetInt(heightFlag)
proof, err := p.Get(key, uint64(h))
proof, err := p.Get(key, uint64(height))
if err != nil {
return err
}
ph := int(proof.BlockHeight())

// here is the certifier, root of all knowledge
cert, err := commands.GetCertifier()
if err != nil {
Expand All @@ -69,7 +77,10 @@ func (p ProofCommander) doGet(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
check := lc.Checkpoint{commit.Header, commit.Commit}
check := lc.Checkpoint{
Header: commit.Header,
Commit: commit.Commit,
}
err = cert.Certify(check)
if err != nil {
return err
Expand Down
8 changes: 7 additions & 1 deletion commands/proofs/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ func (p *ProofCommander) Init() {
p.Prover = p.ProverFunc(p.node)
}

func (p ProofCommander) Register(parent *cobra.Command) {
func (p ProofCommander) Register(parent *cobra.Command, cmdReg func(ProofCommander) *cobra.Command) {
// we add each subcommand here, so we can register the
// ProofCommander in one swoop
parent.AddCommand(cmdReg(p))
}

func (p ProofCommander) RegisterGet(parent *cobra.Command) {
// we add each subcommand here, so we can register the
// ProofCommander in one swoop
parent.AddCommand(p.GetCmd())
Expand Down
15 changes: 8 additions & 7 deletions commands/proofs/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ data to other peers as needed.
`,
}

var stateProverCommander = ProofCommander{
ProverFunc: stateProver,
Presenters: StatePresenters,
}

func init() {
stateProver := ProofCommander{
ProverFunc: stateProver,
Presenters: StatePresenters,
}
stateProver.Register(stateCmd)
stateProverCommander.RegisterGet(stateCmd)
RootCmd.AddCommand(stateCmd)
}

Expand All @@ -34,6 +35,6 @@ func stateProver(node client.Client) lc.Prover {
}

// RegisterProofStateSubcommand registers a subcommand to proof state cmd
func RegisterProofStateSubcommand(cmd *cobra.Command) {
stateCmd.AddCommand(cmd)
func RegisterProofStateSubcommand(cmdReg func(ProofCommander) *cobra.Command) {
stateProverCommander.Register(stateCmd, cmdReg)
}
2 changes: 1 addition & 1 deletion commands/proofs/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
ProverFunc: txProver,
Presenters: TxPresenters,
}
txProver.Register(txCmd)
txProver.RegisterGet(txCmd)
RootCmd.AddCommand(txCmd)
}

Expand Down

0 comments on commit 79b00d9

Please sign in to comment.