use miden_client::{Felt, Word};
use crate::pair::Pair;
#[derive(Debug, Clone)]
pub struct Entry {
pub pair: Pair,
pub price: u64,
pub decimals: u32,
pub timestamp: u64,
}
impl TryInto<Word> for Entry {
type Error = anyhow::Error;
fn try_into(self) -> Result<Word, Self::Error> {
Ok([
Felt::try_from(self.pair)?,
Felt::new(self.price),
Felt::new(self.decimals as u64),
Felt::new(self.timestamp),
])
}
}
impl From<Word> for Entry {
fn from(word: Word) -> Self {
let [pair_felt, price_felt, decimals_felt, timestamp_felt] = word;
let pair = Pair::from(pair_felt);
let price = price_felt.as_int();
let decimals = decimals_felt.as_int() as u32;
let timestamp = timestamp_felt.as_int();
Entry {
pair,
price,
decimals,
timestamp,
}
}
}