From 6da5f72de93d5b407bc2c4966b2f42b8b8abd419 Mon Sep 17 00:00:00 2001 From: rigel rozanski Date: Mon, 17 Apr 2017 21:28:03 -0400 Subject: [PATCH] tiny fixes --- cmd/commands/ibc.go | 2 +- cmd/commands/init.go | 3 +-- cmd/commands/key.go | 1 - cmd/commands/query.go | 3 +++ cmd/commands/start.go | 7 ++----- cmd/commands/tx.go | 4 ++-- cmd/commands/utils.go | 16 ++++++++++++++-- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/cmd/commands/ibc.go b/cmd/commands/ibc.go index 1c817d5bdb..8b0938826b 100644 --- a/cmd/commands/ibc.go +++ b/cmd/commands/ibc.go @@ -91,7 +91,7 @@ func init() { packetCreateFlags := []Flag2Register{ fromFlagReg, {&ibcToFlag, "to", "", "Destination ChainID"}, - {&ibcTypeFlag, "type", "", "IBC packet type (eg. coin},"}, + {&ibcTypeFlag, "type", "", "IBC packet type (eg. coin)"}, {&ibcPayloadFlag, "payload", "", "IBC packet payload"}, {&ibcSequenceFlag, "ibc_sequence", -1, "sequence number for IBC packet"}, } diff --git a/cmd/commands/init.go b/cmd/commands/init.go index 7308c7961c..68b2ab3899 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -19,11 +19,10 @@ var ( } ) -// setupFile aborts on error... or should we return it?? // returns 1 iff it set a file, otherwise 0 (so we can add them) func setupFile(path, data string, perm os.FileMode) (int, error) { _, err := os.Stat(path) - if !os.IsNotExist(err) { + if !os.IsNotExist(err) { //permission errors generated if use os.IsExist return 0, nil } err = ioutil.WriteFile(path, []byte(data), perm) diff --git a/cmd/commands/key.go b/cmd/commands/key.go index 62be3c1d36..91678f625f 100644 --- a/cmd/commands/key.go +++ b/cmd/commands/key.go @@ -31,7 +31,6 @@ var ( func newKeyCmd(cmd *cobra.Command, args []string) error { key := genKey() keyJSON, err := json.MarshalIndent(key, "", "\t") - fmt.Println(&key) if err != nil { return err } diff --git a/cmd/commands/query.go b/cmd/commands/query.go index 56ec683a16..f73ed0ada0 100644 --- a/cmd/commands/query.go +++ b/cmd/commands/query.go @@ -198,6 +198,9 @@ func verifyCmd(cmd *cobra.Command, args []string) error { } proofBytes, err := hex.DecodeString(StripHex(proofFlag)) + if err != nil { + return errors.Errorf("Proof (%v) is invalid hex: %v\n", proofBytes, err) + } proof, err := merkle.ReadProof(proofBytes) if err != nil { diff --git a/cmd/commands/start.go b/cmd/commands/start.go index e4fd5560cd..4578738ceb 100644 --- a/cmd/commands/start.go +++ b/cmd/commands/start.go @@ -43,12 +43,9 @@ func init() { {&addrFlag, "address", "tcp://0.0.0.0:46658", "Listen address"}, {&eyesFlag, "eyes", "local", "MerkleEyes address, or 'local' for embedded"}, {&dirFlag, "dir", ".", "Root directory"}, - {&withoutTendermintFlag, "without-tendermint", false, "RunE Tendermint in-process with the App"}, + {&withoutTendermintFlag, "without-tendermint", false, "Run Tendermint in-process with the App"}, } RegisterFlags(StartCmd, flags) - - // TODO: move to config file - // eyesCacheSizePtr := flag.Int("eyes-cache-size", 10000, "MerkleEyes db cache size, for embedded") } func startCmd(cmd *cobra.Command, args []string) error { @@ -134,7 +131,7 @@ func startTendermint(dir string, basecoinApp *app.Basecoin) error { _, err := n.Start() if err != nil { - return errors.Errorf("%v\n", err) + return err } // Wait forever diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 1fd6be11cd..2e12be06ec 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -58,10 +58,10 @@ func init() { {&txNodeFlag, "node", "tcp://localhost:46657", "Tendermint RPC address"}, {&chainIDFlag, "chain_id", "test_chain_id", "ID of the chain for replay protection"}, {&fromFlag, "from", "key.json", "Path to a private key to sign the transaction"}, - {&amountFlag, "amount", "", "Coins to send in transaction of the format ,,... (eg: 1btc,2gold,5silver},"}, + {&amountFlag, "amount", "", "Coins to send in transaction of the format ,,... (eg: 1btc,2gold,5silver)"}, {&gasFlag, "gas", 0, "The amount of gas for the transaction"}, {&feeFlag, "fee", "", "Coins for the transaction fee of the format "}, - {&seqFlag, "sequence", -1, "Sequence number for the account (-1 to autocalculate},"}, + {&seqFlag, "sequence", -1, "Sequence number for the account (-1 to autocalculate)"}, } sendTxFlags := []Flag2Register{ diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index 5dd9635fa4..7eea8cdebd 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -4,6 +4,10 @@ import ( "encoding/hex" "fmt" "os" + "path" + "regexp" + "strconv" + "strings" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -22,14 +26,14 @@ import ( //This variable can be overwritten by plugin applications // if they require a different working directory -var DefaultHome = "basecoin" +var DefaultHome = ".basecoin" func BasecoinRoot(rootDir string) string { if rootDir == "" { rootDir = os.Getenv("BCHOME") } if rootDir == "" { - rootDir = os.Getenv("HOME") + "/." + DefaultHome + rootDir = path.Join(os.Getenv("HOME"), DefaultHome) } return rootDir } @@ -48,6 +52,14 @@ func ExecuteWithDebug(RootCmd *cobra.Command) { } } +//Quickly registering flags can be quickly achieved through using the utility functions +//RegisterFlags, and RegisterPersistentFlags. Ex: +// flags := []Flag2Register{ +// {&myStringFlag, "mystringflag", "foobar", "description of what this flag does"}, +// {&myBoolFlag, "myboolflag", false, "description of what this flag does"}, +// {&myInt64Flag, "myintflag", 333, "description of what this flag does"}, +// } +// RegisterFlags(MyCobraCmd, flags) type Flag2Register struct { Pointer interface{} Use string