Skip to content

Commit

Permalink
Add TryFrom<u8>
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianBland committed Aug 26, 2024
1 parent 7df4f78 commit 360c1ec
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions crates/op-test-vectors/src/faultproof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -54,9 +54,29 @@ pub enum FaultProofStatus {
Unknown,
}

impl TryFrom<u8> for FaultProofStatus {
type Error = String;

fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(FaultProofStatus::Valid),
1 => Ok(FaultProofStatus::Invalid),
2 => Ok(FaultProofStatus::Panic),
3 => Ok(FaultProofStatus::Unfinished),
_ => Ok(FaultProofStatus::Unknown),
}
}
}

impl From<FaultProofStatus> 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::*;

Expand Down

0 comments on commit 360c1ec

Please sign in to comment.