Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Query txs by signature and by address+seq #9750

Merged
merged 25 commits into from
Jul 27, 2021
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dafbe1f
WIP for auth query
amaury1093 Jul 21, 2021
d801fbd
Make query by addr and seq work
amaury1093 Jul 22, 2021
3628100
Add tests for sigs
amaury1093 Jul 22, 2021
51f4cf2
Merge branch 'master' into am/9741-tx-query
amaury1093 Jul 22, 2021
ea3dc2e
Make query by sig work
amaury1093 Jul 22, 2021
96d357c
Fix lint
amaury1093 Jul 22, 2021
069e823
Improve err message
amaury1093 Jul 22, 2021
f319d4a
Move HasExtensionOptionsTx to authtx?
amaury1093 Jul 22, 2021
eb06533
Switch to bez's CLI UX
amaury1093 Jul 22, 2021
b7218b1
Fix cycle dep
amaury1093 Jul 22, 2021
56c331a
Cleanups
amaury1093 Jul 22, 2021
620b3ea
Update CHANGELOG.md
amaury1093 Jul 22, 2021
76f6fdd
Emit all nested sigs
amaury1093 Jul 23, 2021
acefab9
Merge branch 'am/9741-tx-query' of ssh://github.com/cosmos/cosmos-sdk…
amaury1093 Jul 23, 2021
209ffb3
Merge branch 'master' into am/9741-tx-query
amaury1093 Jul 23, 2021
f6e61e1
Index by addr++seq
amaury1093 Jul 23, 2021
ef80915
Merge branch 'master' into am/9741-tx-query
amaury1093 Jul 26, 2021
1d0c8c5
Use '/' delimiter
amaury1093 Jul 26, 2021
1eb8abd
Merge branch 'master' into am/9741-tx-query
alexanderbez Jul 26, 2021
fade9f7
Update x/auth/client/cli/query.go
amaury1093 Jul 27, 2021
10f846e
Update x/auth/client/cli/query.go
amaury1093 Jul 27, 2021
2e9a636
Update x/auth/client/cli/query.go
amaury1093 Jul 27, 2021
4e19f3d
Update x/auth/client/cli/query.go
amaury1093 Jul 27, 2021
91314fe
Address review comments
amaury1093 Jul 27, 2021
78b7526
Merge branch 'master' into am/9741-tx-query
amaury1093 Jul 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review comments
  • Loading branch information
amaury1093 committed Jul 27, 2021
commit 91314fefd9a28b36fd85e143cd20d04953afba85
2 changes: 1 addition & 1 deletion x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
@@ -512,6 +512,6 @@ func signatureDataToBz(data signing.SignatureData) ([][]byte, error) {

return sigs, nil
default:
return nil, fmt.Errorf("unexpected signature data type %T", data)
return nil, sdkerrors.ErrInvalidType.Wrapf("unexpected signature data type %T", data)
}
}
24 changes: 17 additions & 7 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
@@ -222,9 +223,10 @@ Example:
$ %s query tx <hash>
$ %s query tx --%s=%s <addr>:<sequence>
$ %s query tx --%s=%s <sig1_base64,sig2_base64...>
`, version.AppName,
version.AppName, flagType, typeAccSeq,
version.AppName, flagType, typeSig)),
`,
version.AppName,
version.AppName, flagType, typeAccSeq,
version.AppName, flagType, typeSig)),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
@@ -255,11 +257,10 @@ version.AppName, flagType, typeSig)),
}
case typeSig:
{
if len(args) != 1 || args[0] == "" {
return fmt.Errorf("argument should be comma-separated signatures")
sigParts, err := parseSigArgs(args)
if err != nil {
return err
}

sigParts := strings.Split(args[0], ",")
tmEvents := make([]string, len(sigParts))
for i, sig := range sigParts {
tmEvents[i] = fmt.Sprintf("%s.%s='%s'", sdk.EventTypeTx, sdk.AttributeKeySignature, sig)
@@ -313,3 +314,12 @@ version.AppName, flagType, typeSig)),

return cmd
}

// parseSigArgs parses comma-separated signatures from the CLI arguments.
func parseSigArgs(args []string) ([]string, error) {
if len(args) != 1 || args[0] == "" {
return nil, fmt.Errorf("argument should be comma-separated signatures")
}

return strings.Split(args[0], ","), nil
}
32 changes: 32 additions & 0 deletions x/auth/client/cli/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cli

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestParseSigs(t *testing.T) {
cases := []struct {
name string
args []string
expErr bool
expNumSigs int
}{
{"no args", []string{}, true, 0},
{"empty args", []string{""}, true, 0},
{"too many args", []string{"foo", "bar"}, true, 0},
{"1 sig", []string{"foo"}, false, 1},
{"3 sigs", []string{"foo,bar,baz"}, false, 3},
}

for _, tc := range cases {
sigs, err := parseSigArgs(tc.args)
if tc.expErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, tc.expNumSigs, len(sigs))
}
}
}