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
mod auth;
mod consts;
mod helpers;
mod keys;
mod safe_client;
mod sequence;
#[cfg(test)]
mod test_helpers;
use super::{common, constants, Result};
use rand::rngs::OsRng;
use safe_client::SafeAppClient;
use sn_data_types::Keypair;
use std::time::Duration;
static DEFAULT_TIMEOUT_SECS: u64 = 20;
pub mod fetch;
pub mod files;
pub mod multimap;
pub mod nrs;
pub mod register;
pub mod wallet;
pub use consts::DEFAULT_XORURL_BASE;
pub use helpers::parse_coins_amount;
pub use sn_url::*;
pub use xor_name::{XorName, XOR_NAME_LEN};
#[derive(Clone)]
pub struct Safe {
safe_client: SafeAppClient,
pub xorurl_base: XorUrlBase,
#[allow(dead_code)]
timeout: Duration,
}
impl Default for Safe {
fn default() -> Self {
Self::new(
Some(DEFAULT_XORURL_BASE),
Duration::from_secs(DEFAULT_TIMEOUT_SECS),
)
}
}
impl Safe {
pub fn new(xorurl_base: Option<XorUrlBase>, timeout: Duration) -> Self {
Self {
safe_client: SafeAppClient::new(),
xorurl_base: xorurl_base.unwrap_or(DEFAULT_XORURL_BASE),
timeout,
}
}
pub fn keypair(&self) -> Keypair {
let mut rng = OsRng;
Keypair::new_ed25519(&mut rng)
}
pub async fn get_my_keypair(&self) -> Result<Keypair> {
self.safe_client.keypair().await
}
}