Skip to content

Commit

Permalink
Implement try_from rpc tx for TransactionSignedEcRecovered (#7752)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Apr 22, 2024
1 parent 0231492 commit 612cfcb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/primitives/src/transaction/mod.rs
Expand Up @@ -1822,6 +1822,25 @@ impl IntoRecoveredTransaction for TransactionSignedEcRecovered {
}
}

impl TryFrom<reth_rpc_types::Transaction> for TransactionSignedEcRecovered {
type Error = ConversionError;

fn try_from(tx: reth_rpc_types::Transaction) -> Result<Self, Self::Error> {
let signature = tx.signature.ok_or(ConversionError::MissingSignature)?;

TransactionSigned::from_transaction_and_signature(
tx.try_into()?,
Signature {
r: signature.r,
s: signature.s,
odd_y_parity: signature.y_parity.ok_or(ConversionError::MissingYParity)?.0,
},
)
.try_into_ecrecovered()
.map_err(|_| ConversionError::InvalidSignature)
}
}

#[cfg(test)]
mod tests {
use crate::{
Expand Down

0 comments on commit 612cfcb

Please sign in to comment.