Skip to content

Commit fd8887c

Browse files
authored
refactor: create indexer-types and update re-exports (#497)
1 parent 462f8bc commit fd8887c

File tree

27 files changed

+110
-155
lines changed

27 files changed

+110
-155
lines changed

Cargo.lock

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"crates/query",
77
"crates/service",
88
"crates/tap-agent",
9+
"crates/types",
910
"crates/tests/tap-utils",
1011
]
1112
resolver = "2"

crates/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
indexer-config = { path = "../config" }
88
indexer-query = { path = "../query" }
9+
indexer-types = { path = "../types" }
910
thiserror.workspace = true
1011
async-trait.workspace = true
1112
alloy.workspace = true
@@ -20,7 +21,6 @@ prometheus.workspace = true
2021
thegraph-core.workspace = true
2122
axum.workspace = true
2223
lazy_static.workspace = true
23-
thegraph-graphql-http.workspace = true
2424
build-info.workspace = true
2525
graphql_client.workspace = true
2626

crates/common/src/allocations/monitor.rs renamed to crates/common/src/allocations.rs

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

4+
use crate::{client::SubgraphClient, watcher::new_watcher};
5+
use alloy::{primitives::Address, primitives::TxHash};
6+
use indexer_query::allocations_query::{self, AllocationsQuery};
7+
use indexer_types::Allocation;
48
use std::{
59
collections::HashMap,
6-
str::FromStr,
710
time::{Duration, SystemTime, UNIX_EPOCH},
811
};
9-
10-
use super::Allocation;
11-
use crate::{prelude::SubgraphClient, watcher::new_watcher};
12-
use alloy::primitives::TxHash;
13-
use indexer_query::allocations_query::{self, AllocationsQuery};
14-
use thegraph_core::{Address, DeploymentId};
1512
use tokio::sync::watch::Receiver;
1613

