From 3d034519af0d81c73db7452df323e345b3fcf812 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Wed, 25 Sep 2024 14:13:28 +0100 Subject: [PATCH] feat(exex): `ExExNotification::into_inverted` (#11205) --- crates/exex/types/src/notification.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/exex/types/src/notification.rs b/crates/exex/types/src/notification.rs index 390d9dc66..2a5595787 100644 --- a/crates/exex/types/src/notification.rs +++ b/crates/exex/types/src/notification.rs @@ -43,6 +43,20 @@ impl ExExNotification { Self::ChainCommitted { .. } => None, } } + + /// Converts the notification into a notification that is the inverse of the original one. + /// + /// - For [`Self::ChainCommitted`], it's [`Self::ChainReverted`]. + /// - For [`Self::ChainReverted`], it's [`Self::ChainCommitted`]. + /// - For [`Self::ChainReorged`], it's [`Self::ChainReorged`] with the new chain as the old + /// chain and the old chain as the new chain. + pub fn into_inverted(self) -> Self { + match self { + Self::ChainCommitted { new } => Self::ChainReverted { old: new }, + Self::ChainReverted { old } => Self::ChainCommitted { new: old }, + Self::ChainReorged { old, new } => Self::ChainReorged { old: new, new: old }, + } + } } impl From for ExExNotification {