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

rpc: add sort_order in tx_search #4253

Closed
wants to merge 18 commits into from

Conversation

princesinha19
Copy link
Contributor

@princesinha19 princesinha19 commented Dec 16, 2019

I have added order_by which can be "asc" or "desc" (should be in string format) in the tx_search RPC method.

Fixes: #3333

  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

rpc/core/tx.go Outdated Show resolved Hide resolved
rpc/client/httpclient.go Outdated Show resolved Hide resolved
rpc/client/localclient.go Outdated Show resolved Hide resolved
lite2/rpc/client.go Outdated Show resolved Hide resolved
lite2/proxy/routes.go Outdated Show resolved Hide resolved
rpc/client/httpclient.go Outdated Show resolved Hide resolved
@tac0turtle tac0turtle added T:enhancement Type: Enhancement C:rpc Component: JSON RPC, gRPC labels Dec 16, 2019
@tessr tessr changed the title rpc: Added sort_order in tx_search rpc: add sort_order in tx_search Dec 16, 2019
lite2/proxy/routes.go Outdated Show resolved Hide resolved
lite2/proxy/routes.go Outdated Show resolved Hide resolved
lite2/rpc/client.go Outdated Show resolved Hide resolved
rpc/client/httpclient.go Outdated Show resolved Hide resolved
rpc/client/interface.go Outdated Show resolved Hide resolved
rpc/client/localclient.go Outdated Show resolved Hide resolved
rpc/core/tx.go Outdated Show resolved Hide resolved
rpc/core/tx.go Outdated Show resolved Hide resolved
rpc/swagger/swagger.yaml Outdated Show resolved Hide resolved
@tac0turtle tac0turtle added feature Feature work that definitely changes system behavior and removed T:enhancement Type: Enhancement labels Dec 17, 2019
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. this needs an actual test case
  2. rpc: add sort_order in tx_search #4253 (comment)

CHANGELOG_PENDING.md Outdated Show resolved Hide resolved
rpc/client/rpc_test.go Outdated Show resolved Hide resolved
rpc/client/rpc_test.go Outdated Show resolved Hide resolved
rpc/client/rpc_test.go Outdated Show resolved Hide resolved
rpc/client/rpc_test.go Outdated Show resolved Hide resolved
rpc/client/rpc_test.go Outdated Show resolved Hide resolved
rpc/swagger/swagger.yaml Outdated Show resolved Hide resolved
rpc/swagger/swagger.yaml Outdated Show resolved Hide resolved
rpc/swagger/swagger.yaml Outdated Show resolved Hide resolved
@princesinha19
Copy link
Contributor Author

@melekes I have added test cases and removed unnecessary sorting from kv-store. Please have a look.

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. I have a few more comments though...

rpc/client/rpc_test.go Show resolved Hide resolved
rpc/client/rpc_test.go Show resolved Hide resolved
}
}

if orderBy == "desc" {
Copy link
Contributor

@melekes melekes Jan 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch orderBy {
case "desc":
...
case "asc":
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melekes actually this will create issue because by default we wanted to keep "asc" order but, if we will use switch case then if someone will not specify the correct order then the transaction will be unordered.

@@ -101,5 +103,29 @@ func TxSearch(ctx *rpctypes.Context, query string, prove bool, page, perPage int
}
}

if len(apiResults) > 1 {
for _, item := range apiResults {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain what this loop does? it looks like it just appends apiResults to itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct @melekes. But, it will remove the nil items present in the array. So, we will only get the txs which are not null. If we will allow nil items then, at the time of order by it will not able to sort correctly and it will fail because, the one item from (a,b) is nil.

@@ -221,60 +221,6 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) {
assert.Equal(t, []*types.TxResult{txResult}, results)
}

func TestTxSearchMultipleTxs(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we have removed #4253 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIght. But we still want to test "indexed fourth (to test we don't include txs with similar events)" use-case. See #2908

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should I take back #4253 (comment)?

// Transaction should be in the ascending order
result, err = c.TxSearch(fmt.Sprintf("tx.height >= 1"), true, 1, 30, "asc")
require.Nil(t, err, "%+v", err)
for k := 0; k < len(result.Txs)-1; k++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we only have one transaction, so this does not actually test what we want

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there are multiple. Throughout the test, many tx has been performed.

@@ -221,60 +221,6 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) {
assert.Equal(t, []*types.TxResult{txResult}, results)
}

func TestTxSearchMultipleTxs(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIght. But we still want to test "indexed fourth (to test we don't include txs with similar events)" use-case. See #2908

@melekes
Copy link
Contributor

melekes commented Jan 27, 2020

Closing in favor of #4342.

@melekes melekes closed this Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:rpc Component: JSON RPC, gRPC feature Feature work that definitely changes system behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rpc: add possibility of sorting /tx_search results
5 participants