diff --git a/storage/client/client.go b/storage/client/client.go index 602afca81..90966b99d 100644 --- a/storage/client/client.go +++ b/storage/client/client.go @@ -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, ) diff --git a/storage/client/queries.go b/storage/client/queries.go index 89cb96b5c..b2a81ac4f 100644 --- a/storage/client/queries.go +++ b/storage/client/queries.go @@ -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) }