From 4207275d1871ae44be020e343364cd0089ff62d9 Mon Sep 17 00:00:00 2001 From: rigel rozanski Date: Mon, 1 May 2017 03:05:54 -0400 Subject: [PATCH] basecli cleanup glide fix int int --- cmd/basecli/adapters.go | 40 ++++++++++++++++++++++------------------ cmd/basecli/main.go | 22 +++++++++++----------- glide.yaml | 2 +- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/cmd/basecli/adapters.go b/cmd/basecli/adapters.go index b0b10d2fc..4398b9731 100644 --- a/cmd/basecli/adapters.go +++ b/cmd/basecli/adapters.go @@ -7,7 +7,10 @@ import ( "github.com/pkg/errors" flag "github.com/spf13/pflag" "github.com/spf13/viper" + + "github.com/tendermint/basecoin/state" btypes "github.com/tendermint/basecoin/types" + keycmd "github.com/tendermint/go-crypto/cmd" wire "github.com/tendermint/go-wire" lightclient "github.com/tendermint/light-client" @@ -20,7 +23,7 @@ type AccountPresenter struct{} func (_ AccountPresenter) MakeKey(str string) ([]byte, error) { res, err := hex.DecodeString(str) if err == nil { - res = append([]byte("base/a/"), res...) + res = state.AccountKey(res) } return res, err } @@ -41,21 +44,6 @@ func (_ BaseTxPresenter) ParseData(raw []byte) (interface{}, error) { return tx, err } -// SendTXReader allows us to create SendTx -type SendTxReader struct { - ChainID string -} - -func (t SendTxReader) ReadTxJSON(data []byte) (interface{}, error) { - var tx btypes.SendTx - err := json.Unmarshal(data, &tx) - send := SendTx{ - chainID: t.ChainID, - Tx: &tx, - } - return &send, errors.Wrap(err, "parse sendtx") -} - type SendTxMaker struct{} func (m SendTxMaker) MakeReader() (lightclient.TxReader, error) { @@ -72,7 +60,8 @@ type SendFlags struct { } func (m SendTxMaker) Flags() (*flag.FlagSet, interface{}) { - fs := flag.NewFlagSet("foobar", flag.ContinueOnError) + fs := flag.NewFlagSet("", flag.ContinueOnError) + 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 ") @@ -81,6 +70,21 @@ func (m SendTxMaker) Flags() (*flag.FlagSet, interface{}) { return fs, &SendFlags{} } +// SendTXReader allows us to create SendTx +type SendTxReader struct { + ChainID string +} + +func (t SendTxReader) ReadTxJSON(data []byte) (interface{}, error) { + var tx btypes.SendTx + err := json.Unmarshal(data, &tx) + send := SendTx{ + chainID: t.ChainID, + Tx: &tx, + } + return &send, errors.Wrap(err, "parse sendtx") +} + func (t SendTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { data := flags.(*SendFlags) @@ -134,7 +138,7 @@ func (t SendTxReader) ReadTxFlags(flags interface{}) (interface{}, error) { return &send, nil } -/** copied from basecoin cli - put in common somewhere? **/ +/** TODO copied from basecoin cli - put in common somewhere? **/ // Returns true for non-empty hex-string prefixed with "0x" func isHex(s string) bool { diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index baaf630da..79aa4c4bf 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -7,7 +7,6 @@ import ( keycmd "github.com/tendermint/go-crypto/cmd" "github.com/tendermint/light-client/commands" "github.com/tendermint/light-client/commands/proofs" - "github.com/tendermint/light-client/commands/proxy" "github.com/tendermint/light-client/commands/seeds" "github.com/tendermint/light-client/commands/txs" "github.com/tendermint/tmlibs/cli" @@ -25,22 +24,23 @@ tmcli to work for any custom abci app. `, } -func init() { +func main() { commands.AddBasicFlags(BaseCli) - // set up the various commands to use - BaseCli.AddCommand(keycmd.RootCmd) - BaseCli.AddCommand(commands.InitCmd) - BaseCli.AddCommand(seeds.RootCmd) + //initialize proofs and txs proofs.StatePresenters.Register("account", AccountPresenter{}) proofs.TxPresenters.Register("base", BaseTxPresenter{}) - BaseCli.AddCommand(proofs.RootCmd) txs.Register("send", SendTxMaker{}) - BaseCli.AddCommand(txs.RootCmd) - BaseCli.AddCommand(proxy.RootCmd) -} -func main() { + // set up the various commands to use + BaseCli.AddCommand( + keycmd.RootCmd, + commands.InitCmd, + seeds.RootCmd, + proofs.RootCmd, + txs.RootCmd, + ) + cmd := cli.PrepareMainCmd(BaseCli, "BC", os.ExpandEnv("$HOME/.basecli")) cmd.Execute() } diff --git a/glide.yaml b/glide.yaml index b05000855..718b80e6d 100644 --- a/glide.yaml +++ b/glide.yaml @@ -44,7 +44,7 @@ import: - rpc/lib/types - types - package: github.com/tendermint/tmlibs - version: develop + version: basecoin-cli subpackages: - cli - common