Skip to content

Commit

Permalink
feat: JS tracer callbacks (#4487)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann authored Oct 19, 2023
1 parent d17bf53 commit 9ac4bf5
Show file tree
Hide file tree
Showing 37 changed files with 1,411 additions and 203 deletions.
6 changes: 3 additions & 3 deletions crates/edr_eth/src/remote/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
access_list::AccessListItem,
signature::Signature,
transaction::{
EIP1559SignedTransaction, EIP155SignedTransaction, EIP2930SignedTransaction,
EIP155SignedTransaction, Eip1559SignedTransaction, Eip2930SignedTransaction,
Eip4844SignedTransaction, LegacySignedTransaction, SignedTransaction, TransactionKind,
},
withdrawal::Withdrawal,
Expand Down Expand Up @@ -175,7 +175,7 @@ impl TryFrom<Transaction> for (SignedTransaction, Address) {
})
}
}
1 => SignedTransaction::Eip2930(EIP2930SignedTransaction {
1 => SignedTransaction::Eip2930(Eip2930SignedTransaction {
odd_y_parity: value.odd_y_parity(),
chain_id: value
.chain_id
Expand All @@ -194,7 +194,7 @@ impl TryFrom<Transaction> for (SignedTransaction, Address) {
s: value.s,
hash: OnceLock::from(value.hash),
}),
2 => SignedTransaction::Eip1559(EIP1559SignedTransaction {
2 => SignedTransaction::Eip1559(Eip1559SignedTransaction {
odd_y_parity: value.odd_y_parity(),
chain_id: value
.chain_id
Expand Down
10 changes: 5 additions & 5 deletions crates/edr_eth/src/transaction/request/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use revm_primitives::{keccak256, B256, U256};
use crate::{
access_list::AccessListItem,
signature::{Signature, SignatureError},
transaction::{kind::TransactionKind, signed::EIP1559SignedTransaction},
transaction::{kind::TransactionKind, signed::Eip1559SignedTransaction},
utils::envelop_bytes,
};

Expand Down Expand Up @@ -36,12 +36,12 @@ impl EIP1559TransactionRequest {
keccak256(&envelop_bytes(2, &encoded))
}

pub fn sign(self, secret_key: &SecretKey) -> Result<EIP1559SignedTransaction, SignatureError> {
pub fn sign(self, secret_key: &SecretKey) -> Result<Eip1559SignedTransaction, SignatureError> {
let hash = self.hash();

let signature = Signature::new(hash, secret_key)?;

Ok(EIP1559SignedTransaction {
Ok(Eip1559SignedTransaction {
chain_id: self.chain_id,
nonce: self.nonce,
max_priority_fee_per_gas: self.max_priority_fee_per_gas,
Expand All @@ -59,8 +59,8 @@ impl EIP1559TransactionRequest {
}
}

impl From<&EIP1559SignedTransaction> for EIP1559TransactionRequest {
fn from(t: &EIP1559SignedTransaction) -> Self {
impl From<&Eip1559SignedTransaction> for EIP1559TransactionRequest {
fn from(t: &Eip1559SignedTransaction) -> Self {
Self {
chain_id: t.chain_id,
nonce: t.nonce,
Expand Down
10 changes: 5 additions & 5 deletions crates/edr_eth/src/transaction/request/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use revm_primitives::{keccak256, ruint::aliases::U64, B256, U256};
use crate::{
access_list::AccessListItem,
signature::{Signature, SignatureError},
transaction::{kind::TransactionKind, signed::EIP2930SignedTransaction},
transaction::{kind::TransactionKind, signed::Eip2930SignedTransaction},
utils::envelop_bytes,
};

Expand Down Expand Up @@ -36,12 +36,12 @@ impl EIP2930TransactionRequest {
}

/// Signs the transaction with the provided secret key.
pub fn sign(self, secret_key: &SecretKey) -> Result<EIP2930SignedTransaction, SignatureError> {
pub fn sign(self, secret_key: &SecretKey) -> Result<Eip2930SignedTransaction, SignatureError> {
let hash = self.hash();

let signature = Signature::new(hash, secret_key)?;

Ok(EIP2930SignedTransaction {
Ok(Eip2930SignedTransaction {
chain_id: self.chain_id,
nonce: self.nonce,
gas_price: self.gas_price,
Expand All @@ -58,8 +58,8 @@ impl EIP2930TransactionRequest {
}
}

impl From<&EIP2930SignedTransaction> for EIP2930TransactionRequest {
fn from(tx: &EIP2930SignedTransaction) -> Self {
impl From<&Eip2930SignedTransaction> for EIP2930TransactionRequest {
fn from(tx: &Eip2930SignedTransaction) -> Self {
Self {
chain_id: tx.chain_id,
nonce: tx.nonce,
Expand Down
14 changes: 7 additions & 7 deletions crates/edr_eth/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
use super::kind::TransactionKind;

pub use self::{
eip155::EIP155SignedTransaction, eip1559::EIP1559SignedTransaction,
eip2930::EIP2930SignedTransaction, eip4844::Eip4844SignedTransaction,
eip155::EIP155SignedTransaction, eip1559::Eip1559SignedTransaction,
eip2930::Eip2930SignedTransaction, eip4844::Eip4844SignedTransaction,
legacy::LegacySignedTransaction,
};

Expand All @@ -29,9 +29,9 @@ pub enum SignedTransaction {
/// EIP-155 transaction
PostEip155Legacy(EIP155SignedTransaction),
/// EIP-2930 transaction
Eip2930(EIP2930SignedTransaction),
Eip2930(Eip2930SignedTransaction),
/// EIP-1559 transaction
Eip1559(EIP1559SignedTransaction),
Eip1559(Eip1559SignedTransaction),
/// EIP-4844 transaction
Eip4844(Eip4844SignedTransaction),
}
Expand Down Expand Up @@ -329,7 +329,7 @@ mod tests {
},
hash: OnceLock::new(),
}),
SignedTransaction::Eip2930(EIP2930SignedTransaction {
SignedTransaction::Eip2930(Eip2930SignedTransaction {
chain_id: 1,
nonce: 0,
gas_price: U256::from(1),
Expand All @@ -343,7 +343,7 @@ mod tests {
access_list: vec![].into(),
hash: OnceLock::new(),
}),
SignedTransaction::Eip1559(EIP1559SignedTransaction {
SignedTransaction::Eip1559(Eip1559SignedTransaction {
chain_id: 1u64,
nonce: 0,
max_priority_fee_per_gas: U256::from(1),
Expand Down Expand Up @@ -465,7 +465,7 @@ mod tests {
assert_eq!(expected, rlp::decode(&bytes_third).unwrap());

let bytes_fourth = hex::decode("02f872041a8459682f008459682f0d8252089461815774383099e24810ab832a5b2a5425c154d58829a2241af62c000080c001a059e6b67f48fb32e7e570dfb11e042b5ad2e55e3ce3ce9cd989c7e06e07feeafda0016b83f4f980694ed2eee4d10667242b1f40dc406901b34125b008d334d47469").unwrap();
let expected = SignedTransaction::Eip1559(EIP1559SignedTransaction {
let expected = SignedTransaction::Eip1559(Eip1559SignedTransaction {
chain_id: 4,
nonce: 26,
max_priority_fee_per_gas: U256::from(1500000000u64),
Expand Down
10 changes: 5 additions & 5 deletions crates/edr_eth/src/transaction/signed/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
derive(open_fastrlp::RlpEncodable, open_fastrlp::RlpDecodable)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EIP1559SignedTransaction {
pub struct Eip1559SignedTransaction {
#[cfg_attr(feature = "serde", serde(with = "crate::serde::u64"))]
pub chain_id: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::serde::u64"))]
Expand All @@ -38,7 +38,7 @@ pub struct EIP1559SignedTransaction {
pub hash: OnceLock<B256>,
}

impl EIP1559SignedTransaction {
impl Eip1559SignedTransaction {
pub fn nonce(&self) -> &u64 {
&self.nonce
}
Expand All @@ -64,7 +64,7 @@ impl EIP1559SignedTransaction {
}
}

impl PartialEq for EIP1559SignedTransaction {
impl PartialEq for Eip1559SignedTransaction {
fn eq(&self, other: &Self) -> bool {
self.chain_id == other.chain_id
&& self.nonce == other.nonce
Expand All @@ -81,7 +81,7 @@ impl PartialEq for EIP1559SignedTransaction {
}
}

impl rlp::Encodable for EIP1559SignedTransaction {
impl rlp::Encodable for Eip1559SignedTransaction {
fn rlp_append(&self, s: &mut rlp::RlpStream) {
s.begin_list(12);
s.append(&U64::from(self.chain_id));
Expand All @@ -99,7 +99,7 @@ impl rlp::Encodable for EIP1559SignedTransaction {
}
}

impl rlp::Decodable for EIP1559SignedTransaction {
impl rlp::Decodable for Eip1559SignedTransaction {
fn decode(rlp: &rlp::Rlp<'_>) -> Result<Self, rlp::DecoderError> {
if rlp.item_count()? != 12 {
return Err(rlp::DecoderError::RlpIncorrectListLen);
Expand Down
10 changes: 5 additions & 5 deletions crates/edr_eth/src/transaction/signed/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
derive(open_fastrlp::RlpEncodable, open_fastrlp::RlpDecodable)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EIP2930SignedTransaction {
pub struct Eip2930SignedTransaction {
#[cfg_attr(feature = "serde", serde(with = "crate::serde::u64"))]
pub chain_id: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::serde::u64"))]
Expand All @@ -37,7 +37,7 @@ pub struct EIP2930SignedTransaction {
pub hash: OnceLock<B256>,
}

impl EIP2930SignedTransaction {
impl Eip2930SignedTransaction {
pub fn nonce(&self) -> &u64 {
&self.nonce
}
Expand All @@ -63,7 +63,7 @@ impl EIP2930SignedTransaction {
}
}

impl PartialEq for EIP2930SignedTransaction {
impl PartialEq for Eip2930SignedTransaction {
fn eq(&self, other: &Self) -> bool {
self.chain_id == other.chain_id
&& self.nonce == other.nonce
Expand All @@ -79,7 +79,7 @@ impl PartialEq for EIP2930SignedTransaction {
}
}

impl rlp::Encodable for EIP2930SignedTransaction {
impl rlp::Encodable for Eip2930SignedTransaction {
fn rlp_append(&self, s: &mut rlp::RlpStream) {
s.begin_list(11);
s.append(&U64::from(self.chain_id));
Expand All @@ -96,7 +96,7 @@ impl rlp::Encodable for EIP2930SignedTransaction {
}
}

impl rlp::Decodable for EIP2930SignedTransaction {
impl rlp::Decodable for Eip2930SignedTransaction {
fn decode(rlp: &rlp::Rlp<'_>) -> Result<Self, rlp::DecoderError> {
if rlp.item_count()? != 11 {
return Err(rlp::DecoderError::RlpIncorrectListLen);
Expand Down
Loading

0 comments on commit 9ac4bf5

Please sign in to comment.