use crate::utils::json::Json;
use crate::utils::sign::goldilocks::Fp;
use crate::utils::sign::tx::{Attributes, BadTx, Tx, TxType, element, number};
use crate::utils::{MarketId, OrderRef};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CancelOrder {
pub market: MarketId,
pub order: OrderRef,
pub attributes: Attributes,
}
impl CancelOrder {
#[must_use]
pub fn new(market: MarketId, order: impl Into<OrderRef>) -> CancelOrder {
CancelOrder { market, order: order.into(), attributes: Attributes::NONE }
}
#[must_use]
pub const fn with(mut self, attributes: Attributes) -> CancelOrder {
self.attributes = attributes;
self
}
}
impl Tx for CancelOrder {
fn tx_type(&self) -> TxType {
TxType::CancelOrder
}
fn hash_fields(&self) -> Vec<Fp> {
vec![element(self.market.get()), element(self.order.index())]
}
fn info_fields(&self) -> Vec<(&'static str, Json)> {
vec![("MarketIndex", number(self.market.get())), ("Index", number(self.order.index()))]
}
fn attributes(&self) -> Attributes {
self.attributes
}
fn check(&self) -> Result<(), BadTx> {
self.attributes.check()
}
}
#[cfg(test)]
#[path = "tests/cancel.rs"]
mod tests;