Skip to content

Commit 8bd5a40

Browse files
committed
GH-598: little reassurance on scan intervals parsing and some cosmetics
1 parent 93e3d7e commit 8bd5a40

3 files changed

Lines changed: 39 additions & 39 deletions

File tree

masq/src/commands/configuration_command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ impl ConfigurationCommand {
166166
let scan_intervals = Self::preprocess_combined_parameters({
167167
let s_i = &configuration.scan_intervals;
168168
&[
169-
("Pending payable:", &s_i.pending_payable_sec, "s"),
170169
("Payable:", &s_i.payable_sec, "s"),
170+
("Pending payable:", &s_i.pending_payable_sec, "s"),
171171
("Receivable:", &s_i.receivable_sec, "s"),
172172
]
173173
});
@@ -397,8 +397,8 @@ mod tests {
397397
| Exit byte rate: 129,000,000 wei\n\
398398
| Exit service rate: 160,000,000 wei\n\
399399
|Scan intervals: \n\
400-
| Pending payable: 150,500 s\n\
401400
| Payable: 155,000 s\n\
401+
| Pending payable: 150,500 s\n\
402402
| Receivable: 250,666 s\n"
403403
)
404404
.replace('|', "")
@@ -494,8 +494,8 @@ mod tests {
494494
| Exit byte rate: 20 wei\n\
495495
| Exit service rate: 30 wei\n\
496496
|Scan intervals: \n\
497-
| Pending payable: 1,000 s\n\
498497
| Payable: 1,000 s\n\
498+
| Pending payable: 1,000 s\n\
499499
| Receivable: 1,000 s\n",
500500
)
501501
.replace('|', "")

node/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ cmake-build-debug/
7373
# IntelliJ
7474
out/
7575

76+
# Local IDE database configuration
77+
.idea/db-forest-config.xml
78+
7679
# mpeltonen/sbt-idea plugin
7780
.idea_modules/
7881

node/src/sub_lib/combined_parameters.rs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::fmt;
1313
use std::fmt::Display;
1414
use std::time::Duration;
1515

16-
macro_rules! initiate_struct{
16+
macro_rules! initialize_struct{
1717
($struct_type: ident, $hash_map: expr, $($field:literal),+) =>{
1818
paste!{
1919
$struct_type{
@@ -119,40 +119,37 @@ impl CombinedParams {
119119
delimiter: char,
120120
expected_collection: &[(&str, CombinedParamsDataTypes)],
121121
) -> Result<HashMap<String, CombinedParamsValueRetriever>, String> {
122-
let check = |count: usize| {
123-
if count != expected_collection.len() {
124-
return Err(format!(
125-
"Wrong number of values: expected {} but {} supplied{}",
126-
expected_collection.len(),
127-
count,
128-
if count == 1 {
129-
format!(". Did you use the correct delimiter '{}'?", delimiter)
130-
} else {
131-
"".to_string()
132-
}
133-
));
134-
}
135-
Ok(())
136-
};
137122
let pieces: Vec<&str> = input.split(delimiter).collect();
138-
check(pieces.len())?;
123+
let param_count = pieces.len();
124+
let expected_param_count = expected_collection.len();
125+
if param_count != expected_param_count {
126+
return Err(format!(
127+
"Wrong number of values: expected {} but {} supplied{}",
128+
expected_param_count,
129+
param_count,
130+
if param_count == 1 {
131+
format!(". Did you use the correct delimiter '{}'?", delimiter)
132+
} else {
133+
"".to_string()
134+
}
135+
));
136+
}
139137
let zipped = pieces.into_iter().zip(expected_collection.iter());
140-
Ok(zipped
141-
.map(|(piece, (param_name, data_type))| {
142-
(
143-
param_name.to_string(),
144-
CombinedParamsValueRetriever::parse(piece, data_type).expectv("numeric value"),
145-
)
146-
})
147-
.collect())
138+
let remapped_pairs = zipped.map(|(piece, (param_name, data_type))| {
139+
(
140+
param_name.to_string(),
141+
CombinedParamsValueRetriever::parse(piece, data_type).expectv("numeric value"),
142+
)
143+
});
144+
Ok(HashMap::from_iter(remapped_pairs))
148145
}
149146

150147
fn initialize_objects(
151148
&self,
152149
parsed_values: HashMap<String, CombinedParamsValueRetriever>,
153150
) -> Self {
154151
match self {
155-
Self::RatePack(Uninitialized) => Self::RatePack(Initialized(initiate_struct!(
152+
Self::RatePack(Uninitialized) => Self::RatePack(Initialized(initialize_struct!(
156153
RatePack,
157154
&parsed_values,
158155
"routing_byte_rate",
@@ -161,7 +158,7 @@ impl CombinedParams {
161158
"exit_service_rate"
162159
))),
163160
Self::PaymentThresholds(Uninitialized) => {
164-
Self::PaymentThresholds(Initialized(initiate_struct!(
161+
Self::PaymentThresholds(Initialized(initialize_struct!(
165162
PaymentThresholds,
166163
&parsed_values,
167164
"maturity_threshold_sec",
@@ -173,7 +170,7 @@ impl CombinedParams {
173170
)))
174171
}
175172
Self::ScanIntervals(Uninitialized) => {
176-
Self::ScanIntervals(Initialized(initiate_struct!(
173+
Self::ScanIntervals(Initialized(initialize_struct!(
177174
ScanIntervals,
178175
&parsed_values,
179176
Duration::from_secs,
@@ -183,7 +180,7 @@ impl CombinedParams {
183180
)))
184181
}
185182
_ => panic!(
186-
"should be called only on uninitialized object, not: {:?}",
183+
"should be called only on an uninitialized object, not: {:?}",
187184
self
188185
),
189186
}
@@ -213,7 +210,7 @@ impl From<&CombinedParams> for &[(&str, CombinedParamsDataTypes)] {
213210
("receivable_scan_interval", U64),
214211
],
215212
_ => panic!(
216-
"should be called only on uninitialized object, not: {:?}",
213+
"should be called only on an uninitialized object, not: {:?}",
217214
params
218215
),
219216
}
@@ -433,7 +430,7 @@ mod tests {
433430
assert_eq!(
434431
panic_1_msg,
435432
&format!(
436-
"should be called only on uninitialized object, not: RatePack(Initialized({:?}))",
433+
"should be called only on an uninitialized object, not: RatePack(Initialized({:?}))",
437434
DEFAULT_RATE_PACK
438435
)
439436
);
@@ -449,7 +446,7 @@ mod tests {
449446
assert_eq!(
450447
panic_2_msg,
451448
&format!(
452-
"should be called only on uninitialized object, not: PaymentThresholds(Initialized({:?}))",
449+
"should be called only on an uninitialized object, not: PaymentThresholds(Initialized({:?}))",
453450
PaymentThresholds::default()
454451
)
455452
);
@@ -464,7 +461,7 @@ mod tests {
464461
assert_eq!(
465462
panic_3_msg,
466463
&format!(
467-
"should be called only on uninitialized object, not: ScanIntervals(Initialized({:?}))",
464+
"should be called only on an uninitialized object, not: ScanIntervals(Initialized({:?}))",
468465
*TEST_SCAN_INTERVALS
469466
)
470467
);
@@ -482,7 +479,7 @@ mod tests {
482479
assert_eq!(
483480
panic_1_msg,
484481
&format!(
485-
"should be called only on uninitialized object, not: RatePack(Initialized({:?}))",
482+
"should be called only on an uninitialized object, not: RatePack(Initialized({:?}))",
486483
DEFAULT_RATE_PACK
487484
)
488485
);
@@ -497,7 +494,7 @@ mod tests {
497494
assert_eq!(
498495
panic_2_msg,
499496
&format!(
500-
"should be called only on uninitialized object, not: PaymentThresholds(Initialized({:?}))",
497+
"should be called only on an uninitialized object, not: PaymentThresholds(Initialized({:?}))",
501498
PaymentThresholds::default()
502499
)
503500
);
@@ -512,7 +509,7 @@ mod tests {
512509
assert_eq!(
513510
panic_3_msg,
514511
&format!(
515-
"should be called only on uninitialized object, not: ScanIntervals(Initialized({:?}))",
512+
"should be called only on an uninitialized object, not: ScanIntervals(Initialized({:?}))",
516513
*TEST_SCAN_INTERVALS
517514
)
518515
);

0 commit comments

Comments
 (0)