Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 20 additions & 28 deletions src/platform/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,6 @@ pub enum Eligibility {
PermanentlyIneligible,
}

/// This is a quality of life helper that allows users of this api to say:
/// `if bundle.is_eligible(block) { .. }`, without going into the details of
/// the eligibility.
impl PartialEq<bool> for Eligibility {
fn eq(&self, other: &bool) -> bool {
match self {
Eligibility::Eligible => *other,
Eligibility::TemporarilyIneligible
| Eligibility::PermanentlyIneligible => !(*other),
}
}
}

/// This is a quality of life helper that allows users of this api to say:
/// `if !bundle.is_eligible(block) { .. }`, without going into the details of
/// the ineligibility.
impl Not for Eligibility {
type Output = bool;

fn not(self) -> Self::Output {
match self {
Eligibility::Eligible => false,
Eligibility::TemporarilyIneligible
| Eligibility::PermanentlyIneligible => true,
}
}
}

impl Eligibility {
/// Returns `Some(f())` if the eligibility is `Eligible`, otherwise returns
/// `None`.
Expand All @@ -187,6 +159,26 @@ impl Eligibility {
}
}

/// This is a quality of life helper that allows users of this api to say:
/// `if bundle.is_eligible(block).into() {.}`, without going into the
/// details of the eligibility.
impl From<Eligibility> for bool {
fn from(el: Eligibility) -> Self {
matches!(el, Eligibility::Eligible)
}
}

/// This is a quality of life helper that allows users of this api to say:
/// `if !bundle.is_eligible(block) {.}`, without going into the details of
/// the ineligibility.
impl Not for Eligibility {
type Output = bool;

fn not(self) -> Self::Output {
!<Eligibility as Into<bool>>::into(self)
}
}

/// A bundle of transactions that adheres to the [Flashbots specification].
/// see: <https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint#eth_sendbundle>
///
Expand Down
Loading