17-
impl TryFrom<allocations_query::AllocationFragment> for Allocation {
18-
type Error = anyhow::Error;
19-
20-
fn try_from(
21-
value: allocations_query::AllocationsQueryAllocations,
22-
) -> Result<Self, Self::Error> {
23-
Ok(Self {
24-
id: Address::from_str(&value.id)?,
25-
status: super::AllocationStatus::Null,
26-
subgraph_deployment: super::SubgraphDeployment {
27-
id: DeploymentId::from_str(&value.subgraph_deployment.id)?,
28-
denied_at: Some(value.subgraph_deployment.denied_at as u64),
29-
},
30-
indexer: Address::from_str(&value.indexer.id)?,
31-
allocated_tokens: value.allocated_tokens,
32-
created_at_epoch: value.created_at_epoch as u64,
33-
created_at_block_hash: value.created_at_block_hash.to_string(),
34-
closed_at_epoch: value.closed_at_epoch.map(|v| v as u64),
35-
closed_at_epoch_start_block_hash: None,
36-
previous_epoch_start_block_hash: None,
37-
poi: None,
38-
query_fee_rebates: None,
39-
query_fees_collected: None,
40-
})
41-
}
42-
}
43-
4414
/// An always up-to-date list of an indexer's active and recently closed allocations.
4515
pub async fn indexer_allocations(
4616
network_subgraph: &'static SubgraphClient,
@@ -118,7 +88,7 @@ mod test {
11888
"https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-arbitrum";
11989
use std::str::FromStr;
12090

121-
use crate::{prelude::SubgraphClient, subgraph_client::DeploymentDetails};
91+
use crate::client::{DeploymentDetails, SubgraphClient};
12292

12393
use super::*;
12494

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

4-
pub mod dispute_manager;
4+
mod monitor;
55
pub mod signer;
6-
pub mod signers;
6+
7+
pub use monitor::attestation_signers;
8+
pub use signer::{derive_key_pair, AttestationSigner};

crates/common/src/attestations/signers.rs renamed to crates/common/src/attestation/monitor.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ use thegraph_core::{Address, ChainId};
88
use tokio::sync::watch::Receiver;
99
use tracing::warn;
1010

11-
use crate::{
12-
prelude::{Allocation, AttestationSigner},
13-
watcher::join_and_map_watcher,
14-
};
11+
use crate::{attestation::signer::AttestationSigner, watcher::join_and_map_watcher};
12+
use indexer_types::Allocation;
1513

1614
/// An always up-to-date list of attestation signers, one for each of the indexer's allocations.
1715
pub fn attestation_signers(

crates/common/src/attestations/signer.rs renamed to crates/common/src/attestation/signer.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use alloy::{
1010
};
1111
use thegraph_core::{attestation, Address, Attestation, ChainId, DeploymentId};
1212

13-
use crate::prelude::Allocation;
13+
use indexer_types::Allocation;
1414

1515
pub fn derive_key_pair(
1616
indexer_mnemonic: &str,
@@ -121,10 +121,8 @@ mod tests {
121121
use std::str::FromStr;
122122
use test_log::test;
123123

124-
use crate::{
125-
prelude::{Allocation, AllocationStatus, SubgraphDeployment},
126-
test_vectors::DISPUTE_MANAGER_ADDRESS,
127-
};
124+
use crate::test_vectors::DISPUTE_MANAGER_ADDRESS;
125+
use indexer_types::{Allocation, AllocationStatus, SubgraphDeployment};
128126

129127
use super::*;
130128

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

4-
mod client;
54
mod monitor;
5+
mod subgraph_client;
66

7-
pub use client::{DeploymentDetails, Query, QueryVariables, SubgraphClient};
7+
pub use subgraph_client::{DeploymentDetails, SubgraphClient};
File renamed without changes.

crates/common/src/subgraph_client/client.rs renamed to crates/common/src/client/subgraph_client.rs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,75 +6,12 @@ use anyhow::anyhow;
66
use axum::body::Bytes;
77
use graphql_client::GraphQLQuery;
88
use reqwest::{header, Url};
9-
use serde_json::{Map, Value};
109
use thegraph_core::DeploymentId;
11-
use thegraph_graphql_http::{
12-
graphql::{Document, IntoDocument},
13-
http::request::{IntoRequestParameters, RequestParameters},
14-
};
1510
use tokio::sync::watch::Receiver;
1611
use tracing::warn;
1712

18-
#[derive(Clone)]
19-
pub struct Query {
20-
pub query: Document,
21-
pub variables: Map<String, Value>,
22-
}
23-
2413
pub type ResponseResult<T> = Result<T, anyhow::Error>;
2514

26-
impl Query {
27-
pub fn new(query: &str) -> Self {
28-
Self {
29-
query: query.into_document(),
30-
variables: Map::default(),
31-
}
32-
}
33-
34-
pub fn new_with_variables(
35-
query: impl IntoDocument,
36-
variables: impl Into<QueryVariables>,
37-
) -> Self {
38-
Self {
39-
query: query.into_document(),
40-
variables: variables.into().into(),
41-
}
42-
}
43-
}
44-
45-
pub struct QueryVariables(Map<String, Value>);
46-
47-
impl<'a, T> From<T> for QueryVariables
48-
where
49-
T: IntoIterator<Item = (&'a str, Value)>,
50-
{
51-
fn from(variables: T) -> Self {
52-
Self(
53-
variables
54-
.into_iter()
55-
.map(|(k, v)| (k.to_string(), v))
56-
.collect::<Map<_, _>>(),
57-
)
58-
}
59-
}
60-
61-
impl From<QueryVariables> for Map<String, Value> {
62-
fn from(variables: QueryVariables) -> Self {
63-
variables.0
64-
}
65-
}
66-
67-
impl IntoRequestParameters for Query {
68-
fn into_request_parameters(self) -> RequestParameters {
69-
RequestParameters {
70-
query: self.query.into_document(),
71-
variables: self.variables,
72-
extensions: Map::default(),
73-
operation_name: None,
74-
}
75-
}
76-
}
77-
7815
#[derive(Debug, Clone)]
7916
pub struct DeploymentDetails {
8017
pub deployment: Option<DeploymentId>,

0 commit comments

Comments
 (0)