From 360c1ec38cd6e16e5c1f76ebd310441320daebbf Mon Sep 17 00:00:00 2001 From: Brian Bland Date: Mon, 26 Aug 2024 10:51:00 -0700 Subject: [PATCH] Add TryFrom --- crates/op-test-vectors/src/faultproof.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/op-test-vectors/src/faultproof.rs b/crates/op-test-vectors/src/faultproof.rs index 0bd1e63..eb57f0c 100644 --- a/crates/op-test-vectors/src/faultproof.rs +++ b/crates/op-test-vectors/src/faultproof.rs @@ -2,7 +2,7 @@ use alloy_primitives::{BlockHash, BlockNumber, Bytes, B256}; use hashbrown::HashMap; -use kona_derive::types::RollupConfig; +use kona_primitives::RollupConfig; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; @@ -54,9 +54,29 @@ pub enum FaultProofStatus { Unknown, } +impl TryFrom for FaultProofStatus { + type Error = String; + + fn try_from(value: u8) -> Result { + match value { + 0 => Ok(FaultProofStatus::Valid), + 1 => Ok(FaultProofStatus::Invalid), + 2 => Ok(FaultProofStatus::Panic), + 3 => Ok(FaultProofStatus::Unfinished), + _ => Ok(FaultProofStatus::Unknown), + } + } +} + +impl From for u8 { + fn from(status: FaultProofStatus) -> u8 { + status as u8 + } +} + #[cfg(test)] mod tests { - use kona_derive::types::BASE_MAINNET_CONFIG; + use kona_primitives::BASE_MAINNET_CONFIG; use super::*;