Skip to content

Commit

Permalink
fix: make dips config optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas authored and gusinacio committed Nov 8, 2024
1 parent e3eb2e5 commit fcf9e33
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
2 changes: 0 additions & 2 deletions config/minimal-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
14 changes: 11 additions & 3 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct Config {
pub blockchain: BlockchainConfig,
pub service: ServiceConfig,
pub tap: TapConfig,
pub dips: DipsConfig,
pub dips: Option<DipsConfig>,
}

// Newtype wrapping Config to be able use serde_ignored with Figment
Expand Down Expand Up @@ -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};
Expand All @@ -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()
Expand Down
61 changes: 34 additions & 27 deletions service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -180,37 +180,44 @@ pub async fn run() -> anyhow::Result<()> {
let agreement_store: Arc<dyn AgreementStore> = Arc::new(InMemoryAgreementStore::default());
let prices: Vec<Price> = 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
}

0 comments on commit fcf9e33

Please sign in to comment.