feat: impl SignedTransaction for OpPooledTransaction (#13406)

This commit is contained in:
Dan Cline
2024-12-14 18:02:34 -05:00
committed by GitHub
parent ed7b778bbe
commit 7e41a4b14a
4 changed files with 68 additions and 19 deletions

28
Cargo.lock generated
View File

@ -5412,9 +5412,9 @@ checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9"
[[package]]
name = "op-alloy-consensus"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24aaf487dd59beed72931e31b11b305cdcb6a20651a1cccf992a20706a54cc3b"
checksum = "848b3567a9a469ab0c9c712fca0fd6bbce13a9a0b723c94cb81214f53507cf07"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5430,9 +5430,9 @@ dependencies = [
[[package]]
name = "op-alloy-genesis"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ad6c33c2711611e19092a7d17c076542e27687ef975f67bf57039fa3d57e06"
checksum = "3cd04d0e24b3538e2bc9c024da1c08e0a97822c63b341c4491a6b29e86740641"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5445,9 +5445,9 @@ dependencies = [
[[package]]
name = "op-alloy-network"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8273ddf3a0a8cb891abbc625289f8094fbeab1329e0874b38e14bf1670402b7c"
checksum = "3de7f38f96e4d8bc13bd6b05f27d9876c17e897898705734020a59291a06d781"
dependencies = [
"alloy-consensus",
"alloy-network",
@ -5460,9 +5460,9 @@ dependencies = [
[[package]]
name = "op-alloy-protocol"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccb98f90d0101cdaabb739c44f4d4b2d0ad0ad1a3dd68ce525683ffafd97dd13"
checksum = "0d0d72853e704a067ad6229dd3a753d1662fa02c4ea85783e25a887d7aadd150"
dependencies = [
"alloc-no-stdlib",
"alloy-consensus",
@ -5484,9 +5484,9 @@ dependencies = [
[[package]]
name = "op-alloy-rpc-jsonrpsee"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44a41095f6aa4f39e3d8927ac8a903a45e76ddb533f466ef592853f9a49fe8cf"
checksum = "5f2d5234f9aad47742ad3719c54fbdf2940a3731b659373d75d0f53f11d4a28c"
dependencies = [
"alloy-eips",
"alloy-primitives",
@ -5497,9 +5497,9 @@ dependencies = [
[[package]]
name = "op-alloy-rpc-types"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21d0ada6356ac7818d4b1ba48c37116662732b97f18a3684f08727dafbef2437"
checksum = "8a555dd1bd39cbcdd60b92f03a21871767a16e3a2ce2f82a26cff9aade56d35f"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5516,9 +5516,9 @@ dependencies = [
[[package]]
name = "op-alloy-rpc-types-engine"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c63ba3f50dba410d1ce18aa16242c198f91ad44da5221f7347c1525958a9b09"
checksum = "16779322cc84d57f68afaef4cdabc150a5f8b53f345982f1aea010fe4d790267"
dependencies = [
"alloy-eips",
"alloy-primitives",

View File

@ -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"

View File

@ -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::*;

View File

@ -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)
}
}