Skip to content

Commit fcf9e33

Browse files
mangasgusinacio
authored andcommitted
fix: make dips config optional
1 parent e3eb2e5 commit fcf9e33

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
@@ -419,9 +419,10 @@ pub struct RavRequestConfig {
419419

420420
#[cfg(test)]
421421
mod tests {
422+
use alloy::primitives::FixedBytes;
422423
use figment::value::Uncased;
423424
use sealed_test::prelude::*;
424-
use std::{env, fs, path::PathBuf};
425+
use std::{env, fs, path::PathBuf, str::FromStr};
425426
use tracing_test::traced_test;
426427

427428
use crate::{Config, ConfigPrefix};
@@ -440,11 +441,18 @@ mod tests {
440441
#[test]
441442
fn test_maximal_config() {
442443
// Generate full config by deserializing the minimal config and let the code fill in the defaults.
443-
let max_config = Config::parse(
444+
let mut max_config = Config::parse(
444445
ConfigPrefix::Service,
445446
Some(PathBuf::from("minimal-config-example.toml")).as_ref(),
446447
)
447448
.unwrap();
449+
max_config.dips = Some(crate::DipsConfig {
450+
allowed_payers: vec![thegraph_core::Address(
451+
FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(),
452+
)],
453+
cancellation_time_tolerance: None,
454+
});
455+
448456
let max_config_file: Config = toml::from_str(
449457
fs::read_to_string("maximal-config-example.toml")
450458
.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)