forked from apezord/ord-dogecoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdegree.rs
75 lines (69 loc) Β· 1.54 KB
/
degree.rs
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
use super::*;
#[derive(PartialEq, Debug)]
pub(crate) struct Degree {
pub(crate) hour: u64,
pub(crate) minute: u64,
pub(crate) second: u64,
pub(crate) third: u64,
}
impl Display for Degree {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
f,
"{}Β°{}β²{}β³{}β΄",
self.hour, self.minute, self.second, self.third
)
}
}
impl From<Sat> for Degree {
fn from(sat: Sat) -> Self {
let height = sat.height().n();
Degree {
hour: height / (CYCLE_EPOCHS * SUBSIDY_HALVING_INTERVAL),
minute: height % SUBSIDY_HALVING_INTERVAL,
second: height % DIFFCHANGE_INTERVAL,
third: sat.third(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn case(sat: u64, hour: u64, minute: u64, second: u64, third: u64) {
assert_eq!(
Degree::from(Sat(sat)),
Degree {
hour,
minute,
second,
third,
}
);
}
#[test]
fn from() {
case(0, 0, 0, 0, 0);
case(1, 0, 0, 0, 1);
case(5_000_000_000, 0, 1, 1, 0);
case(
5_000_000_000 * DIFFCHANGE_INTERVAL,
0,
DIFFCHANGE_INTERVAL,
0,
0,
);
case(5_000_000_000 * SUBSIDY_HALVING_INTERVAL, 0, 0, 336, 0);
case(
5_000_000_000 * SUBSIDY_HALVING_INTERVAL
+ 2_500_000_000 * SUBSIDY_HALVING_INTERVAL
+ 1_250_000_000 * SUBSIDY_HALVING_INTERVAL
+ 625_000_000 * SUBSIDY_HALVING_INTERVAL
+ 312_500_000 * SUBSIDY_HALVING_INTERVAL
+ 156_250_000 * SUBSIDY_HALVING_INTERVAL,
1,
0,
0,
0,
);
}
}