diff --git a/cmd/basecli/commands/adapters.go b/cmd/basecli/commands/adapters.go index 516cb2f0d..7df8ca338 100644 --- a/cmd/basecli/commands/adapters.go +++ b/cmd/basecli/commands/adapters.go @@ -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 ,...") - fs.String("fee", "", "Coins for the transaction fee of the format ") + fs.String("fee", "0mycoin", "Coins for the transaction fee of the format ") fs.Int64("gas", 0, "Amount of gas for this transaction") fs.Int("sequence", -1, "Sequence number for this transaction") return fs, &SendFlags{} diff --git a/cmd/basecli/commands/query.go b/cmd/basecli/commands/query.go new file mode 100644 index 000000000..1162d2b09 --- /dev/null +++ b/cmd/basecli/commands/query.go @@ -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()) +} diff --git a/cmd/basecli/counter/query.go b/cmd/basecli/counter/query.go new file mode 100644 index 000000000..46973791d --- /dev/null +++ b/cmd/basecli/counter/query.go @@ -0,0 +1,44 @@ +package counter + +import ( + "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" + + "github.com/tendermint/basecoin/plugins/counter" +) + +var CounterTxCmd = &cobra.Command{ + Use: "counter", + Short: "query counter state", + RunE: counterTxCmd, +} + +func init() { + //first modify the full node account query command for the light client + proofcmd.RootCmd.AddCommand(CounterTxCmd) +} + +func counterTxCmd(cmd *cobra.Command, args []string) error { + + // get the proof -> this will be used by all prover commands + height := proofcmd.GetHeight() + node := commands.GetNode() + prover := proofs.NewAppProver(node) + key := counter.New().StateKey() + proof, err := proofcmd.GetProof(node, prover, key, height) + if err != nil { + return err + } + + var cp counter.CounterPluginState + err = wire.ReadBinaryBytes(proof.Data(), &cp) + if err != nil { + return err + } + + return proofcmd.OutputProof(cp, proof.BlockHeight()) +} diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index 01dc64683..7af9ce4de 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -33,9 +33,9 @@ func main() { commands.AddBasicFlags(BaseCli) //initialize proofs and txs - proofs.StatePresenters.Register("account", bcmd.AccountPresenter{}) + //proofs.StatePresenters.Register("account", bcmd.AccountPresenter{}) proofs.TxPresenters.Register("base", bcmd.BaseTxPresenter{}) - proofs.StatePresenters.Register("counter", bcount.CounterPresenter{}) + //proofs.StatePresenters.Register("counter", bcount.CounterPresenter{}) txs.Register("send", bcmd.SendTxMaker{}) txs.Register("counter", bcount.CounterTxMaker{}) diff --git a/cmd/counter/cmd.go b/cmd/counter/cmd.go index e83430498..a8c543e13 100644 --- a/cmd/counter/cmd.go +++ b/cmd/counter/cmd.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/spf13/cobra" + "github.com/spf13/viper" wire "github.com/tendermint/go-wire" "github.com/tendermint/basecoin/cmd/commands" @@ -19,16 +20,15 @@ var CounterTxCmd = &cobra.Command{ RunE: counterTxCmd, } -//flags -var ( - validFlag bool - countFeeFlag string +const ( + flagValid = "valid" + flagCountFee = "countfee" ) func init() { - CounterTxCmd.Flags().BoolVar(&validFlag, "valid", false, "Set valid field in CounterTx") - CounterTxCmd.Flags().StringVar(&countFeeFlag, "countfee", "", "Coins for the counter fee of the format ") + CounterTxCmd.Flags().Bool(flagValid, false, "Set valid field in CounterTx") + CounterTxCmd.Flags().String(flagCountFee, "", "Coins for the counter fee of the format ") commands.RegisterTxSubcommand(CounterTxCmd) commands.RegisterStartPlugin("counter", func() types.Plugin { return counter.New() }) @@ -36,13 +36,13 @@ func init() { func counterTxCmd(cmd *cobra.Command, args []string) error { - countFee, err := types.ParseCoins(countFeeFlag) + countFee, err := types.ParseCoins(viper.GetString(flagCountFee)) if err != nil { return err } counterTx := counter.CounterTx{ - Valid: validFlag, + Valid: viper.GetBool(flagValid), Fee: countFee, } diff --git a/glide.lock b/glide.lock index 8379e9e6d..e034a7afc 100644 --- a/glide.lock +++ b/glide.lock @@ -127,7 +127,7 @@ imports: - data - data/base58 - name: github.com/tendermint/light-client - version: 424905d3813586ce7e64e18690676250a0595ad4 + version: d993d8a9ba6cb51f05faf6e527016288e38c2853 subpackages: - certifiers - certifiers/client