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

[api] add rel filter on emerald/transactions #314

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ func (c *StorageClient) RuntimeTransactions(ctx context.Context, p apiTypes.GetR
QueryFactoryFromCtx(ctx).RuntimeTransactionsQuery(),
p.Block,
nil, // tx_hash; filter not supported by this endpoint
p.Rel,
p.Limit,
p.Offset,
)
Expand Down Expand Up @@ -1023,8 +1024,9 @@ func (c *StorageClient) RuntimeTransaction(ctx context.Context, txHash string) (
QueryFactoryFromCtx(ctx).RuntimeTransactionsQuery(),
nil, // block; filter not supported by this endpoint
txHash,
1, // limit
0, // offset
nil, // rel; filter not supported by this endpoint
1, // limit
0, // offset
).Scan(
&t.Round,
&t.Index,
Expand Down
30 changes: 22 additions & 8 deletions storage/client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,28 @@ func (qf QueryFactory) RuntimeBlocksQuery() string {

func (qf QueryFactory) RuntimeTransactionsQuery() string {
return fmt.Sprintf(`
SELECT round, tx_index, tx_hash, tx_eth_hash, timestamp, raw, result_raw
FROM %[1]s.runtime_transactions
WHERE (runtime = '%[2]s') AND
($1::bigint IS NULL OR round = $1::bigint) AND
($2::text IS NULL OR tx_hash = $2::text)
ORDER BY round DESC, tx_index DESC
LIMIT $3::bigint
OFFSET $4::bigint`, qf.chainID, qf.runtime)
SELECT
txs.round,
txs.tx_index,
txs.tx_hash,
txs.tx_eth_hash,
txs.timestamp,
txs.raw,
txs.result_raw
FROM %[1]s.runtime_transactions AS txs
LEFT JOIN %[1]s.runtime_related_transactions AS rel_accounts ON txs.round = rel_accounts.tx_round
AND txs.tx_index = rel_accounts.tx_index
AND txs.runtime = rel_accounts.runtime
-- When related_address ($3) 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.
AND $3::text IS NOT NULL
WHERE (txs.runtime = '%[2]s') AND
($1 IS NULL OR txs.round = $1::bigint) AND
($2 IS NULL OR txs.tx_hash = $2::text) AND
($3 IS NULL OR rel_accounts.account_address = $3::text)
ORDER BY txs.round DESC, txs.tx_index DESC
LIMIT $4::bigint
OFFSET $5::bigint`, qf.chainID, qf.runtime)
}

func (qf QueryFactory) RuntimeEventsQuery() string {
Expand Down