Use Get/GetParsed everywhere

This commit is contained in:
Alexis Sellier
2017-08-04 19:21:40 +02:00
parent 391380bef2
commit 831c9ae3ec
7 changed files with 89 additions and 118 deletions
+4 -2
View File
@@ -3,6 +3,7 @@ package commands
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
lc "github.com/tendermint/light-client"
@@ -32,12 +33,13 @@ func accountQueryCmd(cmd *cobra.Command, args []string) error {
key := stack.PrefixedKey(coin.NameCoin, act.Bytes())
acc := coin.Account{}
proof, err := proofcmd.GetAndParseAppProof(key, &acc)
prove := !viper.GetBool(commands.FlagTrustNode)
height, err := proofcmd.GetParsed(key, &acc, prove)
if lc.IsNoDataErr(err) {
return errors.Errorf("Account bytes are empty for address %s ", addr)
} else if err != nil {
return err
}
return proofcmd.OutputProof(acc, proof.BlockHeight())
return proofcmd.OutputProof(acc, height)
}
+4 -2
View File
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/gorilla/mux"
"github.com/spf13/viper"
"github.com/tendermint/basecoin"
"github.com/tendermint/basecoin/client/commands"
@@ -47,7 +48,8 @@ func doQueryAccount(w http.ResponseWriter, r *http.Request) {
actor = coin.ChainAddr(actor)
key := stack.PrefixedKey(coin.NameCoin, actor.Bytes())
account := new(coin.Account)
proof, err := proofs.GetAndParseAppProof(key, account)
prove := !viper.GetBool(commands.FlagTrustNode)
height, err := proofs.GetParsed(key, account, prove)
if lightclient.IsNoDataErr(err) {
err := fmt.Errorf("account bytes are empty for address: %q", signature)
common.WriteError(w, err)
@@ -57,7 +59,7 @@ func doQueryAccount(w http.ResponseWriter, r *http.Request) {
return
}
if err := proofs.FoutputProof(w, account, proof.BlockHeight()); err != nil {
if err := proofs.FoutputProof(w, account, height); err != nil {
common.WriteError(w, err)
}
}
+18 -23
View File
@@ -12,8 +12,6 @@ import (
"github.com/tendermint/basecoin/modules/ibc"
"github.com/tendermint/basecoin/stack"
"github.com/tendermint/go-wire/data"
"github.com/tendermint/light-client/proofs"
"github.com/tendermint/merkleeyes/iavl"
)
// TODO: query seeds (register/update)
@@ -86,17 +84,19 @@ func init() {
func ibcQueryCmd(cmd *cobra.Command, args []string) error {
var res ibc.HandlerInfo
key := stack.PrefixedKey(ibc.NameIBC, ibc.HandlerKey())
proof, err := proofcmd.GetAndParseAppProof(key, &res)
prove := !viper.GetBool(commands.FlagTrustNode)
h, err := proofcmd.GetParsed(key, &res, prove)
if err != nil {
return err
}
return proofcmd.OutputProof(res, proof.BlockHeight())
return proofcmd.OutputProof(res, h)
}
func chainsQueryCmd(cmd *cobra.Command, args []string) error {
list := [][]byte{}
key := stack.PrefixedKey(ibc.NameIBC, ibc.ChainsKey())
proof, err := proofcmd.GetAndParseAppProof(key, &list)
prove := !viper.GetBool(commands.FlagTrustNode)
h, err := proofcmd.GetParsed(key, &list, prove)
if err != nil {
return err
}
@@ -107,7 +107,7 @@ func chainsQueryCmd(cmd *cobra.Command, args []string) error {
res[i] = string(list[i])
}
return proofcmd.OutputProof(res, proof.BlockHeight())
return proofcmd.OutputProof(res, h)
}
func chainQueryCmd(cmd *cobra.Command, args []string) error {
@@ -118,12 +118,13 @@ func chainQueryCmd(cmd *cobra.Command, args []string) error {
var res ibc.ChainInfo
key := stack.PrefixedKey(ibc.NameIBC, ibc.ChainKey(arg))
proof, err := proofcmd.GetAndParseAppProof(key, &res)
prove := !viper.GetBool(commands.FlagTrustNode)
h, err := proofcmd.GetParsed(key, &res, prove)
if err != nil {
return err
}
return proofcmd.OutputProof(res, proof.BlockHeight())
return proofcmd.OutputProof(res, h)
}
func assertOne(from, to string) error {
@@ -154,12 +155,13 @@ func packetsQueryCmd(cmd *cobra.Command, args []string) error {
}
var res uint64
proof, err := proofcmd.GetAndParseAppProof(key, &res)
prove := !viper.GetBool(commands.FlagTrustNode)
h, err := proofcmd.GetParsed(key, &res, prove)
if err != nil {
return err
}
return proofcmd.OutputProof(res, proof.BlockHeight())
return proofcmd.OutputProof(res, h)
}
func packetQueryCmd(cmd *cobra.Command, args []string) error {
@@ -174,6 +176,7 @@ func packetQueryCmd(cmd *cobra.Command, args []string) error {
if seq < 0 {
return errors.Errorf("--%s must be a non-negative number", FlagSequence)
}
prove := !viper.GetBool(commands.FlagTrustNode)
var key []byte
if from != "" {
@@ -185,24 +188,16 @@ func packetQueryCmd(cmd *cobra.Command, args []string) error {
// Input queue just display the results
if from != "" {
var packet ibc.Packet
proof, err := proofcmd.GetAndParseAppProof(key, &packet)
h, err := proofcmd.GetParsed(key, &packet, prove)
if err != nil {
return err
}
return proofcmd.OutputProof(packet, proof.BlockHeight())
return proofcmd.OutputProof(packet, h)
}
// output queue, create a post packet
var packet ibc.Packet
proof, err := proofcmd.GetAndParseAppProof(key, &packet)
if err != nil {
return err
}
// TODO: oh so ugly. fix before merge!
// wait, i want to change go-merkle too....
appProof := proof.(proofs.AppProof)
extractedProof, err := iavl.ReadProof(appProof.Proof)
bs, height, proof, err := proofcmd.GetWithProof(key)
if err != nil {
return err
}
@@ -210,10 +205,10 @@ func packetQueryCmd(cmd *cobra.Command, args []string) error {
// create the post packet here.
post := ibc.PostPacketTx{
FromChainID: commands.GetChainID(),
FromChainHeight: proof.BlockHeight(),
FromChainHeight: height,
Key: key,
Packet: packet,
Proof: extractedProof,
Proof: proof,
}
// print json direct, as we don't need to wrap with the height
+7 -8
View File
@@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
lc "github.com/tendermint/light-client"
@@ -33,23 +34,21 @@ func nonceQueryCmd(cmd *cobra.Command, args []string) error {
return err
}
seq, proof, err := doNonceQuery(signers)
seq, height, err := doNonceQuery(signers)
if err != nil {
return err
}
return proofcmd.OutputProof(seq, proof.BlockHeight())
return proofcmd.OutputProof(seq, height)
}
func doNonceQuery(signers []basecoin.Actor) (sequence uint32, proof lc.Proof, err error) {
func doNonceQuery(signers []basecoin.Actor) (sequence uint32, height uint64, err error) {
key := stack.PrefixedKey(nonce.NameNonce, nonce.GetSeqKey(signers))
proof, err = proofcmd.GetAndParseAppProof(key, &sequence)
prove := !viper.GetBool(commands.FlagTrustNode)
height, err = proofcmd.GetParsed(key, &sequence, prove)
if lc.IsNoDataErr(err) {
// no data, return sequence 0
return 0, proof, nil
return 0, 0, nil
}
return
}
+4 -2
View File
@@ -2,6 +2,7 @@ package commands
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/basecoin/client/commands"
proofcmd "github.com/tendermint/basecoin/client/commands/proofs"
@@ -28,10 +29,11 @@ func roleQueryCmd(cmd *cobra.Command, args []string) error {
var res roles.Role
key := stack.PrefixedKey(roles.NameRole, role)
proof, err := proofcmd.GetAndParseAppProof(key, &res)
prove := !viper.GetBool(commands.FlagTrustNode)
height, err := proofcmd.GetParsed(key, &res, prove)
if err != nil {
return err
}
return proofcmd.OutputProof(res, proof.BlockHeight())
return proofcmd.OutputProof(res, height)
}