Skip to content

Commit 5a43a57

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

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.7.2", features = [
3838
tracing = { version = "0.1.40", default-features = false }
3939
bigdecimal = "0.4.3"
4040
build-info = "0.0.38"
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
@@ -11,6 +11,7 @@ use axum::{
1111
};
1212
use axum_extra::TypedHeader;
1313
use reqwest::StatusCode;
14+
use tap_core::receipt::Context;
1415
use thegraph_core::DeploymentId;
1516
use tracing::trace;
1617

@@ -63,21 +64,18 @@ where
6364
.as_ref()
6465
.map(ToString::to_string)
6566
.unwrap_or_default();
66-
let _ = state
67-
.value_check_sender
68-
.tx_query
69-
.send(AgoraQuery {
70-
signature,
71-
deployment_id: manifest_id,
72-
query: request.query.clone(),
73-
variables,
74-
})
75-
.await;
67+
let mut ctx = Context::new();
68+
ctx.insert(AgoraQuery {
69+
signature,
70+
deployment_id: manifest_id,
71+
query: request.query.clone(),
72+
variables,
73+
});
7674

7775
// Verify the receipt and store it in the database
7876
state
7977
.tap_manager
80-
.verify_and_store_receipt(receipt)
78+
.verify_and_store_receipt(&ctx, receipt)
8179
.await
8280
.map_err(IndexerServiceError::ReceiptError)?;
8381

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 {
@@ -45,6 +49,7 @@ mod tests {
4549
use alloy::signers::local::MnemonicBuilder;
4650
use alloy::signers::local::PrivateKeySigner;
4751
use alloy::sol_types::eip712_domain;
52+
use tap_core::receipt::Context;
4853

4954
use super::*;
5055
use tap_core::{
@@ -96,20 +101,29 @@ mod tests {
96101
async fn test_receipt_lower_than_limit() {
97102
let signed_receipt = create_signed_receipt_with_custom_value(RECEIPT_LIMIT - 1);
98103
let timestamp_check = ReceiptMaxValueCheck::new(RECEIPT_LIMIT);
99-
assert!(timestamp_check.check(&signed_receipt).await.is_ok());
104+
assert!(timestamp_check
105+
.check(&Context::new(), &signed_receipt)
106+
.await
107+
.is_ok());
100108
}
101109

102110
#[tokio::test]
103111
async fn test_receipt_higher_than_limit() {
104112
let signed_receipt = create_signed_receipt_with_custom_value(RECEIPT_LIMIT + 1);
105113
let timestamp_check = ReceiptMaxValueCheck::new(RECEIPT_LIMIT);
106-
assert!(timestamp_check.check(&signed_receipt).await.is_err());
114+
assert!(timestamp_check
115+
.check(&Context::new(), &signed_receipt)
116+
.await
117+
.is_err());
107118
}
108119

109120
#[tokio::test]
110121
async fn test_receipt_same_as_limit() {
111122
let signed_receipt = create_signed_receipt_with_custom_value(RECEIPT_LIMIT);
112123
let timestamp_check = ReceiptMaxValueCheck::new(RECEIPT_LIMIT);
113-
assert!(timestamp_check.check(&signed_receipt).await.is_err());
124+
assert!(timestamp_check
125+
.check(&Context::new(), &signed_receipt)
126+
.await
127+
.is_err());
114128
}
115129
}

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()))?;
@@ -55,7 +59,7 @@ mod tests {
5559

5660
use super::*;
5761
use tap_core::{
58-
receipt::{checks::Check, state::Checking, Receipt, ReceiptWithState},
62+
receipt::{checks::Check, state::Checking, Context, Receipt, ReceiptWithState},
5963
signed_message::EIP712SignedMessage,
6064
};
6165

@@ -102,7 +106,10 @@ mod tests {
102106
let timestamp_ns = timestamp as u64;
103107
let signed_receipt = create_signed_receipt_with_custom_timestamp(timestamp_ns);
104108
let timestamp_check = TimestampCheck::new(Duration::from_secs(30));
105-
assert!(timestamp_check.check(&signed_receipt).await.is_ok());
109+
assert!(timestamp_check
110+
.check(&Context::new(), &signed_receipt)
111+
.await
112+
.is_ok());
106113
}
107114

108115
#[tokio::test]
@@ -115,7 +122,10 @@ mod tests {
115122
let timestamp_ns = timestamp as u64;
116123
let signed_receipt = create_signed_receipt_with_custom_timestamp(timestamp_ns);
117124
let timestamp_check = TimestampCheck::new(Duration::from_secs(30));
118-
assert!(timestamp_check.check(&signed_receipt).await.is_err());
125+
assert!(timestamp_check
126+
.check(&Context::new(), &signed_receipt)
127+
.await
128+
.is_err());
119129
}
120130

121131
#[tokio::test]
@@ -128,6 +138,9 @@ mod tests {
128138
let timestamp_ns = timestamp as u64;
129139
let signed_receipt = create_signed_receipt_with_custom_timestamp(timestamp_ns);
130140
let timestamp_check = TimestampCheck::new(Duration::from_secs(30));
131-
assert!(timestamp_check.check(&signed_receipt).await.is_err());
141+
assert!(timestamp_check
142+
.check(&Context::new(), &signed_receipt)
143+
.await
144+
.is_err());
132145
}
133146
}

0 commit comments

Comments
 (0)