Skip to content

Commit 0e9c6ac

Browse files
committed
feat: use new context to pass query
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 2086893 commit 0e9c6ac

File tree

13 files changed

+134
-107
lines changed

13 files changed

+134
-107
lines changed

Cargo.lock

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sqlx = { version = "0.8.2", features = [
3838
tracing = { version = "0.1.40", default-features = false }
3939
bigdecimal = "0.4.3"
4040
build-info = "0.0.39"
41-
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "ff856d9", default-features = false }
41+
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "3fe6bc2", default-features = false }
4242
tracing-subscriber = { version = "0.3", features = [
4343
"json",
4444
"env-filter",

common/src/indexer_service/http/request_handler.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use axum_extra::TypedHeader;
1313
use lazy_static::lazy_static;
1414
use prometheus::{register_counter_vec, register_histogram_vec, CounterVec, HistogramVec};
1515
use reqwest::StatusCode;
16+
use tap_core::receipt::Context;
1617
use thegraph_core::DeploymentId;
1718
use tracing::trace;
1819

@@ -126,16 +127,13 @@ where
126127
.as_ref()
127128
.map(ToString::to_string)
128129
.unwrap_or_default();
129-
let _ = state
130-
.value_check_sender
131-
.tx_query
132-
.send(AgoraQuery {
133-
signature,
134-
deployment_id: manifest_id,
135-
query: query_body.query.clone(),
136-
variables,
137-
})
138-
.await;
130+
let mut ctx = Context::new();
131+
ctx.insert(AgoraQuery {
132+
signature,
133+
deployment_id: manifest_id,
134+
query: query_body.query.clone(),
135+
variables,
136+
});
139137

140138
// recover the signer address
141139
// get escrow accounts from eventual
@@ -168,7 +166,7 @@ where
168166
// Verify the receipt and store it in the database
169167
state
170168
.tap_manager
171-
.verify_and_store_receipt(receipt)
169+
.verify_and_store_receipt(&ctx, receipt)
172170
.await
173171
.inspect_err(|_| {
174172
FAILED_RECEIPT

common/src/tap/checks/allocation_eligible.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ impl AllocationEligible {
2727
}
2828
#[async_trait::async_trait]
2929
impl Check for AllocationEligible {
30-
async fn check(&self, receipt: &ReceiptWithState<Checking>) -> CheckResult {
30+
async fn check(
31+
&self,
32+
_: &tap_core::receipt::Context,
33+
receipt: &ReceiptWithState<Checking>,
34+
) -> CheckResult {
3135
let allocation_id = receipt.signed_receipt().message.allocation_id;
3236
if !self
3337
.indexer_allocations

common/src/tap/checks/deny_list_check.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ impl DenyListCheck {
150150

151151
#[async_trait::async_trait]
152152
impl Check for DenyListCheck {
153-
async fn check(&self, receipt: &ReceiptWithState<Checking>) -> CheckResult {
153+
async fn check(
154+
&self,
155+
_: &tap_core::receipt::Context,
156+
receipt: &ReceiptWithState<Checking>,
157+
) -> CheckResult {
154158
let receipt_signer = receipt
155159
.signed_receipt()
156160
.recover_signer(&self.domain_separator)
@@ -195,7 +199,7 @@ mod tests {
195199
use std::str::FromStr;
196200

197201
use alloy::hex::ToHexExt;
198-
use tap_core::receipt::ReceiptWithState;
202+
use tap_core::receipt::{Context, ReceiptWithState};
199203

200204
use crate::test_vectors::{self, create_signed_receipt, TAP_SENDER};
201205

@@ -241,7 +245,10 @@ mod tests {
241245
let checking_receipt = ReceiptWithState::new(signed_receipt);
242246

243247
// Check that the receipt is rejected
244-
assert!(deny_list_check.check(&checking_receipt).await.is_err());
248+
assert!(deny_list_check
249+
.check(&Context::new(), &checking_receipt)
250+
.await
251+
.is_err());
245252
}
246253

247254
#[sqlx::test(migrations = "../migrations")]
@@ -255,7 +262,10 @@ mod tests {
255262
// Check that the receipt is valid
256263
let checking_receipt = ReceiptWithState::new(signed_receipt);
257264

258-
deny_list_check.check(&checking_receipt).await.unwrap();
265+
deny_list_check
266+
.check(&Context::new(), &checking_receipt)
267+
.await
268+
.unwrap();
259269

260270
// Add the sender to the denylist
261271
sqlx::query!(
@@ -271,7 +281,10 @@ mod tests {
271281

272282
// Check that the receipt is rejected
273283
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
274-
assert!(deny_list_check.check(&checking_receipt).await.is_err());
284+
assert!(deny_list_check
285+
.check(&Context::new(), &checking_receipt)
286+
.await
287+
.is_err());
275288

276289
// Remove the sender from the denylist
277290
sqlx::query!(
@@ -287,6 +300,9 @@ mod tests {
287300

288301
// Check that the receipt is valid again
289302
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
290-
deny_list_check.check(&checking_receipt).await.unwrap();
303+
deny_list_check
304+
.check(&Context::new(), &checking_receipt)
305+
.await
306+
.unwrap();
291307
}
292308
}

common/src/tap/checks/receipt_max_val_check.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ impl ReceiptMaxValueCheck {
2020

2121
#[async_trait::async_trait]
2222
impl Check for ReceiptMaxValueCheck {
23-
async fn check(&self, receipt: &ReceiptWithState<Checking>) -> CheckResult {
23+
async fn check(
24+
&self,
25+
_: &tap_core::receipt::Context,
26+
receipt: &ReceiptWithState<Checking>,
27+
) -> CheckResult {
2428
let receipt_value = receipt.signed_receipt().message.value;
2529

2630
if receipt_value < self.receipt_max_value {
@@ -42,6 +46,7 @@ mod tests {
4246
use std::str::FromStr;
4347
use std::time::Duration;
4448
use std::time::SystemTime;
49+
use tap_core::receipt::Context;
4550

4651
use super::*;
4752
use crate::tap::Eip712Domain;
@@ -92,20 +97,29 @@ mod tests {
9297
async fn test_receipt_lower_than_limit() {
9398
let signed_receipt = create_signed_receipt_with_custom_value(RECEIPT_LIMIT - 1);
9499
let timestamp_check = ReceiptMaxValueCheck::new(RECEIPT_LIMIT);
95-
assert!(timestamp_check.check(&signed_receipt).await.is_ok());
100+
assert!(timestamp_check
101+
.check(&Context::new(), &signed_receipt)
102+
.await
103+
.is_ok());
96104
}
97105

98106
#[tokio::test]
99107
async fn test_receipt_higher_than_limit() {
100108
let signed_receipt = create_signed_receipt_with_custom_value(RECEIPT_LIMIT + 1);
101109
let timestamp_check = ReceiptMaxValueCheck::new(RECEIPT_LIMIT);
102-
assert!(timestamp_check.check(&signed_receipt).await.is_err());
110+
assert!(timestamp_check
111+
.check(&Context::new(), &signed_receipt)
112+
.await
113+
.is_err());
103114
}
104115

105116
#[tokio::test]
106117
async fn test_receipt_same_as_limit() {
107118
let signed_receipt = create_signed_receipt_with_custom_value(RECEIPT_LIMIT);
108119
let timestamp_check = ReceiptMaxValueCheck::new(RECEIPT_LIMIT);
109-
assert!(timestamp_check.check(&signed_receipt).await.is_err());
120+
assert!(timestamp_check
121+
.check(&Context::new(), &signed_receipt)
122+
.await
123+
.is_err());
110124
}
111125
}

common/src/tap/checks/sender_balance_check.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ impl SenderBalanceCheck {
3030

3131
#[async_trait::async_trait]
3232
impl Check for SenderBalanceCheck {
33-
async fn check(&self, receipt: &ReceiptWithState<Checking>) -> CheckResult {
33+
async fn check(
34+
&self,
35+
_: &tap_core::receipt::Context,
36+
receipt: &ReceiptWithState<Checking>,
37+
) -> CheckResult {
3438
let escrow_accounts_snapshot = self.escrow_accounts.value_immediate().unwrap_or_default();
3539

3640
let receipt_signer = receipt

common/src/tap/checks/timestamp_check.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ impl TimestampCheck {
2323

2424
#[async_trait::async_trait]
2525
impl Check for TimestampCheck {
26-
async fn check(&self, receipt: &ReceiptWithState<Checking>) -> CheckResult {
26+
async fn check(
27+
&self,
28+
_: &tap_core::receipt::Context,
29+
receipt: &ReceiptWithState<Checking>,
30+
) -> CheckResult {
2731
let timestamp_now = SystemTime::now()
2832
.duration_since(SystemTime::UNIX_EPOCH)
2933
.map_err(|e| CheckError::Failed(e.into()))?;
@@ -54,7 +58,7 @@ mod tests {
5458
use super::*;
5559
use crate::tap::Eip712Domain;
5660
use tap_core::{
57-
receipt::{checks::Check, state::Checking, Receipt, ReceiptWithState},
61+
receipt::{checks::Check, state::Checking, Context, Receipt, ReceiptWithState},
5862
signed_message::EIP712SignedMessage,
5963
tap_eip712_domain,
6064
};
@@ -98,7 +102,10 @@ mod tests {
98102
let timestamp_ns = timestamp as u64;
99103
let signed_receipt = create_signed_receipt_with_custom_timestamp(timestamp_ns);
100104
let timestamp_check = TimestampCheck::new(Duration::from_secs(30));
101-
assert!(timestamp_check.check(&signed_receipt).await.is_ok());
105+
assert!(timestamp_check
106+
.check(&Context::new(), &signed_receipt)
107+
.await
108+
.is_ok());
102109
}
103110

104111
#[tokio::test]
@@ -111,7 +118,10 @@ mod tests {
111118
let timestamp_ns = timestamp as u64;
112119
let signed_receipt = create_signed_receipt_with_custom_timestamp(timestamp_ns);
113120
let timestamp_check = TimestampCheck::new(Duration::from_secs(30));
114-
assert!(timestamp_check.check(&signed_receipt).await.is_err());
121+
assert!(timestamp_check
122+
.check(&Context::new(), &signed_receipt)
123+
.await
124+
.is_err());
115125
}
116126

117127
#[tokio::test]
@@ -124,6 +134,9 @@ mod tests {
124134
let timestamp_ns = timestamp as u64;
125135
let signed_receipt = create_signed_receipt_with_custom_timestamp(timestamp_ns);
126136
let timestamp_check = TimestampCheck::new(Duration::from_secs(30));
127-
assert!(timestamp_check.check(&signed_receipt).await.is_err());
137+
assert!(timestamp_check
138+
.check(&Context::new(), &signed_receipt)
139+
.await
140+
.is_err());
128141
}
129142
}

0 commit comments

Comments
 (0)