Skip to content

Commit

Permalink
feat: impl SignedTransaction for OpPooledTransaction (#13406)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Dec 14, 2024
1 parent ed7b778 commit 7e41a4b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 19 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,11 @@ alloy-transport-ipc = { version = "0.8.0", default-features = false }
alloy-transport-ws = { version = "0.8.0", default-features = false }

# op
op-alloy-rpc-types = "0.8.2"
op-alloy-rpc-types-engine = "0.8.2"
op-alloy-rpc-jsonrpsee = "0.8.2"
op-alloy-network = "0.8.2"
op-alloy-consensus = "0.8.2"
op-alloy-rpc-types = "0.8.3"
op-alloy-rpc-types-engine = "0.8.3"
op-alloy-rpc-jsonrpsee = "0.8.3"
op-alloy-network = "0.8.3"
op-alloy-consensus = "0.8.3"

# misc
aquamarine = "0.6"
Expand Down
12 changes: 12 additions & 0 deletions crates/primitives-traits/src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ impl InMemorySize for op_alloy_consensus::OpTypedTransaction {
}
}

#[cfg(feature = "op")]
impl InMemorySize for op_alloy_consensus::OpPooledTransaction {
fn size(&self) -> usize {
match self {
Self::Legacy(tx) => tx.size(),
Self::Eip2930(tx) => tx.size(),
Self::Eip1559(tx) => tx.size(),
Self::Eip7702(tx) => tx.size(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
37 changes: 37 additions & 0 deletions crates/primitives-traits/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,40 @@ impl SignedTransaction for PooledTransaction {
recover_signer_unchecked(self.signature(), signature_hash)
}
}

#[cfg(feature = "op")]
impl SignedTransaction for op_alloy_consensus::OpPooledTransaction {
fn tx_hash(&self) -> &TxHash {
match self {
Self::Legacy(tx) => tx.hash(),
Self::Eip2930(tx) => tx.hash(),
Self::Eip1559(tx) => tx.hash(),
Self::Eip7702(tx) => tx.hash(),
}
}

fn signature(&self) -> &Signature {
match self {
Self::Legacy(tx) => tx.signature(),
Self::Eip2930(tx) => tx.signature(),
Self::Eip1559(tx) => tx.signature(),
Self::Eip7702(tx) => tx.signature(),
}
}

fn recover_signer(&self) -> Option<Address> {
let signature_hash = self.signature_hash();
recover_signer(self.signature(), signature_hash)
}

fn recover_signer_unchecked_with_buf(&self, buf: &mut Vec<u8>) -> Option<Address> {
match self {
Self::Legacy(tx) => tx.tx().encode_for_signing(buf),
Self::Eip2930(tx) => tx.tx().encode_for_signing(buf),
Self::Eip1559(tx) => tx.tx().encode_for_signing(buf),
Self::Eip7702(tx) => tx.tx().encode_for_signing(buf),
}
let signature_hash = keccak256(buf);
recover_signer_unchecked(self.signature(), signature_hash)
}
}

0 comments on commit 7e41a4b

Please sign in to comment.