Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement try_from rpc tx for TransactionSignedEcRecovered #7752

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/primitives/src/transaction/mod.rs
Expand Up @@ -1816,6 +1816,32 @@ 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> {
tx.signature.ok_or(ConversionError::MissingSignature).and_then(|signature| {
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
TransactionSigned::from_transaction_and_signature(
tx.try_into()?,
Signature {
r: signature.r,
s: signature.s,
odd_y_parity: signature
.y_parity
.ok_or(ConversionError::SignatureError(
alloy_primitives::SignatureError::InvalidParity(0),
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
))?
.0,
},
)
.try_into_ecrecovered()
.map_err(|_| {
ConversionError::SignatureError(alloy_primitives::SignatureError::InvalidParity(0))
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
})
})
}
}

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