Skip to content

Commit 83bd73f

Browse files
committed
fix(tap-agent): add data service filters to RAV and receipt queries
1 parent 4997fa7 commit 83bd73f

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
@@ -153,7 +153,6 @@ impl RavRead<tap_graph::v2::ReceiptAggregateVoucher> for TapAgentContext<Horizon
153153
type AdapterError = AdapterError;
154154

155155
async fn last_rav(&self) -> Result<Option<tap_graph::v2::SignedRav>, Self::AdapterError> {
156-
// TODO add data service filter
157156
let row = sqlx::query!(
158157
r#"
159158
SELECT
@@ -169,10 +168,12 @@ impl RavRead<tap_graph::v2::ReceiptAggregateVoucher> for TapAgentContext<Horizon
169168
WHERE
170169
collection_id = $1
171170
AND payer = $2
172-
AND service_provider = $3
171+
AND data_service = $3
172+
AND service_provider = $4
173173
"#,
174174
CollectionId::from(self.allocation_id).encode_hex(),
175175
self.sender.encode_hex(),
176+
self.indexer_address.encode_hex(),
176177
self.indexer_address.encode_hex()
177178
)
178179
.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
@@ -224,8 +224,6 @@ impl ReceiptRead<TapReceipt> for TapAgentContext<Horizon> {
224224
error: format!("{e:?}."),
225225
})?;
226226

227-
// TODO filter by data_service when we have multiple data services
228-
229227
let records = sqlx::query!(
230228
r#"
231229
SELECT
@@ -242,15 +240,17 @@ impl ReceiptRead<TapReceipt> for TapAgentContext<Horizon> {
242240
WHERE
243241
collection_id = $1
244242
AND payer = $2
245-
AND service_provider = $3
246-
AND signer_address IN (SELECT unnest($4::text[]))
247-
AND $5::numrange @> timestamp_ns
243+
AND data_service = $3
244+
AND service_provider = $4
245+
AND signer_address IN (SELECT unnest($5::text[]))
246+
AND $6::numrange @> timestamp_ns
248247
ORDER BY timestamp_ns ASC
249-
LIMIT $6
248+
LIMIT $7
250249
"#,
251250
CollectionId::from(self.allocation_id).encode_hex(),
252251
self.sender.encode_hex(),
253252
self.indexer_address.encode_hex(),
253+
self.indexer_address.encode_hex(),
254254
&signers,
255255
rangebounds_to_pgrange(timestamp_range_ns),
256256
(receipts_limit + 1) as i64,
@@ -364,13 +364,15 @@ impl ReceiptDelete for TapAgentContext<Horizon> {
364364
AND signer_address IN (SELECT unnest($2::text[]))
365365
AND $3::numrange @> timestamp_ns
366366
AND payer = $4
367-
AND service_provider = $5
367+
AND data_service = $5
368+
AND service_provider = $6
368369
"#,
369370
CollectionId::from(self.allocation_id).encode_hex(),
370371
&signers,
371372
rangebounds_to_pgrange(timestamp_ns),
372373
self.sender.encode_hex(),
373374
self.indexer_address.encode_hex(),
375+
self.indexer_address.encode_hex(),
374376
)
375377
.execute(&self.pgpool)
376378
.await?;

0 commit comments

Comments
 (0)