cfx_rpc_cfx_types/
subscriber_id.rs

1use cfx_types::H64;
2use std::str;
3
4#[derive(Debug, Clone, Hash, Eq, PartialEq)]
5pub struct SubId(H64);
6
7impl str::FromStr for SubId {
8    type Err = String;
9
10    fn from_str(s: &str) -> Result<Self, Self::Err> {
11        if s.starts_with("0x") {
12            Ok(SubId(s[2..].parse().map_err(|e| format!("{}", e))?))
13        } else {
14            Err("The id must start with 0x".into())
15        }
16    }
17}
18impl SubId {
19    pub fn new(data: H64) -> Self { SubId(data) }
20
21    // TODO: replace `format!` see [#10412](https://github.com/paritytech/parity-ethereum/issues/10412)
22    pub fn as_string(&self) -> String { format!("{:?}", self.0) }
23}
24
25pub mod random {
26    use rand_07;
27
28    pub type Rng = rand_07::rngs::OsRng;
29
30    pub fn new() -> Rng { rand_07::rngs::OsRng }
31}