Skip to content

Commit

Permalink
feat: add missing txtype tryfroms (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 16, 2024
1 parent 16b2164 commit e58ea5e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloy_eips::{
eip2930::AccessList,
eip7702::SignedAuthorization,
};
use alloy_primitives::{Address, Bytes, TxKind, B256, U256};
use alloy_primitives::{Address, Bytes, TxKind, B256, U256, U64};
use alloy_rlp::{BufMut, Decodable, Encodable};
use derive_more::Display;

Expand Down Expand Up @@ -79,6 +79,24 @@ impl TryFrom<u8> for OpTxType {
}
}

impl TryFrom<u64> for OpTxType {
type Error = &'static str;

fn try_from(value: u64) -> Result<Self, Self::Error> {
let err = || "invalid tx type";
let value: u8 = value.try_into().map_err(|_| err())?;
Self::try_from(value).map_err(|_| err())
}
}

impl TryFrom<U64> for OpTxType {
type Error = &'static str;

fn try_from(value: U64) -> Result<Self, Self::Error> {
value.to::<u64>().try_into()
}
}

impl PartialEq<u8> for OpTxType {
fn eq(&self, other: &u8) -> bool {
(*self as u8) == *other
Expand Down

0 comments on commit e58ea5e

Please sign in to comment.