Skip to content

Commit

Permalink
fix: build typed tx (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing authored Oct 14, 2024
1 parent 2bafb0c commit a6f3612
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ pub trait TxTrace {
/// Get `access_list`.
fn access_list(&self) -> AccessList;

/// Get `v`.
fn v(&self) -> u64;

/// Get `signature`.
fn signature(&self) -> Result<Signature, SignatureError>;

Expand All @@ -205,7 +208,7 @@ pub trait TxTrace {
let tx = match self.ty() {
0x0 => {
let tx = TxLegacy {
chain_id: if chain_id >= 35 { Some(chain_id) } else { None },
chain_id: if self.v() >= 35 { Some(chain_id) } else { None },
nonce: self.nonce(),
gas_price: self.gas_price(),
gas_limit: self.gas_limit(),
Expand Down Expand Up @@ -391,6 +394,10 @@ impl<T: TxTrace> TxTrace for &T {
(*self).access_list()
}

fn v(&self) -> u64 {
(*self).v()
}

fn signature(&self) -> Result<Signature, SignatureError> {
(*self).signature()
}
Expand Down
9 changes: 9 additions & 0 deletions crates/primitives/src/types/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ impl TxTrace for TransactionTrace {
self.access_list.clone()
}

fn v(&self) -> u64 {
self.v.to()
}

fn signature(&self) -> Result<Signature, SignatureError> {
Signature::from_rs_and_parity(self.r, self.s, self.v)
}
Expand Down Expand Up @@ -262,6 +266,11 @@ impl TxTrace for ArchivedTransactionTrace {
rkyv::deserialize::<_, rancor::Error>(&self.access_list).unwrap()
}

fn v(&self) -> u64 {
let v: U64 = self.v.into();
v.to()
}

fn signature(&self) -> Result<Signature, SignatureError> {
let v: U64 = self.v.into();
Signature::from_rs_and_parity(self.r.into(), self.s.into(), v)
Expand Down

0 comments on commit a6f3612

Please sign in to comment.