Skip to content

Commit

Permalink
evm: Add access list and chain ID to TX output (#2224)
Browse files Browse the repository at this point in the history
* Add access list and chain ID to TX output

* Undo test changes

* Use chain_id from SignedTx
  • Loading branch information
shohamc1 authored Jul 26, 2023
1 parent 3919458 commit 8f153a0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/ain-evm/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ impl SignedTx {
TransactionV2::EIP1559(tx) => Some(tx.max_priority_fee_per_gas),
}
}

pub fn chain_id(&self) -> u64 {
match &self.transaction {
TransactionV2::Legacy(tx) => tx.signature.chain_id().unwrap_or_default(),
TransactionV2::EIP2930(tx) => tx.chain_id,
TransactionV2::EIP1559(tx) => tx.chain_id,
}
}
}

use std::convert::{TryFrom, TryInto};
Expand Down
35 changes: 33 additions & 2 deletions lib/ain-grpc/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use ain_evm::transaction::{SignedTx, TransactionError};
use ethereum::EnvelopedEncodable;
use ethereum::{AccessListItem, EnvelopedEncodable};
use ethereum::{BlockAny, TransactionV2};
use primitive_types::{H256, U256};

use crate::{
codegen::types::EthTransactionInfo,
codegen::types::{EthAccessList, EthTransactionInfo},
utils::{format_address, format_h256, format_u256},
};

Expand All @@ -16,6 +16,22 @@ impl From<SignedTx> for EthTransactionInfo {
format!("0x{}", hex::encode(signed_tx.data()))
};

let access_list: Vec<EthAccessList> = match &signed_tx.transaction {
TransactionV2::Legacy(_) => Vec::new(),
TransactionV2::EIP2930(tx) => tx
.access_list
.clone()
.into_iter()
.map(|list| list.into())
.collect(),
TransactionV2::EIP1559(tx) => tx
.access_list
.clone()
.into_iter()
.map(|list| list.into())
.collect(),
};

EthTransactionInfo {
hash: format_h256(signed_tx.transaction.hash()),
from: format_address(signed_tx.sender),
Expand All @@ -42,6 +58,21 @@ impl From<SignedTx> for EthTransactionInfo {
.max_priority_fee_per_gas()
.map(format_u256)
.unwrap_or_default(),
access_list,
chain_id: format!("{:#x}", signed_tx.chain_id()),
}
}
}

impl From<AccessListItem> for EthAccessList {
fn from(access_list: AccessListItem) -> Self {
Self {
address: format_address(access_list.address),
storage_keys: access_list
.storage_keys
.into_iter()
.map(format_h256)
.collect(),
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/proto/types/eth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ message EthTransactionInfo {
string type = 15; // Transaction type
string maxFeePerGas = 16; // Present in EIP1559 TXs
string maxPriorityFeePerGas = 17; // Present in EIP1559 TXs
repeated EthAccessList accessList = 18; // Transaction access list
string chainId = 19; // Transaction chain ID
}

message EthAccessList {
string address = 1;
repeated string storageKeys = 2;
}

message EthChainIdResult {
Expand Down

0 comments on commit 8f153a0

Please sign in to comment.