Skip to content

Commit

Permalink
feat: update tap agent to latest subgraph client
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis committed Dec 4, 2023
1 parent c70ebfc commit 4e6401e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 38 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tap-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tap_core = "0.7.0"
thiserror = "1.0.44"
tokio = { version = "1.33.0" }
thegraph = { git = "https://github.com/edgeandnode/toolshed", branch = "main" }
graphql-http = { git = "https://github.com/edgeandnode/toolshed", branch = "main" }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3", features = [
"env-filter",
Expand Down
72 changes: 34 additions & 38 deletions tap-agent/src/tap/receipt_checks_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use alloy_primitives::Address;
use async_trait::async_trait;
use ethereum_types::U256;
use eventuals::{timer, Eventual, EventualExt};
use indexer_common::subgraph_client::SubgraphClient;
use serde_json::json;
use indexer_common::subgraph_client::{Query, SubgraphClient};
use sqlx::PgPool;
use tap_core::adapters::receipt_checks_adapter::ReceiptChecksAdapter as ReceiptChecksAdapterTrait;
use tap_core::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt};
Expand Down Expand Up @@ -153,45 +152,42 @@ impl ReceiptChecksAdapter {
timer(Duration::from_millis(escrow_subgraph_polling_interval_ms)).map_with_retry(
move |_| async move {
let response = escrow_subgraph
.query::<TransactionsResponse>(&json!({
"query": r#"
query (
$sender_id: ID!,
$receiver_id: ID!,
$allocation_id: String!
) {
transactions(
where: {
and: [
{ type: "redeem" }
{ sender_: { id: $sender_id } }
{ receiver_: { id: $receiver_id } }
{ allocationID: $allocation_id }
]
}
) {
allocationID
sender {
id
}
}
.query::<TransactionsResponse>(Query::new_with_variables(
r#"
query (
$sender_id: ID!,
$receiver_id: ID!,
$allocation_id: String!
) {
transactions(
where: {
and: [
{ type: "redeem" }
{ sender_: { id: $sender_id } }
{ receiver_: { id: $receiver_id } }
{ allocationID: $allocation_id }
]
}
"#,
"variables": {
"sender_id": sender_address.to_string(),
"receiver_id": indexer_address.to_string(),
"allocation_id": allocation_id.to_string(),
}
}))
) {
allocationID
sender {
id
}
}
}
"#,
[
("sender_id", sender_address.to_string().into()),
("receiver_id", indexer_address.to_string().into()),
("allocation_id", allocation_id.to_string().into()),
],
))
.await
.map_err(|e| e.to_string())?;
let response = response.data.ok_or_else(|| {
format!(
"No data found in escrow subgraph response for allocation {} and sender {}",
allocation_id, sender_address
)
})?;
Ok(!response.transactions.is_empty())

response
.map_err(|e| e.to_string())
.map(|data| !data.transactions.is_empty())
},
move |error: String| {
error!(
Expand Down

0 comments on commit 4e6401e

Please sign in to comment.