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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(clippy::nursery, missing_docs, rust_2018_idioms, warnings)]
#![allow(
clippy::redundant_pub_crate,
clippy::module_name_repetitions,
clippy::missing_const_for_fn,
clippy::significant_drop_in_scrutinee
)]
#[macro_use]
extern crate serde;
#[cfg(feature = "mqtt")]
macro_rules! lazy_static {
($init:expr => $type:ty) => {{
static mut VALUE: Option<$type> = None;
static INIT: std::sync::Once = std::sync::Once::new();
INIT.call_once(|| unsafe { VALUE = Some($init) });
unsafe { VALUE.as_ref() }.expect("failed to get lazy static value")
}};
}
pub mod api;
pub mod builder;
pub mod client;
pub mod constants;
pub mod error;
#[cfg(feature = "message_interface")]
#[cfg_attr(docsrs, doc(cfg(feature = "message_interface")))]
pub mod message_interface;
pub mod node_api;
pub mod node_manager;
pub mod secret;
pub mod storage;
#[cfg(feature = "stronghold")]
#[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))]
pub mod stronghold;
pub mod utils;
pub use crypto::{self, keys::slip10::Seed};
pub use iota_pow as pow;
pub use iota_types::{api as api_types, block};
pub use packable;
pub use url::Url;
#[cfg(feature = "mqtt")]
pub use self::node_api::mqtt::*;
pub use self::{
builder::{ClientBuilder, NetworkInfo, NetworkInfoDto},
client::*,
error::*,
node_api::core::routes::NodeInfoWrapper,
utils::*,
};
#[cfg(feature = "mqtt")]
mod async_runtime {
use std::sync::Mutex;
use once_cell::sync::OnceCell;
use tokio::runtime::Runtime;
static RUNTIME: OnceCell<Mutex<Runtime>> = OnceCell::new();
pub(crate) fn block_on<C: futures::Future>(cb: C) -> C::Output {
let runtime = RUNTIME.get_or_init(|| Mutex::new(Runtime::new().expect("failed to create Tokio runtime")));
runtime.lock().expect("failed to lock the runtime.").block_on(cb)
}
pub(crate) fn spawn<F>(future: F)
where
F: futures::Future + Send + 'static,
F::Output: Send + 'static,
{
let runtime = RUNTIME.get_or_init(|| Mutex::new(Runtime::new().expect("failed to create Tokio runtime")));
runtime.lock().expect("failed to lock the runtime.").spawn(future);
}
}
fn unix_timestamp_now() -> u32 {
instant::SystemTime::now()
.duration_since(instant::SystemTime::UNIX_EPOCH)
.expect("time went backwards")
.as_secs() as u32
}