use crate::utils::wire::{BadWire, field, hash_of, parse, str_of, u128_of};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Accepted {
pub intent_id: [u8; 32],
pub action: String,
pub state: String,
pub queue_revision: Option<u128>,
}
impl Accepted {
pub fn parse(text: &str) -> Result<Accepted, BadWire> {
let json = parse(text, "intent_answer")?;
Ok(Accepted {
intent_id: hash_of(field(&json, "intentId")?, "intentId")?,
action: str_of(field(&json, "action")?, "action")?.to_owned(),
state: str_of(field(&json, "state")?, "state")?.to_owned(),
queue_revision: match json.get("queueRevision") {
Some(value) => Some(u128_of(value, "queueRevision")?),
None => None,
},
})
}
#[must_use]
pub fn kept(&self) -> bool {
matches!(self.state.as_str(), "queued" | "prepared" | "confirmed")
}
}
#[cfg(test)]
#[path = "tests/accepted.rs"]
mod tests;