Skip to content

Commit d232252

Browse files
committed
fix: expose dips price on config file
1 parent c193e64 commit d232252

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

crates/config/maximal-config-example.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,9 @@ max_receipts_per_request = 10000
159159
host = "0.0.0.0"
160160
port = "7601"
161161
allowed_payers = ["0x3333333333333333333333333333333333333333"]
162+
163+
price_per_entity = 1000
164+
165+
[dips.price_per_epoch]
166+
mainnet = 100
167+
hardhat = 100

crates/config/minimal-config-example.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,3 @@ receipts_verifier_address = "0x2222222222222222222222222222222222222222"
6363
# Key-Value of all senders and their aggregator endpoints
6464
0xdeadbeefcafebabedeadbeefcafebabedeadbeef = "https://example.com/aggregate-receipts"
6565
0x0123456789abcdef0123456789abcdef01234567 = "https://other.example.com/aggregate-receipts"
66-

crates/config/src/config.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use std::{
5-
collections::{HashMap, HashSet},
5+
collections::{BTreeMap, HashMap, HashSet},
66
env,
77
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
88
path::PathBuf,
@@ -396,6 +396,9 @@ pub struct DipsConfig {
396396
pub host: String,
397397
pub port: String,
398398
pub allowed_payers: Vec<Address>,
399+
400+
pub price_per_entity: u64,
401+
pub price_per_epoch: BTreeMap<String, u64>,
399402
}
400403

401404
impl Default for DipsConfig {
@@ -404,6 +407,8 @@ impl Default for DipsConfig {
404407
host: "0.0.0.0".to_string(),
405408
port: "7601".to_string(),
406409
allowed_payers: vec![],
410+
price_per_entity: 100,
411+
price_per_epoch: BTreeMap::new(),
407412
}
408413
}
409414
}
@@ -437,7 +442,12 @@ pub struct RavRequestConfig {
437442

438443
#[cfg(test)]
439444
mod tests {
440-
use std::{collections::HashSet, env, fs, path::PathBuf, str::FromStr};
445+
use std::{
446+
collections::{BTreeMap, HashMap, HashSet},
447+
env, fs,
448+
path::PathBuf,
449+
str::FromStr,
450+
};
441451

442452
use figment::value::Uncased;
443453
use sealed_test::prelude::*;
@@ -470,6 +480,11 @@ mod tests {
470480
allowed_payers: vec![Address(
471481
FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(),
472482
)],
483+
price_per_entity: 1000,
484+
price_per_epoch: BTreeMap::from_iter(vec![
485+
("mainnet".to_string(), 100),
486+
("hardhat".to_string(), 100),
487+
]),
473488
..Default::default()
474489
});
475490

crates/dips/src/price.rs

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

4-
use std::collections::HashMap;
4+
use std::collections::BTreeMap;
55

66
#[derive(Debug, Default)]
77
pub struct PriceCalculator {
8-
base_price_per_epoch: HashMap<String, u64>,
8+
base_price_per_epoch: BTreeMap<String, u64>,
99
price_per_entity: u64,
1010
}
1111

1212
impl PriceCalculator {
13+
pub fn new(base_price_per_epoch: BTreeMap<String, u64>, price_per_entity: u64) -> Self {
14+
Self {
15+
base_price_per_epoch,
16+
price_per_entity,
17+
}
18+
}
19+
1320
#[cfg(test)]
1421
pub fn for_testing() -> Self {
1522
Self {
16-
base_price_per_epoch: HashMap::from_iter(vec![("mainnet".to_string(), 200)]),
23+
base_price_per_epoch: BTreeMap::from_iter(vec![("mainnet".to_string(), 200)]),
1724
price_per_entity: 100,
1825
}
1926
}

crates/service/src/service.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ pub async fn run() -> anyhow::Result<()> {
130130
host,
131131
port,
132132
allowed_payers,
133+
price_per_entity,
134+
price_per_epoch,
133135
} = dips;
134136

135137
let addr = format!("{}:{}", host, port)
@@ -156,7 +158,7 @@ pub async fn run() -> anyhow::Result<()> {
156158
pool: database.clone(),
157159
}),
158160
ipfs_fetcher,
159-
price_calculator: PriceCalculator::default(),
161+
price_calculator: PriceCalculator::new(price_per_epoch.clone(), *price_per_entity),
160162
signer_validator: Arc::new(EscrowSignerValidator::new(watcher)),
161163
registry: Arc::new(registry),
162164
};

0 commit comments

Comments
 (0)