Skip to content

Commit 60155c0

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

File tree

12 files changed

+1346
-101
lines changed

12 files changed

+1346
-101
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: 3 additions & 3 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
///
@@ -198,9 +198,9 @@ impl serde::Serialize for AllocationId {
198198
#[macro_export]
199199
macro_rules! allocation_id {
200200
() => {
201-
$crate::AllocationId::new($crate::alloy_primitives::Address::ZERO)
201+
$crate::AllocationId::new($crate::alloy::primitives::Address::ZERO)
202202
};
203203
($value:tt) => {
204-
$crate::AllocationId::new($crate::alloy_primitives::address!($value))
204+
$crate::AllocationId::new($crate::alloy::primitives::address!($value))
205205
};
206206
}

thegraph-core/src/attestation.rs

Lines changed: 19 additions & 15 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,18 +163,19 @@ 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::{b256, ChainId, B256},
176+
signers::{local::PrivateKeySigner, SignerSync},
177+
sol_types::Eip712Domain,
178+
};
175179

176180
use super::{create, eip712_domain, verify, Attestation};
177181
use crate::{address, deployment_id, Address, DeploymentId};

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: 2 additions & 2 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)]
@@ -275,7 +275,7 @@ pub const fn __parse_cid_v0_const(value: &str) -> B256 {
275275
mod tests {
276276
use std::str::FromStr;
277277

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

280280
use super::{
281281
format_cid_v0, parse_cid_v0_str, parse_hex_str, DeploymentId, ParseDeploymentIdError,

thegraph-core/src/indexer_id.rs

Lines changed: 3 additions & 3 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
///
@@ -198,9 +198,9 @@ impl serde::Serialize for IndexerId {
198198
#[macro_export]
199199
macro_rules! indexer_id {
200200
() => {
201-
$crate::IndexerId::new($crate::alloy_primitives::Address::ZERO)
201+
$crate::IndexerId::new($crate::alloy::primitives::Address::ZERO)
202202
};
203203
($value:tt) => {
204-
$crate::IndexerId::new($crate::alloy_primitives::address!($value))
204+
$crate::IndexerId::new($crate::alloy::primitives::address!($value))
205205
};
206206
}

thegraph-core/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Rust core modules for _The Graph_ network.
22
3-
#[doc(inline)]
4-
pub use alloy_primitives::{address, Address, BlockHash, BlockNumber, BlockTimestamp, ChainId};
3+
// Re-export `alloy` crate
54
#[doc(hidden)]
6-
pub use {::alloy_primitives, ::alloy_signer, ::alloy_sol_types};
5+
pub use ::alloy;
6+
// Re-export some primitive `alloy` types for convenience
7+
#[doc(inline)]
8+
pub use alloy::primitives::{address, Address, BlockHash, BlockNumber, BlockTimestamp, ChainId};
79

810
#[doc(inline)]
911
pub use self::{
@@ -15,6 +17,7 @@ pub use self::{
1517
proof_of_indexing::ProofOfIndexing,
1618
subgraph_id::{ParseSubgraphIdError, SubgraphId},
1719
};
20+
// Re-export functions required by the `deployment_id!(...)` and `subgraph_id!(...)` macros.
1821
#[doc(hidden)]
1922
pub use self::{deployment_id::__parse_cid_v0_const, subgraph_id::__parse_subgraph_id_const};
2023

0 commit comments

Comments
 (0)