Skip to content

Commit

Permalink
feat: type (de)serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Jun 28, 2024
1 parent 180e2b0 commit 846bd81
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/edr_eth/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ impl TryFrom<u8> for Type {
}
}

impl<'deserializer> serde::Deserialize<'deserializer> for Type {
fn deserialize<D>(deserializer: D) -> Result<Type, D::Error>
where
D: serde::Deserializer<'deserializer>,
{
let value = U8::deserialize(deserializer)?;
Type::try_from(value.to::<u8>()).map_err(serde::de::Error::custom)
}
}

impl serde::Serialize for Type {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
U8::serialize(&U8::from(u8::from(*self)), serializer)
}
}

pub trait SignedTransaction: Transaction {
/// The effective gas price of the transaction, calculated using the
/// provided block base fee.
Expand Down

0 comments on commit 846bd81

Please sign in to comment.