anvil_zksync_types/
transaction_order.rsuse std::fmt;
use std::str::FromStr;
use zksync_types::{Transaction, U256};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct TransactionPriority(pub U256);
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum TransactionOrder {
Fifo,
#[default]
Fees,
}
impl TransactionOrder {
pub fn priority(&self, tx: &Transaction) -> TransactionPriority {
match self {
Self::Fifo => TransactionPriority::default(),
Self::Fees => TransactionPriority(tx.max_fee_per_gas()),
}
}
}
impl FromStr for TransactionOrder {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.to_lowercase();
let order = match s.as_str() {
"fees" => Self::Fees,
"fifo" => Self::Fifo,
_ => return Err(format!("Unknown TransactionOrder: `{s}`")),
};
Ok(order)
}
}
impl fmt::Display for TransactionOrder {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
TransactionOrder::Fifo => f.write_str("fifo"),
TransactionOrder::Fees => f.write_str("fees"),
}
}
}