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
use std::time::{SystemTime, UNIX_EPOCH};
static DA_UNIX_EPOCH: u128 = 170141184475152167957503069145530368000;
static DA_SECOND: u128 = 18446744073709551616;
pub fn unix_time_to_da(unix_time: u64) -> u128 {
let time_since_epoch = (unix_time as u128 * DA_SECOND) / 1000;
DA_UNIX_EPOCH + time_since_epoch
}
pub fn get_current_time() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64
}
pub fn get_current_da_time() -> u128 {
let unix_time = get_current_time();
unix_time_to_da(unix_time)
}
pub fn index_dec_to_ud(index: &str) -> String {
let index_split: Vec<&str> = index.split("/").collect();
let mut udindex = String::new();
for i in 0..index_split.len() {
if index_split[i].len() > 0 {
let mut rev: String = index_split[i].chars().rev().collect();
let mut out = String::new();
while rev.len() >= 3 {
let chunk: String = rev.drain(..3).collect();
out += &chunk;
if rev.len() > 0 {
out += ".";
}
}
out += &rev;
let seg: String = out.chars().rev().collect();
udindex += &format!("/{}", &seg);
}
}
udindex
}