Skip to content

Commit 443ce40

Browse files
committed
cargo fmt
1 parent b137a97 commit 443ce40

File tree

2 files changed

+96
-70
lines changed

2 files changed

+96
-70
lines changed

primitives/examples/get_cfg_response.rs

+58-58
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,68 @@ use serde_json::{from_value, json};
33

44
fn main() {
55
let json = json!({
6-
"max_channels": 512,
7-
"channels_find_limit": 200,
8-
"campaigns_find_limit": 200,
9-
"spendable_find_limit": 200,
10-
"wait_time": 500,
11-
"msgs_find_limit": 10,
12-
"analytics_find_limit": 5000,
13-
"analytics_maxtime": 20000,
14-
"heartbeat_time": 30000,
15-
"health_threshold_promilles": 950,
16-
"health_unsignable_promilles": 750,
17-
"propagation_timeout": 2000,
18-
"fetch_timeout": 5000,
19-
"all_campaigns_timeout": 5000,
20-
"channel_tick_timeout": 8000,
21-
"ip_rate_limit": {
22-
"type": "ip",
23-
"timeframe": 1200000
24-
},
25-
"creators_whitelist": [],
26-
"validators_whitelist": [],
27-
"admins": [
28-
"0x80690751969B234697e9059e04ed72195c3507fa"
29-
],
30-
"chain": {
31-
"Ganache #1337": {
32-
"chain_id": 1337,
33-
"rpc": "http://localhost:1337/",
34-
"outpace": "0xAbc27d46a458E2e49DaBfEf45ca74dEDBAc3DD06",
35-
"token": {
36-
"Mocked TOKEN 1337": {
37-
"min_campaign_budget": "1000000000000000000",
38-
"min_validator_fee": "1000000000000",
39-
"precision": 18,
40-
"address": "0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E"
41-
}
42-
}
43-
},
44-
"Ganache #1": {
45-
"chain_id": 1,
46-
"rpc": "http://localhost:8545/",
47-
"outpace": "0x26CBc2eAAe377f6Ac4b73a982CD1125eF4CEC96f",
48-
"token": {
49-
"Mocked TOKEN 1": {
50-
"min_campaign_budget": "1000000000000000000",
51-
"min_validator_fee": "1000000000000",
52-
"precision": 18,
53-
"address": "0x12a28f2bfBFfDf5842657235cC058242f40fDEa6"
54-
}
6+
"max_channels": 512,
7+
"channels_find_limit": 200,
8+
"campaigns_find_limit": 200,
9+
"spendable_find_limit": 200,
10+
"wait_time": 500,
11+
"msgs_find_limit": 10,
12+
"analytics_find_limit": 5000,
13+
"analytics_maxtime": 20000,
14+
"heartbeat_time": 30000,
15+
"health_threshold_promilles": 950,
16+
"health_unsignable_promilles": 750,
17+
"propagation_timeout": 2000,
18+
"fetch_timeout": 5000,
19+
"all_campaigns_timeout": 5000,
20+
"channel_tick_timeout": 8000,
21+
"ip_rate_limit": {
22+
"type": "ip",
23+
"timeframe": 1200000
24+
},
25+
"creators_whitelist": [],
26+
"validators_whitelist": [],
27+
"admins": [
28+
"0x80690751969B234697e9059e04ed72195c3507fa"
29+
],
30+
"chain": {
31+
"Ganache #1337": {
32+
"chain_id": 1337,
33+
"rpc": "http://localhost:1337/",
34+
"outpace": "0xAbc27d46a458E2e49DaBfEf45ca74dEDBAc3DD06",
35+
"token": {
36+
"Mocked TOKEN 1337": {
37+
"min_campaign_budget": "1000000000000000000",
38+
"min_validator_fee": "1000000000000",
39+
"precision": 18,
40+
"address": "0x2BCaf6968aEC8A3b5126FBfAb5Fd419da6E8AD8E"
5541
}
5642
}
5743
},
58-
"platform": {
59-
"url": "https://platform.adex.network/",
60-
"keep_alive_interval": 1200000
61-
},
62-
"limits": {
63-
"units_for_slot": {
64-
"max_campaigns_earning_from": 25,
65-
"global_min_impression_price": "1000000"
44+
"Ganache #1": {
45+
"chain_id": 1,
46+
"rpc": "http://localhost:8545/",
47+
"outpace": "0x26CBc2eAAe377f6Ac4b73a982CD1125eF4CEC96f",
48+
"token": {
49+
"Mocked TOKEN 1": {
50+
"min_campaign_budget": "1000000000000000000",
51+
"min_validator_fee": "1000000000000",
52+
"precision": 18,
53+
"address": "0x12a28f2bfBFfDf5842657235cC058242f40fDEa6"
54+
}
6655
}
6756
}
68-
});
57+
},
58+
"platform": {
59+
"url": "https://platform.adex.network/",
60+
"keep_alive_interval": 1200000
61+
},
62+
"limits": {
63+
"units_for_slot": {
64+
"max_campaigns_earning_from": 25,
65+
"global_min_impression_price": "1000000"
66+
}
67+
}
68+
});
6969
assert!(from_value::<Config>(json).is_ok());
7070
}

primitives/src/config.rs

+38-12
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use crate::{
44
util::ApiUrl,
55
Address, BigNum, ChainOf, ValidatorId,
66
};
7+
use duration::{milliseconds_to_std_duration, std_duration_to_milliseconds};
78
use once_cell::sync::Lazy;
89
use serde::{Deserialize, Serialize};
910
use std::{collections::HashMap, num::NonZeroU8, time::Duration};
1011
use thiserror::Error;
11-
use duration::{milliseconds_to_std_duration, std_duration_to_milliseconds};
1212

1313
pub use toml::de::Error as TomlError;
1414

@@ -78,7 +78,10 @@ pub struct Config {
7878
/// finish before running a new tick in the Validator Worker.
7979
///
8080
/// In milliseconds
81-
#[serde(deserialize_with = "milliseconds_to_std_duration", serialize_with = "std_duration_to_milliseconds")]
81+
#[serde(
82+
deserialize_with = "milliseconds_to_std_duration",
83+
serialize_with = "std_duration_to_milliseconds"
84+
)]
8285
pub wait_time: Duration,
8386
/// The maximum allowed limit of [`ValidatorMessage`](crate::sentry::ValidatorMessage)s per page
8487
/// returned by Sentry's GET `/v5/channel/0xXXX.../validator-messages` route.
@@ -109,12 +112,18 @@ pub struct Config {
109112
/// - GET `/v5/analytics/for-admin`
110113
///
111114
/// In milliseconds
112-
#[serde(deserialize_with = "milliseconds_to_std_duration", serialize_with = "std_duration_to_milliseconds")]
115+
#[serde(
116+
deserialize_with = "milliseconds_to_std_duration",
117+
serialize_with = "std_duration_to_milliseconds"
118+
)]
113119
pub analytics_maxtime: Duration,
114120
/// The amount of time that should have passed before sending a new heartbeat.
115121
///
116122
/// In milliseconds
117-
#[serde(deserialize_with = "milliseconds_to_std_duration", serialize_with = "std_duration_to_milliseconds")]
123+
#[serde(
124+
deserialize_with = "milliseconds_to_std_duration",
125+
serialize_with = "std_duration_to_milliseconds"
126+
)]
118127
pub heartbeat_time: Duration,
119128
/// The pro miles below which the [`ApproveState`](crate::validator::ApproveState)
120129
/// becomes **unhealthy** in the [`Channel`](crate::Channel)'s Follower.
@@ -133,7 +142,10 @@ pub struct Config {
133142
/// to a validator.
134143
///
135144
/// In milliseconds
136-
#[serde(deserialize_with = "milliseconds_to_std_duration", serialize_with = "std_duration_to_milliseconds")]
145+
#[serde(
146+
deserialize_with = "milliseconds_to_std_duration",
147+
serialize_with = "std_duration_to_milliseconds"
148+
)]
137149
pub propagation_timeout: Duration,
138150
/// The Client timeout for `SentryApi`.
139151
///
@@ -143,20 +155,29 @@ pub struct Config {
143155
/// [`Config.propagation_timeout`](Config::propagation_timeout).
144156
///
145157
/// In milliseconds
146-
#[serde(deserialize_with = "milliseconds_to_std_duration", serialize_with = "std_duration_to_milliseconds")]
158+
#[serde(
159+
deserialize_with = "milliseconds_to_std_duration",
160+
serialize_with = "std_duration_to_milliseconds"
161+
)]
147162
pub fetch_timeout: Duration,
148163
/// The Client timeout for `SentryApi` when collecting all channels
149164
/// and Validators using the `/campaign/list` route.
150165
///
151166
/// In milliseconds
152-
#[serde(deserialize_with = "milliseconds_to_std_duration", serialize_with = "std_duration_to_milliseconds")]
167+
#[serde(
168+
deserialize_with = "milliseconds_to_std_duration",
169+
serialize_with = "std_duration_to_milliseconds"
170+
)]
153171
pub all_campaigns_timeout: Duration,
154172
/// The timeout for a single tick of a [`Channel`](crate::Channel) in
155173
/// the Validator Worker.
156174
/// This timeout is applied to both the leader and follower ticks.
157175
///
158176
/// In milliseconds
159-
#[serde(deserialize_with = "milliseconds_to_std_duration", serialize_with = "std_duration_to_milliseconds")]
177+
#[serde(
178+
deserialize_with = "milliseconds_to_std_duration",
179+
serialize_with = "std_duration_to_milliseconds"
180+
)]
160181
pub channel_tick_timeout: Duration,
161182
/// The default IP rate limit that will be imposed if
162183
/// [`Campaign.event_submission`](crate::Campaign::event_submission) is [`None`].
@@ -215,7 +236,10 @@ impl Config {
215236
#[derive(Serialize, Deserialize, Debug, Clone)]
216237
pub struct PlatformConfig {
217238
pub url: ApiUrl,
218-
#[serde(deserialize_with = "milliseconds_to_std_duration", serialize_with = "std_duration_to_milliseconds")]
239+
#[serde(
240+
deserialize_with = "milliseconds_to_std_duration",
241+
serialize_with = "std_duration_to_milliseconds"
242+
)]
219243
pub keep_alive_interval: Duration,
220244
}
221245

@@ -253,10 +277,9 @@ pub struct Limits {
253277
pub units_for_slot: limits::UnitsForSlot,
254278
}
255279

256-
257280
pub mod duration {
281+
use serde::{Deserialize, Deserializer, Serializer};
258282
use std::time::Duration;
259-
use serde::{Serializer, Deserializer, Deserialize};
260283

261284
pub fn milliseconds_to_std_duration<'de, D>(deserializer: D) -> Result<Duration, D::Error>
262285
where
@@ -275,7 +298,10 @@ pub mod duration {
275298
Ok(Duration::from_millis(milliseconds))
276299
}
277300

278-
pub fn std_duration_to_milliseconds<S>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error>
301+
pub fn std_duration_to_milliseconds<S>(
302+
duration: &Duration,
303+
serializer: S,
304+
) -> Result<S::Ok, S::Error>
279305
where
280306
S: Serializer,
281307
{

0 commit comments

Comments
 (0)