1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
mod import_params;
mod transaction_pool_params;
mod shared_params;
mod node_key_params;
mod network_configuration_params;
mod pruning_params;
use std::str::FromStr;
use std::fmt::Debug;
pub use crate::params::import_params::*;
pub use crate::params::transaction_pool_params::*;
pub use crate::params::shared_params::*;
pub use crate::params::node_key_params::*;
pub use crate::params::network_configuration_params::*;
pub use crate::params::pruning_params::*;
#[derive(Debug, Clone)]
pub struct BlockNumber(String);
impl FromStr for BlockNumber {
type Err = String;
fn from_str(block_number: &str) -> Result<Self, Self::Err> {
if block_number.chars().any(|d| !d.is_digit(10)) {
Err(format!(
"Invalid block number: {}, expected decimal formatted unsigned integer",
block_number,
))
} else {
Ok(Self(block_number.to_owned()))
}
}
}
impl BlockNumber {
pub fn parse<N>(&self) -> Result<N, String>
where
N: FromStr,
N::Err: std::fmt::Debug,
{
self.0
.parse()
.map_err(|e| format!("BlockNumber: {} parsing failed because of {:?}", self.0, e))
}
}