Skip to content

Commit

Permalink
[api] add rel filter on emerald/transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew7234 committed Feb 14, 2023
1 parent 96a1407 commit c5f8919
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ func (c *StorageClient) RuntimeTransactions(ctx context.Context, p apiTypes.GetR
ctx,
QueryFactoryFromCtx(ctx).RuntimeTransactionsQuery(),
p.Block,
nil, // tx_hash; filter not supported by this endpoint
p.Rel,
p.Limit,
p.Offset,
)
Expand Down
23 changes: 18 additions & 5 deletions storage/client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,25 @@ 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
SELECT
%[1]s.runtime_transactions.round,
%[1]s.runtime_transactions.tx_index,
%[1]s.runtime_transactions.tx_hash,
%[1]s.runtime_transactions.tx_eth_hash,
%[1]s.runtime_transactions.timestamp,
%[1]s.runtime_transactions.raw,
%[1]s.runtime_transactions.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
LEFT JOIN %[1]s.runtime_related_transactions ON %[1]s.runtime_transactions.round = %[1]s.runtime_related_transactions.tx_round
AND %[1]s.runtime_transactions.tx_index = %[1]s.runtime_related_transactions.tx_index
AND %[1]s.runtime_transactions.runtime = %[1]s.runtime_related_transactions.runtime
-- When related_address ($2) 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 $2::text IS NOT NULL
WHERE (%[1]s.runtime_transactions.runtime = '%[2]s') AND
($1::bigint IS NULL OR %[1]s.runtime_transactions.round = $1::bigint) AND
($2::text IS NULL OR %[1]s.runtime_related_transactions.account_address = $2::text)
ORDER BY %[1]s.runtime_transactions.round DESC, %[1]s.runtime_transactions.tx_index DESC
LIMIT $3::bigint
OFFSET $4::bigint`, qf.chainID, qf.runtime)
}
Expand Down

0 comments on commit c5f8919

Please sign in to comment.