Skip to content

Commit 9e6cbb8

Browse files
kakao-jun-esgkim126
authored andcommitted
Add a macro for checking hexadecimal number
1 parent f0e6c71 commit 9e6cbb8

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ codechain-cuckoo-miner [OPTIONS]
1919
```
2020

2121
### Usage Examples
22-
* N=16, M=8, L=6, listening on port **3333**, submitting on port **8080**, **1** concurrent jobs :
22+
* N=0x10, M=0x8, L=6, listening on port **3333**, submitting on port **8080**, **1** concurrent jobs :
2323
```
24-
codechain-cuckoo-miner -n 16 -m 8 -l 6 -p 3333 -s 8080 -j 1
24+
codechain-cuckoo-miner -n 0x10 -m 0x8 -l 6 -p 3333 -s 8080 -j 1
2525
```
2626

2727
## Configuration

src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,25 @@ use codechain_miner::run;
3434

3535
use self::config::CuckooConfig;
3636

37+
macro_rules! hex_value_t {
38+
($m:ident, $v:expr) => {{
39+
let val = value_t!($m, $v, String).map_err(|_| format!("Invalid value"))?;
40+
if val.len() > 2 && &val[0..2] == "0x" {
41+
usize::from_str_radix(&val[2..], 16).map_err(|_| format!("'{}' isn't parsed", val))
42+
} else {
43+
Err(format!("'{}' isn't a hexadecimal number", val))
44+
}
45+
}};
46+
}
47+
3748
fn get_options() -> Result<CuckooConfig, String> {
3849
let yaml = load_yaml!("./cli.yml");
3950
let matches = clap::App::from_yaml(yaml).get_matches();
4051

4152
let listening_port = value_t!(matches, "listening port", u16).map_err(|_| "Invalid listening port")?;
4253
let submitting_port = value_t!(matches, "submitting port", u16).map_err(|_| "Invalid submitting port")?;
43-
let max_vertex = value_t!(matches, "max vertex", usize).map_err(|_| "Invalid max vertex")?;
44-
let max_edge = value_t!(matches, "max edge", usize).map_err(|_| "Invalid max edge")?;
54+
let max_vertex = hex_value_t!(matches, "max vertex").map_err(|e| format!("Invalid max vertex: {}", e))?;
55+
let max_edge = hex_value_t!(matches, "max edge").map_err(|e| format!("Invalid max edge: {}", e))?;
4556
let cycle_length = value_t!(matches, "cycle length", usize).map_err(|_| "Invalid cycle length")?;
4657
let concurrent_jobs = value_t!(matches, "concurrent jobs", u16).map_err(|_| "Invalid concurrent jobs")?;
4758

0 commit comments

Comments
 (0)