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
use crate::account_config::DIEM_MODULE_NAME;
use anyhow::Result;
use move_core_types::{
identifier::{IdentStr, Identifier},
move_resource::MoveResource,
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct ToXDXExchangeRateUpdateEvent {
currency_code: Identifier,
new_to_xdx_exchange_rate: u64,
}
impl ToXDXExchangeRateUpdateEvent {
pub fn new_to_xdx_exchange_rate(&self) -> f32 {
let unrounded = (self.new_to_xdx_exchange_rate as f32) / 2f32.powf(32f32);
(unrounded * 100.0).round() / 100.0
}
pub fn currency_code(&self) -> &IdentStr {
&self.currency_code
}
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}
}
impl MoveResource for ToXDXExchangeRateUpdateEvent {
const MODULE_NAME: &'static str = DIEM_MODULE_NAME;
const STRUCT_NAME: &'static str = "ToXDXExchangeRateUpdateEvent";
}