Skip to content

Commit

Permalink
api/transactions: Filtering by multiple method types
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Feb 27, 2025
1 parent 0e1223e commit 9251c91
Show file tree
Hide file tree
Showing 16 changed files with 11,341 additions and 16 deletions.
1 change: 1 addition & 0 deletions .changelog/915.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
api: Support filtering transaction by multiple method types
12 changes: 10 additions & 2 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,12 @@ paths:
example: *block_height_1
- in: query
name: method
style: form
explode: false
schema:
allOf: [$ref: '#/components/schemas/ConsensusTxMethod']
type: array
items:
allOf: [$ref: '#/components/schemas/ConsensusTxMethod']
description: A filter on transaction method.
- in: query
name: sender
Expand Down Expand Up @@ -913,8 +917,12 @@ paths:
best-effort basis. For example, it inspects ERC20 methods inside `evm.Call` txs.
- in: query
name: method
style: form
explode: false
schema:
type: string
type: array
items:
type: string
description: |
A filter on the runtime transaction method.
Expand Down
24 changes: 10 additions & 14 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ const (
LEFT JOIN chain.accounts_related_transactions AS art ON
(t.block = art.tx_block) AND
(t.tx_index = art.tx_index) AND
($3::text IS NULL OR t.method = art.method) AND
($3::text[] IS NULL OR t.method = ANY($3::text[])) AND
-- When related_address ($5) is NULL and hence we do no filtering on it, avoid the join altogether.
-- Otherwise, every tx will be returned as many times as there are related addresses for it.
($5::text IS NOT NULL)
WHERE
($1::text IS NULL OR t.tx_hash = $1::text) AND
($2::bigint IS NULL OR t.block = $2::bigint) AND
($3::text IS NULL OR t.method = $3::text) AND
($3::text[] IS NULL OR t.method = ANY($3::text[])) AND
($4::text IS NULL OR t.sender = $4::text) AND
($5::text IS NULL OR art.account_address = $5::text) AND
($6::timestamptz IS NULL OR b.time >= $6::timestamptz) AND
Expand Down Expand Up @@ -566,7 +566,7 @@ const (
(txs.runtime = rel.runtime) AND
(txs.round = rel.tx_round) AND
(txs.tx_index = rel.tx_index) AND
($5::text IS NULL OR txs.method = rel.method AND txs.likely_native_transfer = rel.likely_native_transfer) AND
($5::text[] IS NULL OR txs.method = rel.method AND txs.likely_native_transfer = rel.likely_native_transfer) AND
-- When related_address ($4) is NULL and hence we do no filtering on it, avoid the join altogether.
-- Otherwise, every tx will be returned as many times as there are related addresses for it.
($4::text IS NOT NULL)
Expand All @@ -576,20 +576,16 @@ const (
($3::text IS NULL OR txs.tx_hash = $3::text OR txs.tx_eth_hash = $3::text) AND
($4::text IS NULL OR rel.account_address = $4::text) AND
(
CASE
-- No filtering on method.
WHEN $5::text IS NULL THEN
TRUE
-- No filtering on method.
$5::text[] IS NULL OR
(
-- Special case to return are 'likely to be native transfers'.
WHEN $5::text = 'native_transfers' THEN
txs.likely_native_transfer
('native_transfers' = ANY($5::text[]) AND txs.likely_native_transfer) OR
-- Special case to return all evm.Calls that are likely not native transfers.
WHEN $5::text = 'evm.Call_no_native' THEN
(txs.method = 'evm.Call' AND NOT txs.likely_native_transfer)
('evm.Call_no_native' = ANY($5::text[]) AND txs.method = 'evm.Call' AND NOT txs.likely_native_transfer) OR
-- Regular case.
ELSE
(txs.method = $5::text)
END
(txs.method = ANY($5::text[]))
)
) AND
($6::timestamptz IS NULL OR txs.timestamp >= $6::timestamptz) AND
($7::timestamptz IS NULL OR txs.timestamp < $7::timestamptz)
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e_regression/common_test_cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ commonTestCases=(
'active_accounts_window /v1/consensus/stats/active_accounts?window_step_seconds=300'
'active_accounts_emerald /v1/emerald/stats/active_accounts'
'txs /v1/consensus/transactions'
'txs_by_method /v1/consensus/transactions?method=staking.Transfer'
'txs_by_multiple_methods /v1/consensus/transactions?method=registry.RegisterNode,staking.Transfer'
'validators /v1/consensus/validators?limit=200'
'emerald_blocks /v1/emerald/blocks'
'emerald_txs /v1/emerald/transactions'
'emerald_txs_by_method /v1/emerald/transactions?method=consensus.Withdraw'
'emerald_txs_native_transfers /v1/emerald/transactions?method=native_transfers'
'emerald_txs_evm_call_no_native /v1/emerald/transactions?method=evm.Call_no_native'
'emerald_txs_evm_call /v1/emerald/transactions?method=evm.Call'
'emerald_txs_by_multiple_methods /v1/emerald/transactions?method=consensus.Withdraw,evm.Call_no_native'
'emerald_events /v1/emerald/events'
'emerald_events_by_type /v1/emerald/events?type=accounts.transfer'
'emerald_tokens /v1/emerald/evm_tokens'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"is_total_count_clipped": false,
"total_count": 0,
"transactions": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Origin
Date: UNINTERESTING
Content-Length: UNINTERESTING

159 changes: 159 additions & 0 deletions tests/e2e_regression/damask/expected/txs_by_method.body
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"is_total_count_clipped": false,
"total_count": 8,
"transactions": [
{
"block": 8049946,
"body": {
"amount": "10000000",
"to": "oasis1qz068qtggv6kdstymnvqm46rpv6p6tk6pueffdqu"
},
"fee": "100",
"gas_limit": "1263",
"hash": "4defe2afa3abbd4668958e360e184c73381e8b99ebb8082b911f6b28c811da97",
"index": 0,
"method": "staking.Transfer",
"nonce": 10,
"sender": "oasis1qrqnh093w0pv8asfmc37pyal6yn2h4cnwvdqtzm0",
"success": true,
"timestamp": "2022-04-11T12:44:08Z"
},
{
"block": 8049935,
"body": {
"amount": "10000000",
"to": "oasis1qz068qtggv6kdstymnvqm46rpv6p6tk6pueffdqu"
},
"fee": "0",
"gas_limit": "1263",
"hash": "b40bd05e4f7f0f9700b9934449019ecc340a8af8f505cdebc5adcf3d265c2660",
"index": 0,
"method": "staking.Transfer",
"nonce": 9,
"sender": "oasis1qrqnh093w0pv8asfmc37pyal6yn2h4cnwvdqtzm0",
"success": true,
"timestamp": "2022-04-11T12:43:05Z"
},
{
"block": 8049891,
"body": {
"amount": "100000000",
"to": "oasis1qrqnh093w0pv8asfmc37pyal6yn2h4cnwvdqtzm0"
},
"fee": "0",
"gas_limit": "1264",
"hash": "a116e6343d076569695f0a7a539e38990dcd1c553e94ce3149821673e7f6a07c",
"index": 0,
"method": "staking.Transfer",
"nonce": 8,
"sender": "oasis1qrqnh093w0pv8asfmc37pyal6yn2h4cnwvdqtzm0",
"success": true,
"timestamp": "2022-04-11T12:38:50Z"
},
{
"block": 8049872,
"body": {
"amount": "1000000",
"to": "oasis1qz068qtggv6kdstymnvqm46rpv6p6tk6pueffdqu"
},
"error": {
"code": 9,
"message": "staking: amount is lower than the minimum transfer amount",
"module": "staking"
},
"fee": "0",
"gas_limit": "1263",
"hash": "75a09c999ae3535a661be4f7def83d6165a9555ec7af74cf3963c41f1e657f88",
"index": 0,
"method": "staking.Transfer",
"nonce": 7,
"sender": "oasis1qrqnh093w0pv8asfmc37pyal6yn2h4cnwvdqtzm0",
"success": false,
"timestamp": "2022-04-11T12:37:00Z"
},
{
"block": 8049424,
"body": {
"amount": "100000",
"to": "oasis1qp6pu7sr822u3mecyt3vtzm54wq2rl5ezg5gutvz"
},
"error": {
"code": 9,
"message": "staking: amount is lower than the minimum transfer amount",
"module": "staking"
},
"fee": "0",
"gas_limit": "1263",
"hash": "f7a03e0912d355901ee794e5fec79a6b4c91363fc27d953596ee6de5c1492798",
"index": 0,
"method": "staking.Transfer",
"nonce": 11,
"sender": "oasis1qqnk4au603zs94k0d0n7c0hkx8t4p6r87s60axru",
"success": false,
"timestamp": "2022-04-11T11:52:24Z"
},
{
"block": 8049393,
"body": {
"amount": "100000",
"to": "oasis1qr8znzva3h28hausy7n3fput0fn80sajeywmwp5y"
},
"error": {
"code": 9,
"message": "staking: amount is lower than the minimum transfer amount",
"module": "staking"
},
"fee": "0",
"gas_limit": "1264",
"hash": "7fe023700667850e13b1f416b07e45ff95cf36f2e05221a7d6ef8bfc484b0614",
"index": 0,
"method": "staking.Transfer",
"nonce": 237,
"sender": "oasis1qr8znzva3h28hausy7n3fput0fn80sajeywmwp5y",
"success": false,
"timestamp": "2022-04-11T11:49:14Z"
},
{
"block": 8049349,
"body": {
"amount": "1000000",
"to": "oasis1qr8znzva3h28hausy7n3fput0fn80sajeywmwp5y"
},
"error": {
"code": 9,
"message": "staking: amount is lower than the minimum transfer amount",
"module": "staking"
},
"fee": "0",
"gas_limit": "1264",
"hash": "20e0bb3ca2c4f46577faeabd47b25ca6eb8815acafc77df2a4969d249636447c",
"index": 0,
"method": "staking.Transfer",
"nonce": 236,
"sender": "oasis1qr8znzva3h28hausy7n3fput0fn80sajeywmwp5y",
"success": false,
"timestamp": "2022-04-11T11:44:34Z"
},
{
"block": 8049343,
"body": {
"amount": "100000",
"to": "oasis1qr8znzva3h28hausy7n3fput0fn80sajeywmwp5y"
},
"error": {
"code": 9,
"message": "staking: amount is lower than the minimum transfer amount",
"module": "staking"
},
"fee": "0",
"gas_limit": "1264",
"hash": "ad659789abf19ef8430a0a07606789b94fd85659880c399df1c9cf1b6c8c9ae6",
"index": 0,
"method": "staking.Transfer",
"nonce": 235,
"sender": "oasis1qr8znzva3h28hausy7n3fput0fn80sajeywmwp5y",
"success": false,
"timestamp": "2022-04-11T11:43:55Z"
}
]
}
6 changes: 6 additions & 0 deletions tests/e2e_regression/damask/expected/txs_by_method.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Origin
Date: UNINTERESTING
Transfer-Encoding: chunked

Loading

0 comments on commit 9251c91

Please sign in to comment.