Skip to content

Commit 782dd67

Browse files
YashBitYash Bharti
andauthored
refactor: use tap_core::tap_eip712_domain (#376)
Co-authored-by: Yash Bharti <[email protected]>
1 parent 06644c5 commit 782dd67

File tree

10 files changed

+522
-468
lines changed

10 files changed

+522
-468
lines changed

Cargo.lock

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

common/src/graphql.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use regex::Regex;
77

88
/// There is no convenient function for filtering GraphQL executable documents
99
/// For sake of simplicity, use regex to filter graphql query string
10-
/// Return original string if the query is okay, otherwise error out with
11-
/// unsupported fields
10+
/// Return original string if the query is okay, otherwise error out with unsupported fields
1211
pub fn filter_supported_fields(
1312
query: &str,
1413
supported_root_fields: &HashSet<&str>,

common/src/indexer_service/http/indexer_service.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::{
5-
collections::HashMap, error::Error, fmt::Debug, net::SocketAddr, path::PathBuf, sync::Arc,
6-
time::Duration,
7-
};
8-
94
use alloy::dyn_abi::Eip712Domain;
10-
use alloy::sol_types::eip712_domain;
115
use anyhow;
126
use axum::extract::MatchedPath;
137
use axum::extract::Request as ExtractRequest;
@@ -25,7 +19,11 @@ use prometheus::TextEncoder;
2519
use reqwest::StatusCode;
2620
use serde::{de::DeserializeOwned, Serialize};
2721
use sqlx::postgres::PgPoolOptions;
28-
use tap_core::{manager::Manager, receipt::checks::CheckList};
22+
use std::{
23+
collections::HashMap, error::Error, fmt::Debug, net::SocketAddr, path::PathBuf, sync::Arc,
24+
time::Duration,
25+
};
26+
use tap_core::{manager::Manager, receipt::checks::CheckList, tap_eip712_domain};
2927
use thegraph_core::{Address, Attestation, DeploymentId};
3028
use thiserror::Error;
3129
use tokio::net::TcpListener;
@@ -293,12 +291,10 @@ impl IndexerService {
293291
.connect(&options.config.database.postgres_url)
294292
.await?;
295293

296-
let domain_separator = eip712_domain! {
297-
name: "TAP",
298-
version: "1",
299-
chain_id: options.config.tap.chain_id,
300-
verifying_contract: options.config.tap.receipts_verifier_address,
301-
};
294+
let domain_separator = tap_eip712_domain(
295+
options.config.tap.chain_id,
296+
options.config.tap.receipts_verifier_address,
297+
);
302298
let indexer_context =
303299
IndexerTapContext::new(database.clone(), domain_separator.clone()).await;
304300
let timestamp_error_tolerance =

common/src/tap.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ mod receipt_store;
2525

2626
pub struct IndexerTapContext {
2727
domain_separator: Arc<Eip712Domain>,
28-
2928
receipt_producer: Sender<DatabaseReceipt>,
3029
cancelation_token: CancellationToken,
3130
}

common/src/tap/checks/receipt_max_val_check.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,20 @@ impl Check for ReceiptMaxValueCheck {
3535
}
3636
#[cfg(test)]
3737
mod tests {
38-
use std::str::FromStr;
39-
use std::time::Duration;
40-
use std::time::SystemTime;
41-
42-
use alloy::dyn_abi::Eip712Domain;
4338
use alloy::primitives::Address;
4439
use alloy::signers::local::coins_bip39::English;
4540
use alloy::signers::local::MnemonicBuilder;
4641
use alloy::signers::local::PrivateKeySigner;
47-
use alloy::sol_types::eip712_domain;
42+
use std::str::FromStr;
43+
use std::time::Duration;
44+
use std::time::SystemTime;
4845

4946
use super::*;
47+
use crate::tap::Eip712Domain;
5048
use tap_core::{
5149
receipt::{checks::Check, state::Checking, Receipt, ReceiptWithState},
5250
signed_message::EIP712SignedMessage,
51+
tap_eip712_domain,
5352
};
5453

5554
fn create_signed_receipt_with_custom_value(value: u128) -> ReceiptWithState<Checking> {
@@ -60,12 +59,9 @@ mod tests {
6059
.unwrap()
6160
.build()
6261
.unwrap();
63-
let eip712_domain_separator: Eip712Domain = eip712_domain! {
64-
name: "TAP",
65-
version: "1",
66-
chain_id: 1,
67-
verifying_contract: Address:: from([0x11u8; 20]),
68-
};
62+
63+
let eip712_domain_separator: Eip712Domain =
64+
tap_eip712_domain(1, Address::from([0x11u8; 20]));
6965

7066
let timestamp = SystemTime::now()
7167
.duration_since(SystemTime::UNIX_EPOCH)

common/src/tap/checks/timestamp_check.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ mod tests {
4747
use std::str::FromStr;
4848

4949
use alloy::{
50-
dyn_abi::Eip712Domain,
5150
primitives::Address,
5251
signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner},
53-
sol_types::eip712_domain,
5452
};
5553

5654
use super::*;
55+
use crate::tap::Eip712Domain;
5756
use tap_core::{
5857
receipt::{checks::Check, state::Checking, Receipt, ReceiptWithState},
5958
signed_message::EIP712SignedMessage,
59+
tap_eip712_domain,
6060
};
6161

6262
fn create_signed_receipt_with_custom_timestamp(
@@ -69,12 +69,8 @@ mod tests {
6969
.unwrap()
7070
.build()
7171
.unwrap();
72-
let eip712_domain_separator: Eip712Domain = eip712_domain! {
73-
name: "TAP",
74-
version: "1",
75-
chain_id: 1,
76-
verifying_contract: Address:: from([0x11u8; 20]),
77-
};
72+
let eip712_domain_separator: Eip712Domain =
73+
tap_eip712_domain(1, Address::from([0x11u8; 20]));
7874
let value: u128 = 1234;
7975
let nonce: u64 = 10;
8076
let receipt = EIP712SignedMessage::new(

common/src/test_vectors.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use alloy::{
77
dyn_abi::Eip712Domain,
88
primitives::U256,
99
signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner},
10-
sol_types::eip712_domain,
1110
};
1211
use lazy_static::lazy_static;
1312
use tap_core::{
1413
receipt::{Receipt, SignedReceipt},
1514
signed_message::EIP712SignedMessage,
15+
tap_eip712_domain,
1616
};
1717
use thegraph_core::{Address, DeploymentId};
1818

@@ -252,12 +252,10 @@ lazy_static! {
252252
(wallet, address)
253253
};
254254

255-
pub static ref TAP_EIP712_DOMAIN: Eip712Domain = eip712_domain! {
256-
name: "TAP",
257-
version: "1",
258-
chain_id: 1,
259-
verifying_contract: Address::from([0x11u8; 20]),
260-
};
255+
pub static ref TAP_EIP712_DOMAIN: Eip712Domain = tap_eip712_domain(
256+
1,
257+
Address::from([0x11u8; 20])
258+
);
261259
}
262260

263261
/// Function to generate a signed receipt using the TAP_SIGNER wallet.

tap-agent/src/agent/sender_allocation.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ impl SenderAllocationState {
475475

476476
/// Request a RAV from the sender's TAP aggregator. Only one RAV request will be running at a
477477
/// time through the use of an internal guard.
478-
479478
async fn rav_requester_single(&mut self) -> Result<SignedRAV, RavError> {
480479
tracing::trace!("rav_requester_single()");
481480
let RAVRequest {

tap-agent/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use alloy::{dyn_abi::Eip712Domain, sol_types::eip712_domain};
4+
use alloy::dyn_abi::Eip712Domain;
55
use lazy_static::lazy_static;
6+
use tap_core::tap_eip712_domain;
67

78
use crate::config::Config;
89

910
lazy_static! {
1011
pub static ref CONFIG: Config = Config::from_cli().expect("Failed to load configuration");
11-
pub static ref EIP_712_DOMAIN: Eip712Domain = eip712_domain! {
12-
name: "TAP",
13-
version: "1",
14-
chain_id: CONFIG.receipts.receipts_verifier_chain_id,
15-
verifying_contract: CONFIG.receipts.receipts_verifier_address,
16-
};
12+
pub static ref EIP_712_DOMAIN: Eip712Domain = tap_eip712_domain(
13+
CONFIG.receipts.receipts_verifier_chain_id,
14+
CONFIG.receipts.receipts_verifier_address,
15+
);
1716
}
1817

1918
pub mod agent;

tap-agent/src/tap/test_utils.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::str::FromStr;
66
use alloy::{
77
primitives::hex::ToHexExt,
88
signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner},
9-
sol_types::eip712_domain,
109
};
1110
use bigdecimal::num_bigint::BigInt;
1211

@@ -20,6 +19,7 @@ use tap_core::{
2019
rav::{ReceiptAggregateVoucher, SignedRAV},
2120
receipt::{state::Checking, Receipt, ReceiptWithState, SignedReceipt},
2221
signed_message::EIP712SignedMessage,
22+
tap_eip712_domain,
2323
};
2424

2525
lazy_static! {
@@ -32,12 +32,8 @@ lazy_static! {
3232
pub static ref SENDER_3: (PrivateKeySigner, Address) = wallet(4);
3333
pub static ref SIGNER: (PrivateKeySigner, Address) = wallet(2);
3434
pub static ref INDEXER: (PrivateKeySigner, Address) = wallet(3);
35-
pub static ref TAP_EIP712_DOMAIN_SEPARATOR: Eip712Domain = eip712_domain! {
36-
name: "TAP",
37-
version: "1",
38-
chain_id: 1,
39-
verifying_contract: Address:: from([0x11u8; 20]),
40-
};
35+
pub static ref TAP_EIP712_DOMAIN_SEPARATOR: Eip712Domain =
36+
tap_eip712_domain(1, Address::from([0x11u8; 20]),);
4137
}
4238

4339
/// Fixture to generate a RAV using the wallet from `keys()`

0 commit comments

Comments
 (0)