From fcf9e33d7ccd30aa3918dd4e5f696d4477ed8e89 Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Thu, 7 Nov 2024 22:35:53 +0000 Subject: [PATCH] fix: make dips config optional --- config/minimal-config-example.toml | 2 - config/src/config.rs | 14 +++++-- service/src/service.rs | 61 +++++++++++++++++------------- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/config/minimal-config-example.toml b/config/minimal-config-example.toml index a9520a0b..61cd9460 100644 --- a/config/minimal-config-example.toml +++ b/config/minimal-config-example.toml @@ -64,5 +64,3 @@ receipts_verifier_address = "0x2222222222222222222222222222222222222222" 0xdeadbeefcafebabedeadbeefcafebabedeadbeef = "https://example.com/aggregate-receipts" 0x0123456789abcdef0123456789abcdef01234567 = "https://other.example.com/aggregate-receipts" -[dips] -allowed_payers = ["0x3333333333333333333333333333333333333333"] diff --git a/config/src/config.rs b/config/src/config.rs index 2a22e274..d34c366d 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -41,7 +41,7 @@ pub struct Config { pub blockchain: BlockchainConfig, pub service: ServiceConfig, pub tap: TapConfig, - pub dips: DipsConfig, + pub dips: Option, } // Newtype wrapping Config to be able use serde_ignored with Figment @@ -419,9 +419,10 @@ pub struct RavRequestConfig { #[cfg(test)] mod tests { + use alloy::primitives::FixedBytes; use figment::value::Uncased; use sealed_test::prelude::*; - use std::{env, fs, path::PathBuf}; + use std::{env, fs, path::PathBuf, str::FromStr}; use tracing_test::traced_test; use crate::{Config, ConfigPrefix}; @@ -440,11 +441,18 @@ mod tests { #[test] fn test_maximal_config() { // Generate full config by deserializing the minimal config and let the code fill in the defaults. - let max_config = Config::parse( + let mut max_config = Config::parse( ConfigPrefix::Service, Some(PathBuf::from("minimal-config-example.toml")).as_ref(), ) .unwrap(); + max_config.dips = Some(crate::DipsConfig { + allowed_payers: vec![thegraph_core::Address( + FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(), + )], + cancellation_time_tolerance: None, + }); + let max_config_file: Config = toml::from_str( fs::read_to_string("maximal-config-example.toml") .unwrap() diff --git a/service/src/service.rs b/service/src/service.rs index 2e3f8fe9..2a4b8328 100644 --- a/service/src/service.rs +++ b/service/src/service.rs @@ -16,7 +16,7 @@ use axum::{ use indexer_common::indexer_service::http::{ AttestationOutput, IndexerServiceImpl, IndexerServiceResponse, }; -use indexer_config::Config; +use indexer_config::{Config, DipsConfig}; use reqwest::Url; use serde::{de::DeserializeOwned, Serialize}; use serde_json::{json, Value}; @@ -180,37 +180,44 @@ pub async fn run() -> anyhow::Result<()> { let agreement_store: Arc = Arc::new(InMemoryAgreementStore::default()); let prices: Vec = vec![]; - let schema = Schema::build( - routes::dips::AgreementQuery {}, - routes::dips::AgreementMutation { - expected_payee: config.indexer.indexer_address, - allowed_payers: config.dips.allowed_payers.clone(), - domain: eip712_domain( - // 42161, // arbitrum - config.blockchain.chain_id as u64, - config.blockchain.receipts_verifier_address, - ), - cancel_voucher_time_tolerance: config - .dips - .cancellation_time_tolerance - .unwrap_or(Duration::from_secs(5)), - }, - EmptySubscription, - ) - .data(agreement_store) - .data(prices) - .finish(); + let mut router = Router::new() + .route("/cost", post(routes::cost::cost)) + .route("/status", post(routes::status)) + .with_state(state.clone()); + + if let Some(DipsConfig { + allowed_payers, + cancellation_time_tolerance, + }) = config.dips.as_ref() + { + let schema = Schema::build( + routes::dips::AgreementQuery {}, + routes::dips::AgreementMutation { + expected_payee: config.indexer.indexer_address, + allowed_payers: allowed_payers.clone(), + domain: eip712_domain( + // 42161, // arbitrum + config.blockchain.chain_id as u64, + config.blockchain.receipts_verifier_address, + ), + cancel_voucher_time_tolerance: cancellation_time_tolerance + .unwrap_or(Duration::from_secs(5)), + }, + EmptySubscription, + ) + .data(agreement_store) + .data(prices) + .finish(); + + router = router.route("/dips", post_service(GraphQL::new(schema))); + } IndexerService::run(IndexerServiceOptions { release, config, url_namespace: "subgraphs", - service_impl: SubgraphService::new(state.clone()), - extra_routes: Router::new() - .route("/cost", post(routes::cost::cost)) - .route("/status", post(routes::status)) - .route("/dips", post_service(GraphQL::new(schema))) - .with_state(state), + service_impl: SubgraphService::new(state), + extra_routes: router, }) .await }