Skip to content

Commit ca43d58

Browse files
committed
fix(tap-agent): add data service filters to RAV and receipt queries
1 parent 2839c74 commit ca43d58

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

crates/tap-agent/src/tap/context/rav.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ impl RavRead<tap_graph::v2::ReceiptAggregateVoucher> for TapAgentContext<Horizon
155155
type AdapterError = AdapterError;
156156

157157
async fn last_rav(&self) -> Result<Option<tap_graph::v2::SignedRav>, Self::AdapterError> {
158-
// TODO add data service filter
159158
let row = sqlx::query!(
160159
r#"
161160
SELECT
@@ -171,10 +170,12 @@ impl RavRead<tap_graph::v2::ReceiptAggregateVoucher> for TapAgentContext<Horizon
171170
WHERE
172171
collection_id = $1
173172
AND payer = $2
174-
AND service_provider = $3
173+
AND data_service = $3
174+
AND service_provider = $4
175175
"#,
176176
CollectionId::from(self.allocation_id).encode_hex(),
177177
self.sender.encode_hex(),
178+
self.indexer_address.encode_hex(),
178179
self.indexer_address.encode_hex()
179180
)
180181
.fetch_optional(&self.pgpool)

crates/tap-agent/src/tap/context/receipt.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ impl ReceiptRead<TapReceipt> for TapAgentContext<Horizon> {
226226
error: format!("{:?}.", e),
227227
})?;
228228

229-
// TODO filter by data_service when we have multiple data services
230-
231229
let records = sqlx::query!(
232230
r#"
233231
SELECT
@@ -244,15 +242,17 @@ impl ReceiptRead<TapReceipt> for TapAgentContext<Horizon> {
244242
WHERE
245243
collection_id = $1
246244
AND payer = $2
247-
AND service_provider = $3
248-
AND signer_address IN (SELECT unnest($4::text[]))
249-
AND $5::numrange @> timestamp_ns
245+
AND data_service = $3
246+
AND service_provider = $4
247+
AND signer_address IN (SELECT unnest($5::text[]))
248+
AND $6::numrange @> timestamp_ns
250249
ORDER BY timestamp_ns ASC
251-
LIMIT $6
250+
LIMIT $7
252251
"#,
253252
CollectionId::from(self.allocation_id).encode_hex(),
254253
self.sender.encode_hex(),
255254
self.indexer_address.encode_hex(),
255+
self.indexer_address.encode_hex(),
256256
&signers,
257257
rangebounds_to_pgrange(timestamp_range_ns),
258258
(receipts_limit + 1) as i64,
@@ -371,13 +371,15 @@ impl ReceiptDelete for TapAgentContext<Horizon> {
371371
AND signer_address IN (SELECT unnest($2::text[]))
372372
AND $3::numrange @> timestamp_ns
373373
AND payer = $4
374-
AND service_provider = $5
374+
AND data_service = $5
375+
AND service_provider = $6
375376
"#,
376377
CollectionId::from(self.allocation_id).encode_hex(),
377378
&signers,
378379
rangebounds_to_pgrange(timestamp_ns),
379380
self.sender.encode_hex(),
380381
self.indexer_address.encode_hex(),
382+
self.indexer_address.encode_hex(),
381383
)
382384
.execute(&self.pgpool)
383385
.await?;

0 commit comments

Comments
 (0)