cita_types/
lib.rs

1// Copyright Rivtower Technologies LLC.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15extern crate ethereum_types;
16extern crate plain_hasher;
17
18use std::collections::{HashMap, HashSet};
19use std::hash;
20
21pub mod traits;
22
23pub use ethereum_types::{Bloom, BloomInput, BloomRef};
24pub use ethereum_types::{H128, H160, H256, H264, H32, H512, H520, H64};
25pub use ethereum_types::{U128, U256, U512, U64};
26pub use plain_hasher::PlainHasher;
27
28pub type Address = H160;
29
30/// Specialized version of `HashMap` with H256 keys and fast hashing function.
31pub type H256FastMap<T> = HashMap<H256, T, hash::BuildHasherDefault<PlainHasher>>;
32/// Specialized version of `HashSet` with H256 keys and fast hashing function.
33pub type H256FastSet = HashSet<H256, hash::BuildHasherDefault<PlainHasher>>;
34
35#[inline]
36pub fn pad_left0(hexstr: &str, width: usize) -> String {
37    format!("{:0>width$}", hexstr, width = width)
38}
39
40#[inline]
41pub fn delete_left0(s: &str) -> &str {
42    let mut cnt = 0;
43    for i in s.chars() {
44        if i == '0' {
45            cnt += 1;
46        } else {
47            break;
48        }
49    }
50    &s[cnt..]
51}
52
53#[inline]
54pub fn clean_0x(s: &str) -> &str {
55    if let Some(stripped) = s.strip_prefix("0x") {
56        stripped
57    } else {
58        s
59    }
60}