Skip to content

Commit 77ffae6

Browse files
committed
refactor: update more fields to config crate in service
1 parent 57dd186 commit 77ffae6

File tree

3 files changed

+30
-48
lines changed

3 files changed

+30
-48
lines changed

common/src/indexer_service/http/indexer_service.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,12 @@ impl IndexerService {
208208

209209
let network_subgraph: &'static SubgraphClient = Box::leak(Box::new(SubgraphClient::new(
210210
http_client.clone(),
211-
options
212-
.config
213-
.graph_node
214-
.as_ref()
215-
.zip(options.config.subgraphs.network.config.deployment_id)
216-
.map(|(graph_node, deployment)| {
217-
DeploymentDetails::for_graph_node(
218-
&graph_node.status_url,
219-
&graph_node.query_base_url,
220-
deployment,
221-
)
222-
})
223-
.transpose()?,
211+
Some(DeploymentDetails {
212+
deployment: options.config.subgraphs.network.config.deployment_id,
213+
status_url: Some(options.config.graph_node.status_url.clone()),
214+
query_url: options.config.graph_node.query_url.clone(),
215+
query_auth_token: options.config.service.free_query_auth_token.clone(),
216+
}),
224217
DeploymentDetails::for_query_url_with_token(
225218
&options
226219
.config
@@ -270,26 +263,19 @@ impl IndexerService {
270263
let attestation_signers = attestation_signers(
271264
allocations.clone(),
272265
options.config.indexer.operator_mnemonic.to_string(),
273-
options.config.blockchain.chain_id as u64,
266+
options.config.blockchain.chain_id.clone() as u64,
274267
dispute_manager,
275268
)
276269
.await;
277270

278271
let escrow_subgraph: &'static SubgraphClient = Box::leak(Box::new(SubgraphClient::new(
279272
http_client,
280-
options
281-
.config
282-
.graph_node
283-
.as_ref()
284-
.zip(options.config.subgraphs.escrow.config.deployment_id)
285-
.map(|(graph_node, deployment)| {
286-
DeploymentDetails::for_graph_node(
287-
&graph_node.status_url,
288-
&graph_node.query_base_url,
289-
deployment,
290-
)
291-
})
292-
.transpose()?,
273+
Some(DeploymentDetails {
274+
deployment: options.config.subgraphs.escrow.config.deployment_id.clone(),
275+
status_url: Some(options.config.graph_node.status_url.clone()),
276+
query_url: options.config.graph_node.query_url.clone(),
277+
query_auth_token: options.config.service.free_query_auth_token.clone(),
278+
}),
293279
DeploymentDetails::for_query_url_with_token(
294280
&options.config.subgraphs.escrow.config.query_url.to_string(),
295281
options
@@ -331,13 +317,14 @@ impl IndexerService {
331317
&options
332318
.config
333319
.database
320+
.clone()
334321
.get_formated_postgres_url()
335322
.to_string(),
336323
)
337324
.await?;
338325

339326
let domain_separator = tap_eip712_domain(
340-
options.config.blockchain.chain_id as u64,
327+
options.config.blockchain.chain_id.clone() as u64,
341328
options.config.blockchain.receipts_verifier_address,
342329
);
343330
let indexer_context =

common/src/indexer_service/http/request_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ where
9090
{
9191
None => return Err(IndexerServiceError::Unauthorized),
9292
Some(ref token) => {
93-
if Some(token) != state.config.server.free_query_auth_token.as_ref() {
93+
if Some(token) != state.config.service.free_query_auth_token.as_ref() {
9494
return Err(IndexerServiceError::InvalidFreeQueryAuthToken);
9595
}
9696
}

service/src/service.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
use std::sync::Arc;
55
use std::time::Duration;
66

7-
use super::{config::Config, error::SubgraphServiceError, routes};
7+
use super::{error::SubgraphServiceError, routes};
88
use anyhow::anyhow;
99
use axum::{async_trait, routing::post, Json, Router};
1010
use indexer_common::indexer_service::http::{
1111
AttestationOutput, IndexerServiceImpl, IndexerServiceResponse,
1212
};
13-
use indexer_config::Config as MainConfig;
13+
use indexer_config::Config;
1414
use reqwest::Url;
1515
use serde_json::{json, Value};
1616
use sqlx::PgPool;
@@ -129,7 +129,7 @@ pub async fn run() -> anyhow::Result<()> {
129129
// Load the json-rpc service configuration, which is a combination of the
130130
// general configuration options for any indexer service and specific
131131
// options added for JSON-RPC
132-
let config = MainConfig::parse(indexer_config::ConfigPrefix::Service, cli.config.as_ref())
132+
let config = Config::parse(indexer_config::ConfigPrefix::Service, cli.config.as_ref())
133133
.map_err(|e| {
134134
error!(
135135
"Invalid configuration file `{}`: {}, if a value is missing you can also use \
@@ -151,32 +151,27 @@ pub async fn run() -> anyhow::Result<()> {
151151
// that is involved in serving requests
152152
let state = Arc::new(SubgraphServiceState {
153153
config: config.clone(),
154-
database: database::connect(&config.0.database.postgres_url).await,
154+
database: database::connect(
155+
&config
156+
.database
157+
.clone()
158+
.get_formated_postgres_url()
159+
.to_string(),
160+
)
161+
.await,
155162
cost_schema: routes::cost::build_schema().await,
156163
graph_node_client: reqwest::ClientBuilder::new()
157164
.tcp_nodelay(true)
158165
.timeout(Duration::from_secs(30))
159166
.build()
160167
.expect("Failed to init HTTP client for Graph Node"),
161-
graph_node_status_url: config
162-
.0
163-
.graph_node
164-
.as_ref()
165-
.expect("Config must have `common.graph_node.status_url` set")
166-
.status_url
167-
.clone(),
168-
graph_node_query_base_url: config
169-
.0
170-
.graph_node
171-
.as_ref()
172-
.expect("config must have `common.graph_node.query_url` set")
173-
.query_base_url
174-
.clone(),
168+
graph_node_status_url: config.graph_node.status_url.clone().to_string(),
169+
graph_node_query_base_url: config.graph_node.query_url.clone().to_string(),
175170
});
176171

177172
IndexerService::run(IndexerServiceOptions {
178173
release,
179-
config: config.0.clone(),
174+
config: config.clone(),
180175
url_namespace: "subgraphs",
181176
service_impl: SubgraphService::new(state.clone()),
182177
extra_routes: Router::new()

0 commit comments

Comments
 (0)