emerald_vault/
lib.rs

1/*
2Copyright 2019 ETCDEV GmbH
3Copyright 2020 EmeraldPay, Inc
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9    http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16*/
17//! # Ethereum web3 like connector library
18#![cfg_attr(feature = "dev", feature(plugin))]
19#![cfg_attr(feature = "dev", plugin(clippy))]
20//#![deny(missing_docs)]
21
22#[macro_use]
23extern crate log;
24
25#[macro_use]
26extern crate lazy_static;
27
28#[macro_use]
29extern crate serde_derive;
30
31#[macro_use]
32extern crate enum_display_derive;
33
34extern crate aes;
35extern crate byteorder;
36extern crate chrono;
37extern crate csv;
38extern crate ethabi;
39extern crate glob;
40extern crate hdpath;
41extern crate hex;
42extern crate hmac;
43extern crate num;
44extern crate pbkdf2;
45extern crate protobuf;
46extern crate rand;
47extern crate regex;
48extern crate scrypt;
49extern crate secp256k1;
50extern crate serde;
51extern crate serde_json;
52extern crate sha2;
53extern crate sha3;
54extern crate time;
55extern crate uuid;
56#[macro_use]
57extern crate byte_array_struct;
58extern crate emerald_hwkey;
59
60#[macro_use]
61pub mod util;
62pub mod blockchain;
63pub mod convert;
64pub mod crypto;
65pub mod migration;
66pub mod mnemonic;
67pub mod proto;
68pub mod sign;
69pub mod storage;
70pub mod structs;
71pub mod error;
72
73pub use self::{blockchain::*, util::*};
74
75const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
76
77/// Get the current Emerald version.
78pub fn version() -> &'static str {
79    VERSION.unwrap_or("unknown")
80}
81
82#[cfg(test)]
83mod tests {
84    pub use super::*;
85    use crate::storage::archive::ARCHIVE_DIR;
86    use log::Level;
87    pub use regex::Regex;
88    use std::{fs, fs::DirEntry, path::{Path, PathBuf}};
89
90
91    #[allow(dead_code)]
92    pub fn init_tests() {
93        simple_logger::init_with_level(Level::Debug).unwrap();
94    }
95
96    pub fn read_dir_fully<P: AsRef<Path>>(path: P) -> Vec<DirEntry> {
97        fs::read_dir(path).unwrap().map(|i| i.unwrap()).collect()
98    }
99
100    pub fn get_archived<P: AsRef<Path>>(dir: P) -> Option<PathBuf> {
101        let in_arch: Vec<DirEntry> = read_dir_fully(dir.as_ref().to_path_buf().join(ARCHIVE_DIR));
102        if in_arch.len() != 1 {
103            warn!("There're {} elements in archive", in_arch.len());
104            return None;
105        }
106        let arch_dir = in_arch.first().unwrap();
107        Some(arch_dir.path())
108    }
109
110}