From c7d5799ddee67238c81a6dba66735804e472c290 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 14 Jun 2017 14:52:28 +0200 Subject: [PATCH] A bit or cleanup on hex arg parsing helper --- commands/proofs/root.go | 12 ++++++------ commands/proofs/state.go | 2 +- commands/proofs/tx.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/commands/proofs/root.go b/commands/proofs/root.go index 9efbc60..4312dc6 100644 --- a/commands/proofs/root.go +++ b/commands/proofs/root.go @@ -36,20 +36,20 @@ func init() { } // ParseHexKey parses the key flag as hex and converts to bytes or returns error -// if prefix is non-nil, it prepends this constant to the given key (eg. "base/a/") -func ParseHexKey(args []string, prefix []byte) ([]byte, error) { +// argname is used to customize the error message +func ParseHexKey(args []string, argname string) ([]byte, error) { if len(args) == 0 { - return nil, errors.New("Missing required key argument") + return nil, errors.Errorf("Missing required argument [%s]", argname) } if len(args) > 1 { - return nil, errors.Errorf("Only accepts one key argument") + return nil, errors.Errorf("Only accepts one argument [%s]", argname) } rawkey := args[0] if rawkey == "" { - return nil, errors.New("Cannot query on empty key") + return nil, errors.Errorf("[%s] argument must be non-empty ", argname) } // with tx, we always just parse key as hex and use to lookup - return proofs.KeyMaker{prefix}.MakeKey(rawkey) + return proofs.ParseHexKey(rawkey) } func GetHeight() int { diff --git a/commands/proofs/state.go b/commands/proofs/state.go index f3cbbcd..a64d8b5 100644 --- a/commands/proofs/state.go +++ b/commands/proofs/state.go @@ -22,7 +22,7 @@ If you want json output, use an app-specific command that knows key and value st func doKeyQuery(cmd *cobra.Command, args []string) error { // parse cli height := GetHeight() - bkey, err := ParseHexKey(args, nil) + bkey, err := ParseHexKey(args, "key") if err != nil { return err } diff --git a/commands/proofs/tx.go b/commands/proofs/tx.go index 5cbbc5e..5c199ab 100644 --- a/commands/proofs/tx.go +++ b/commands/proofs/tx.go @@ -24,7 +24,7 @@ data to other peers as needed. func doTxQuery(cmd *cobra.Command, args []string) error { // parse cli height := GetHeight() - bkey, err := ParseHexKey(args, nil) + bkey, err := ParseHexKey(args, "txhash") if err != nil { return err }