Skip to content

Commit 8b46dca

Browse files
committed
fix: make dips config optional
1 parent 2f12a14 commit 8b46dca

File tree

3 files changed

+45
-32
lines changed

3 files changed

+45
-32
lines changed

config/minimal-config-example.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,3 @@ receipts_verifier_address = "0x2222222222222222222222222222222222222222"
6464
0xdeadbeefcafebabedeadbeefcafebabedeadbeef = "https://example.com/aggregate-receipts"
6565
0x0123456789abcdef0123456789abcdef01234567 = "https://other.example.com/aggregate-receipts"
6666

67-
[dips]
68-
allowed_payers = ["0x3333333333333333333333333333333333333333"]

config/src/config.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct Config {
4141
pub blockchain: BlockchainConfig,
4242
pub service: ServiceConfig,
4343
pub tap: TapConfig,
44-
pub dips: DipsConfig,
44+
pub dips: Option<DipsConfig>,
4545
}
4646

4747
// Newtype wrapping Config to be able use serde_ignored with Figment
@@ -399,8 +399,9 @@ pub struct RavRequestConfig {
399399

400400
#[cfg(test)]
401401
mod tests {
402+
use alloy::primitives::FixedBytes;
402403
use sealed_test::prelude::*;
403-
use std::{env, fs, path::PathBuf};
404+
use std::{env, fs, path::PathBuf, str::FromStr};
404405
use tracing_test::traced_test;
405406

406407
use crate::{Config, ConfigPrefix};
@@ -419,11 +420,18 @@ mod tests {
419420
#[test]
420421
fn test_maximal_config() {
421422
// Generate full config by deserializing the minimal config and let the code fill in the defaults.
422-
let max_config = Config::parse(
423+
let mut max_config = Config::parse(
423424
ConfigPrefix::Service,
424425
Some(PathBuf::from("minimal-config-example.toml")).as_ref(),
425426
)
426427
.unwrap();
428+
max_config.dips = Some(crate::DipsConfig {
429+
allowed_payers: vec![thegraph_core::Address(
430+
FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(),
431+
)],
432+
cancellation_time_tolerance: None,
433+
});
434+
427435
let max_config_file: Config = toml::from_str(
428436
fs::read_to_string("maximal-config-example.toml")
429437
.unwrap()

service/src/service.rs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use axum::{
1616
use indexer_common::indexer_service::http::{
1717
AttestationOutput, IndexerServiceImpl, IndexerServiceResponse,
1818
};
19-
use indexer_config::Config;
19+
use indexer_config::{Config, DipsConfig};
2020
use reqwest::Url;
2121
use serde::{de::DeserializeOwned, Serialize};
2222
use serde_json::{json, Value};
@@ -180,37 +180,44 @@ pub async fn run() -> anyhow::Result<()> {
180180
let agreement_store: Arc<dyn AgreementStore> = Arc::new(InMemoryAgreementStore::default());
181181
let prices: Vec<Price> = vec![];
182182

183-
let schema = Schema::build(
184-
routes::dips::AgreementQuery {},
185-
routes::dips::AgreementMutation {
186-
expected_payee: config.indexer.indexer_address,
187-
allowed_payers: config.dips.allowed_payers.clone(),
188-
domain: eip712_domain(
189-
// 42161, // arbitrum
190-
config.blockchain.chain_id as u64,
191-
config.blockchain.receipts_verifier_address,
192-
),
193-
cancel_voucher_time_tolerance: config
194-
.dips
195-
.cancellation_time_tolerance
196-
.unwrap_or(Duration::from_secs(5)),
197-
},
198-
EmptySubscription,
199-
)
200-
.data(agreement_store)
201-
.data(prices)
202-
.finish();
183+
let mut router = Router::new()
184+
.route("/cost", post(routes::cost::cost))
185+
.route("/status", post(routes::status))
186+
.with_state(state.clone());
187+
188+
if let Some(DipsConfig {
189+
allowed_payers,
190+
cancellation_time_tolerance,
191+
}) = config.dips.as_ref()
192+
{
193+
let schema = Schema::build(
194+
routes::dips::AgreementQuery {},
195+
routes::dips::AgreementMutation {
196+
expected_payee: config.indexer.indexer_address,
197+
allowed_payers: allowed_payers.clone(),
198+
domain: eip712_domain(
199+
// 42161, // arbitrum
200+
config.blockchain.chain_id as u64,
201+
config.blockchain.receipts_verifier_address,
202+
),
203+
cancel_voucher_time_tolerance: cancellation_time_tolerance
204+
.unwrap_or(Duration::from_secs(5)),
205+
},
206+
EmptySubscription,
207+
)
208+
.data(agreement_store)
209+
.data(prices)
210+
.finish();
211+
212+
router = router.route("/dips", post_service(GraphQL::new(schema)));
213+
}
203214

204215
IndexerService::run(IndexerServiceOptions {
205216
release,
206217
config,
207218
url_namespace: "subgraphs",
208-
service_impl: SubgraphService::new(state.clone()),
209-
extra_routes: Router::new()
210-
.route("/cost", post(routes::cost::cost))
211-
.route("/status", post(routes::status))
212-
.route("/dips", post_service(GraphQL::new(schema)))
213-
.with_state(state),
219+
service_impl: SubgraphService::new(state),
220+
extra_routes: router,
214221
})
215222
.await
216223
}

0 commit comments

Comments
 (0)