Skip to content

Commit f28f7f9

Browse files
committed
feat(thegraph-core): re-export alloy meta-crate
Signed-off-by: Lorenzo Delgado <[email protected]>
1 parent 1346749 commit f28f7f9

File tree

12 files changed

+1389
-116
lines changed

12 files changed

+1389
-116
lines changed

Cargo.lock

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

thegraph-core/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ rust-version = "1.71.1"
1010

1111
[features]
1212
default = ["serde"]
13+
alloy-signer-local = ["alloy/signer-local"]
1314
async-graphql-support = ["dep:async-graphql"]
14-
serde = ["dep:serde", "dep:serde_with", "alloy-primitives/serde"]
15+
serde = ["dep:serde", "dep:serde_with", "alloy/serde"]
1516
subgraph-client = [
1617
"serde",
1718
"dep:tracing",
@@ -24,8 +25,7 @@ subgraph-client = [
2425
]
2526

2627
[dependencies]
27-
alloy-primitives = "0.8"
28-
alloy-signer = { version = "=0.5", features = ["eip712"] }
28+
alloy = { version = "0.6", features = ["eip712", "signers", "sol-types"] }
2929
alloy-sol-types = "0.8"
3030
async-graphql = { version = "7.0", optional = true }
3131
bs58 = "0.5"
@@ -40,7 +40,7 @@ tracing = { version = "0.1.40", optional = true, default-features = false }
4040
url = "2.5"
4141

4242
[dev-dependencies]
43-
alloy-signer-local = "0.5.0"
43+
alloy = { version = "0.6", features = ["signer-local"] }
4444
assert_matches = "1.5.0"
4545
test-with = { version = "0.14.0", default-features = false }
4646
tokio = { version = "1.37.0", features = ["macros", "rt"] }

thegraph-core/src/allocation_id.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy_primitives::Address;
1+
use alloy::primitives::Address;
22

33
/// A unique identifier for an allocation: the allocation's Ethereum address.
44
///
@@ -189,18 +189,22 @@ impl serde::Serialize for AllocationId {
189189
/// If no argument is provided, the macro will create an `AllocationId` with the zero address:
190190
///
191191
/// ```rust
192-
/// use thegraph_core::{Address, allocation_id, AllocationId };
192+
/// use thegraph_core::{
193+
/// alloy::primitives::Address,
194+
/// allocation_id, AllocationId
195+
/// };
193196
///
194197
/// const ALLOCATION_ID: AllocationId = allocation_id!();
195198
///
196199
/// assert_eq!(ALLOCATION_ID, Address::ZERO);
197200
/// ```
198201
#[macro_export]
199-
macro_rules! allocation_id {
202+
#[doc(hidden)]
203+
macro_rules! __allocation_id {
200204
() => {
201-
$crate::AllocationId::new($crate::alloy_primitives::Address::ZERO)
205+
$crate::AllocationId::new($crate::alloy::primitives::Address::ZERO)
202206
};
203207
($value:tt) => {
204-
$crate::AllocationId::new($crate::alloy_primitives::address!($value))
208+
$crate::AllocationId::new($crate::alloy::primitives::address!($value))
205209
};
206210
}

thegraph-core/src/attestation.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//! Attestation types and functions for verifying attestations.
22
3-
use alloy_primitives::{b256, keccak256, Address, ChainId, Signature, B256};
4-
use alloy_signer::SignerSync;
5-
use alloy_sol_types::{eip712_domain, Eip712Domain, SolStruct};
3+
use alloy::{
4+
primitives::{
5+
b256, keccak256, normalize_v, Address, ChainId, PrimitiveSignature as Signature, B256,
6+
},
7+
signers::SignerSync,
8+
sol_types::{eip712_domain, Eip712Domain, SolStruct},
9+
};
610

711
use crate::{allocation_id::AllocationId, deployment_id::DeploymentId};
812

@@ -38,7 +42,7 @@ pub struct Attestation {
3842
pub v: u8,
3943
}
4044

41-
alloy_sol_types::sol! {
45+
alloy::sol_types::sol! {
4246
/// EIP-712 receipt struct for attestation signing.
4347
struct Receipt {
4448
bytes32 requestCID;
@@ -144,12 +148,11 @@ pub fn recover_allocation(
144148
domain: &Eip712Domain,
145149
attestation: &Attestation,
146150
) -> Result<AllocationId, VerificationError> {
147-
let signature = Signature::from_rs_and_parity(
148-
attestation.r.into(),
149-
attestation.s.into(),
150-
attestation.v as u64,
151-
)
152-
.map_err(|_| VerificationError::FailedSignerRecovery)?;
151+
// Recover the signature components
152+
let signature_parity =
153+
normalize_v(attestation.v as u64).ok_or(VerificationError::FailedSignerRecovery)?;
154+
let signature_r = attestation.r.into();
155+
let signature_s = attestation.s.into();
153156

154157
// Calculate the signing hash
155158
let msg = Receipt {
@@ -160,21 +163,22 @@ pub fn recover_allocation(
160163
let signing_hash = msg.eip712_signing_hash(domain);
161164

162165
// Recover the allocation ID from the signature
163-
signature
166+
Signature::new(signature_r, signature_s, signature_parity)
164167
.recover_address_from_prehash(&signing_hash)
165168
.map(Into::into)
166169
.map_err(|_| VerificationError::FailedSignerRecovery)
167170
}
168171

169172
#[cfg(test)]
170173
mod tests {
171-
use alloy_primitives::{b256, ChainId, B256};
172-
use alloy_signer::SignerSync;
173-
use alloy_signer_local::PrivateKeySigner;
174-
use alloy_sol_types::Eip712Domain;
174+
use alloy::{
175+
primitives::{address, b256, Address, ChainId, B256},
176+
signers::{local::PrivateKeySigner, SignerSync},
177+
sol_types::Eip712Domain,
178+
};
175179

176180
use super::{create, eip712_domain, verify, Attestation};
177-
use crate::{address, deployment_id, Address, DeploymentId};
181+
use crate::{deployment_id, DeploymentId};
178182

179183
const CHAIN_ID: ChainId = 1337;
180184
const DISPUTE_MANAGER_ADDRESS: Address = address!("16def7e0108a5467a106DBd7537F8591F470342e");

thegraph-core/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A pointer to a block in the chain.
22
3-
use alloy_primitives::{BlockHash, BlockNumber};
3+
use alloy::primitives::{BlockHash, BlockNumber};
44

55
/// A pointer to a block in the chain.
66
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]

thegraph-core/src/client/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub mod meta {
7979
}
8080

8181
pub mod page {
82-
use alloy_primitives::{BlockHash, BlockNumber};
82+
use alloy::primitives::{BlockHash, BlockNumber};
8383
use indoc::indoc;
8484
use serde::{ser::SerializeMap as _, Deserialize, Serialize, Serializer};
8585
use serde_json::value::RawValue;

thegraph-core/src/client/subgraph_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::{atomic::AtomicU64, Arc};
22

3-
use alloy_primitives::aliases::BlockNumber;
3+
use alloy::primitives::BlockNumber;
44
use serde::de::Deserialize;
55
use thegraph_graphql_http::{
66
graphql::IntoDocument, http::request::IntoRequestParameters, http_client::ResponseError,

thegraph-core/src/deployment_id.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy_primitives::B256;
1+
use alloy::primitives::B256;
22

33
/// Subgraph deployment ID parsing error.
44
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
@@ -234,7 +234,8 @@ fn parse_hex_str(value: &str) -> Result<DeploymentId, ParseDeploymentIdError> {
234234
/// assert_eq!(DEPLOYMENT_ID, DeploymentId::ZERO);
235235
/// ```
236236
#[macro_export]
237-
macro_rules! deployment_id {
237+
#[doc(hidden)]
238+
macro_rules! __deployment_id {
238239
() => {
239240
$crate::DeploymentId::ZERO
240241
};
@@ -275,11 +276,12 @@ pub const fn __parse_cid_v0_const(value: &str) -> B256 {
275276
mod tests {
276277
use std::str::FromStr;
277278

278-
use alloy_primitives::{b256, B256};
279+
use alloy::primitives::{b256, B256};
279280

280281
use super::{
281282
format_cid_v0, parse_cid_v0_str, parse_hex_str, DeploymentId, ParseDeploymentIdError,
282283
};
284+
use crate::deployment_id;
283285

284286
const VALID_CID: &str = "QmWmyoMoctfbAaiEs2G46gpeUmhqFRDW6KWo64y5r581Vz";
285287
const VALID_HEX: &str = "0x7d5a99f603f231d53a4f39d1521f98d2e8bb279cf29bebfd0687dc98458e7f89";

thegraph-core/src/indexer_id.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy_primitives::Address;
1+
use alloy::primitives::Address;
22

33
/// A unique identifier for an indexer: the indexer's Ethereum address.
44
///
@@ -189,18 +189,22 @@ impl serde::Serialize for IndexerId {
189189
/// If no argument is provided, the macro will create an `IndexerId` with the zero address:
190190
///
191191
/// ```rust
192-
/// use thegraph_core::{Address, indexer_id, IndexerId};
192+
/// use thegraph_core::{
193+
/// alloy::primitives::Address,
194+
/// indexer_id, IndexerId
195+
/// };
193196
///
194197
/// const INDEXER_ID: IndexerId = indexer_id!();
195198
///
196199
/// assert_eq!(INDEXER_ID, Address::ZERO);
197200
/// ```
198201
#[macro_export]
199-
macro_rules! indexer_id {
202+
#[doc(hidden)]
203+
macro_rules! __indexer_id {
200204
() => {
201-
$crate::IndexerId::new($crate::alloy_primitives::Address::ZERO)
205+
$crate::IndexerId::new($crate::alloy::primitives::Address::ZERO)
202206
};
203207
($value:tt) => {
204-
$crate::IndexerId::new($crate::alloy_primitives::address!($value))
208+
$crate::IndexerId::new($crate::alloy::primitives::address!($value))
205209
};
206210
}

thegraph-core/src/lib.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
//! Rust core modules for _The Graph_ network.
2+
//!
3+
//! # Re-exports
4+
//!
5+
//! This crate re-exports the `alloy` crate, which provides core types, traits and macros.
6+
//!
7+
//! As this crate exports types from the `alloy` crate, it is recommended to use the re-exported
8+
//! types and traits from this crate instead of importing the `alloy` crate directly in order to
9+
//! avoid future version conflicts.
210
3-
#[doc(inline)]
4-
pub use alloy_primitives::{address, Address, BlockHash, BlockNumber, BlockTimestamp, ChainId};
5-
#[doc(hidden)]
6-
pub use {::alloy_primitives, ::alloy_signer, ::alloy_sol_types};
11+
// Re-export `alloy` crate
12+
pub use alloy;
713

814
#[doc(inline)]
915
pub use self::{
@@ -15,6 +21,7 @@ pub use self::{
1521
proof_of_indexing::ProofOfIndexing,
1622
subgraph_id::{ParseSubgraphIdError, SubgraphId},
1723
};
24+
// Re-export functions required by the `deployment_id!(...)` and `subgraph_id!(...)` macros.
1825
#[doc(hidden)]
1926
pub use self::{deployment_id::__parse_cid_v0_const, subgraph_id::__parse_subgraph_id_const};
2027

@@ -27,3 +34,15 @@ mod deployment_id;
2734
mod indexer_id;
2835
mod proof_of_indexing;
2936
mod subgraph_id;
37+
38+
// Export macros
39+
#[doc(inline)]
40+
pub use __allocation_id as allocation_id;
41+
#[doc(inline)]
42+
pub use __deployment_id as deployment_id;
43+
#[doc(inline)]
44+
pub use __indexer_id as indexer_id;
45+
#[doc(inline, alias = "poi")]
46+
pub use __proof_of_indexing as proof_of_indexing;
47+
#[doc(inline)]
48+
pub use __subgraph_id as subgraph_id;

0 commit comments

Comments
 (0)