1use miden_client::{Felt, Word};
2
3use crate::pair::Pair;
4#[derive(Debug, Clone)]
5pub struct Entry {
6 pub pair: Pair,
7 pub price: u64,
11 pub decimals: u32,
12 pub timestamp: u64,
13}
14
15impl TryInto<Word> for Entry {
16 type Error = anyhow::Error;
17
18 fn try_into(self) -> Result<Word, Self::Error> {
19 Ok([
20 Felt::try_from(self.pair)?,
21 Felt::new(self.price),
22 Felt::new(self.decimals as u64),
23 Felt::new(self.timestamp),
24 ])
25 }
26}
27
28impl From<Word> for Entry {
29 fn from(word: Word) -> Self {
30 let [pair_felt, price_felt, decimals_felt, timestamp_felt] = word;
31
32 let pair = Pair::from(pair_felt);
34
35 let price = price_felt.as_int();
37 let decimals = decimals_felt.as_int() as u32;
38 let timestamp = timestamp_felt.as_int();
39
40 Entry {
41 pair,
42 price,
43 decimals,
44 timestamp,
45 }
46 }
47}