Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

Commit

Permalink
A bit or cleanup on hex arg parsing helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jun 14, 2017
1 parent d993d8a commit c7d5799
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions commands/proofs/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion commands/proofs/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion commands/proofs/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c7d5799

Please sign in to comment.