replace basecli state presenters with cmds

This commit is contained in:
rigel rozanski
2017-06-14 05:02:42 -04:00
parent 7624c66f98
commit 25e7a79174
6 changed files with 111 additions and 28 deletions
+1 -17
View File
@@ -17,22 +17,6 @@ import (
btypes "github.com/tendermint/basecoin/types"
)
type AccountPresenter struct{}
func (_ AccountPresenter) MakeKey(str string) ([]byte, error) {
res, err := hex.DecodeString(str)
if err == nil {
res = btypes.AccountKey(res)
}
return res, err
}
func (_ AccountPresenter) ParseData(raw []byte) (interface{}, error) {
var acc *btypes.Account
err := wire.ReadBinaryBytes(raw, &acc)
return acc, err
}
type BaseTxPresenter struct {
proofs.RawPresenter // this handles MakeKey as hex bytes
}
@@ -65,7 +49,7 @@ func (m SendTxMaker) Flags() (*flag.FlagSet, interface{}) {
fs.String("to", "", "Destination address for the bits")
fs.String("amount", "", "Coins to send in the format <amt><coin>,<amt><coin>...")
fs.String("fee", "", "Coins for the transaction fee of the format <amt><coin>")
fs.String("fee", "0mycoin", "Coins for the transaction fee of the format <amt><coin>")
fs.Int64("gas", 0, "Amount of gas for this transaction")
fs.Int("sequence", -1, "Sequence number for this transaction")
return fs, &SendFlags{}
+55
View File
@@ -0,0 +1,55 @@
package commands
import (
"encoding/hex"
"fmt"
"github.com/pkg/errors"
"github.com/spf13/cobra"
wire "github.com/tendermint/go-wire"
"github.com/tendermint/light-client/commands"
proofcmd "github.com/tendermint/light-client/commands/proofs"
"github.com/tendermint/light-client/proofs"
bccmd "github.com/tendermint/basecoin/cmd/commands"
btypes "github.com/tendermint/basecoin/types"
)
func init() {
//first modify the full node account query command for the light client
bccmd.AccountCmd.RunE = accountCmd
proofcmd.RootCmd.AddCommand(bccmd.AccountCmd)
}
func accountCmd(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("account command requires an argument ([address])") //never stack trace
}
addrHex := StripHex(args[0])
// convert destination address to bytes
addr, err := hex.DecodeString(addrHex)
if err != nil {
return errors.Errorf("Account address (%v) is invalid hex: %v\n", addrHex, err)
}
// get the proof -> this will be used by all prover commands
height := proofcmd.GetHeight()
node := commands.GetNode()
prover := proofs.NewAppProver(node)
key := btypes.AccountKey(addr)
proof, err := proofcmd.GetProof(node, prover, key, height)
if err != nil {
return err
}
var acc *btypes.Account
err = wire.ReadBinaryBytes(proof.Data(), &acc)
if err != nil {
return err
}
return proofcmd.OutputProof(&acc, proof.BlockHeight())
}