Skip to content

Commit 421df79

Browse files
committed
fix(dips): allow specifying additional networks in config
1 parent d232252 commit 421df79

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

crates/config/maximal-config-example.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,6 @@ price_per_entity = 1000
165165
[dips.price_per_epoch]
166166
mainnet = 100
167167
hardhat = 100
168+
169+
[dips.additional_networks]
170+
eip155:1337 = "hardhat"

crates/config/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ pub struct DipsConfig {
399399

400400
pub price_per_entity: u64,
401401
pub price_per_epoch: BTreeMap<String, u64>,
402+
pub additional_networks: HashMap<String, String>,
402403
}
403404

404405
impl Default for DipsConfig {
@@ -409,6 +410,7 @@ impl Default for DipsConfig {
409410
allowed_payers: vec![],
410411
price_per_entity: 100,
411412
price_per_epoch: BTreeMap::new(),
413+
additional_networks: HashMap::new(),
412414
}
413415
}
414416
}
@@ -485,6 +487,10 @@ mod tests {
485487
("mainnet".to_string(), 100),
486488
("hardhat".to_string(), 100),
487489
]),
490+
additional_networks: HashMap::from([(
491+
"eip155:1337".to_string(),
492+
"hardhat".to_string(),
493+
)]),
488494
..Default::default()
489495
});
490496

crates/dips/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ pub async fn validate_and_create_agreement(
312312
price_calculator,
313313
signer_validator,
314314
registry,
315+
additional_networks,
315316
} = ctx.as_ref();
316317
let decoded_voucher = SignedIndexingAgreementVoucher::abi_decode(voucher.as_ref(), true)
317318
.map_err(|e| DipsError::AbiDecoding(e.to_string()))?;
@@ -340,7 +341,10 @@ pub async fn validate_and_create_agreement(
340341

341342
let network = match registry.get_network_by_id(&metadata.chainId) {
342343
Some(network) => network.id.clone(),
343-
None => return Err(DipsError::UnsupportedChainId(metadata.chainId)),
344+
None => match additional_networks.get(&metadata.chainId) {
345+
Some(network) => network.clone(),
346+
None => return Err(DipsError::UnsupportedChainId(metadata.chainId)),
347+
},
344348
};
345349

346350
let offered_epoch_price = metadata.basePricePerEpoch;

crates/dips/src/server.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::sync::Arc;
4+
use std::{collections::HashMap, sync::Arc};
55

66
use async_trait::async_trait;
77
use graph_networks_registry::NetworksRegistry;
@@ -31,6 +31,7 @@ pub struct DipsServerContext {
3131
pub price_calculator: PriceCalculator,
3232
pub signer_validator: Arc<dyn SignerValidator>,
3333
pub registry: Arc<NetworksRegistry>,
34+
pub additional_networks: Arc<HashMap<String, String>>,
3435
}
3536

3637
impl DipsServerContext {
@@ -48,6 +49,7 @@ impl DipsServerContext {
4849
price_calculator: PriceCalculator::for_testing(),
4950
signer_validator: Arc::new(signers::NoopSignerValidator),
5051
registry: Arc::new(test_registry()),
52+
additional_networks: Arc::new(HashMap::new()),
5153
})
5254
}
5355

@@ -61,6 +63,7 @@ impl DipsServerContext {
6163
price_calculator: PriceCalculator::for_testing(),
6264
signer_validator: Arc::new(signers::EscrowSignerValidator::mock(accounts).await),
6365
registry: Arc::new(crate::registry::test_registry()),
66+
additional_networks: Arc::new(HashMap::new()),
6467
})
6568
}
6669

@@ -76,6 +79,7 @@ impl DipsServerContext {
7679
price_calculator: PriceCalculator::for_testing(),
7780
signer_validator: Arc::new(signers::EscrowSignerValidator::mock(accounts).await),
7881
registry: Arc::new(test_registry()),
82+
additional_networks: Arc::new(HashMap::new()),
7983
})
8084
}
8185
}

crates/service/src/service.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub async fn run() -> anyhow::Result<()> {
132132
allowed_payers,
133133
price_per_entity,
134134
price_per_epoch,
135+
additional_networks,
135136
} = dips;
136137

137138
let addr = format!("{}:{}", host, port)
@@ -161,6 +162,7 @@ pub async fn run() -> anyhow::Result<()> {
161162
price_calculator: PriceCalculator::new(price_per_epoch.clone(), *price_per_entity),
162163
signer_validator: Arc::new(EscrowSignerValidator::new(watcher)),
163164
registry: Arc::new(registry),
165+
additional_networks: Arc::new(additional_networks.clone()),
164166
};
165167

166168
let dips = DipsServer {

0 commit comments

Comments
 (0)