From 4e6401ea5db39b8ef8ba8ce4daa63bf1ab44d678 Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann Date: Thu, 30 Nov 2023 11:26:21 +0100 Subject: [PATCH] feat: update tap agent to latest subgraph client --- Cargo.lock | 1 + tap-agent/Cargo.toml | 1 + tap-agent/src/tap/receipt_checks_adapter.rs | 72 ++++++++++----------- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ffea64e0..e85a4e03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3129,6 +3129,7 @@ dependencies = [ "ethereum-types", "ethers-signers", "eventuals", + "graphql-http", "indexer-common", "jsonrpsee 0.20.2", "lazy_static", diff --git a/tap-agent/Cargo.toml b/tap-agent/Cargo.toml index e2f220f4..d5dd4c4d 100644 --- a/tap-agent/Cargo.toml +++ b/tap-agent/Cargo.toml @@ -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", diff --git a/tap-agent/src/tap/receipt_checks_adapter.rs b/tap-agent/src/tap/receipt_checks_adapter.rs index 5df552dd..e0f9c406 100644 --- a/tap-agent/src/tap/receipt_checks_adapter.rs +++ b/tap-agent/src/tap/receipt_checks_adapter.rs @@ -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}; @@ -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::(&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::(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!(