From 326341511336b84ff7870210156a04235be0f4b4 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 17 Oct 2024 12:57:04 +0200 Subject: [PATCH] feat: add helper to eip155 variant --- crates/primitives/src/signature/parity.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/primitives/src/signature/parity.rs b/crates/primitives/src/signature/parity.rs index c8415f1f0..5cf2d1680 100644 --- a/crates/primitives/src/signature/parity.rs +++ b/crates/primitives/src/signature/parity.rs @@ -76,6 +76,25 @@ impl Parity { } } + /// Applies a check to the [`Parity::Eip155`] v value if this instance is a [`Parity::Eip155`]. + /// + /// Returns [`Ok`] if the instance is not [`Parity::Eip155`] + pub fn ensure_eip155(&self, f: F) -> Result<(), E> + where + F: FnOnce(u64) -> Result<(), E>, + { + if let Self::Eip155(v) = self { + f(*v) + } else { + Ok(()) + } + } + + /// Returns true if this instance is a [`Parity::Eip155`] + pub const fn is_eip155(&self) -> bool { + matches!(self, Self::Eip155(_)) + } + /// Return the y-parity as a boolean. pub const fn y_parity(&self) -> bool { match self {