Skip to content

Commit

Permalink
feat: Query txs by signature and by address+seq (backport cosmos#9750) (
Browse files Browse the repository at this point in the history
cosmos#9782)

* feat: Query txs by signature and by address+seq (cosmos#9750)

<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

Closes: cosmos#9741

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit 7c19434)

# Conflicts:
#	CHANGELOG.md
#	x/auth/client/cli/query.go

* Fix conflicts

* Fix cl

* Fix conflicts

Co-authored-by: Amaury <[email protected]>
  • Loading branch information
mergify[bot] and amaury1093 authored Oct 12, 2021
1 parent cec8828 commit 60abb40
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 74 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Features

* [\#9750](https://github.com/cosmos/cosmos-sdk/pull/9750) Emit events for tx signature and sequence, so clients can now query txs by signature (`tx.signature='<base64_sig>'`) or by address and sequence combo (`tx.acc_seq='<addr>/<seq>'`).

### Improvements

* (cli) [\#9717](https://github.com/cosmos/cosmos-sdk/pull/9717) Added CLI flag `--output json/text` to `tx` cli commands.
Expand Down
1 change: 0 additions & 1 deletion types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ var (

AttributeKeyAccountSequence = "acc_seq"
AttributeKeySignature = "signature"
AttributeKeyFee = "fee"

EventTypeMessage = "message"

Expand Down
6 changes: 3 additions & 3 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ $ %s query txs --%s 'message.sender=cosmos1...&message.action=withdraw_delegator
func QueryTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "tx --type=[hash|acc_seq|signature] [hash|acc_seq|signature]",
Short: "Query for a transaction by hash, \"<addr>/<seq>\" combination or comma-separated signatures in a committed block",
Short: "Query for a transaction by hash, addr++seq combination or signature in a committed block",
Long: strings.TrimSpace(fmt.Sprintf(`
Example:
$ %s query tx <hash>
$ %s query tx --%s=%s <addr>/<sequence>
$ %s query tx --%s=%s <sig1_base64>,<sig2_base64...>
$ %s query tx --%s=%s <addr>:<sequence>
$ %s query tx --%s=%s <sig1_base64,sig2_base64...>
`,
version.AppName,
version.AppName, flagType, typeAccSeq,
Expand Down
70 changes: 0 additions & 70 deletions x/auth/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,76 +425,6 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmdByEvents() {
}
}

func (s *IntegrationTestSuite) TestCLIQueryTxsCmdByEvents() {
val := s.network.Validators[0]

account2, err := val.ClientCtx.Keyring.Key("newAccount2")
s.Require().NoError(err)

sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)

// Send coins.
out, err := s.createBankMsg(
val, account2.GetAddress(),
sdk.NewCoins(sendTokens),
)
s.Require().NoError(err)
var txRes sdk.TxResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))
s.Require().NoError(s.network.WaitForNextBlock())

// Query the tx by hash to get the inner tx.
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, authcli.QueryTxCmd(), []string{txRes.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)})
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes))

testCases := []struct {
name string
args []string
expectEmpty bool
}{
{
"fee event happy case",
[]string{
fmt.Sprintf("--events=tx.fee=%s",
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
false,
},
{
"no matching fee event",
[]string{
fmt.Sprintf("--events=tx.fee=%s",
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(0))).String()),
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
true,
},
}

for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
cmd := authcli.QueryTxsByEventsCmd()
clientCtx := val.ClientCtx

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)

var result sdk.SearchTxsResult
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &result))

if tc.expectEmpty {
s.Require().Equal(0, len(result.Txs))
} else {
s.Require().NotEqual(0, len(result.Txs))
s.Require().NotNil(result.Txs[0])
}
})
}
}

func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
val1 := s.network.Validators[0]

Expand Down

0 comments on commit 60abb40

Please sign in to comment.