From 8f153a0efca2b5c0f9077f9d33ac2f94124f0e06 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Wed, 26 Jul 2023 09:53:14 +0800 Subject: [PATCH] evm: Add access list and chain ID to TX output (#2224) * Add access list and chain ID to TX output * Undo test changes * Use chain_id from SignedTx --- lib/ain-evm/src/transaction/mod.rs | 8 +++++++ lib/ain-grpc/src/transaction.rs | 35 ++++++++++++++++++++++++++++-- lib/proto/types/eth.proto | 7 ++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/ain-evm/src/transaction/mod.rs b/lib/ain-evm/src/transaction/mod.rs index c5a46dd7da..230bae8bec 100644 --- a/lib/ain-evm/src/transaction/mod.rs +++ b/lib/ain-evm/src/transaction/mod.rs @@ -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}; diff --git a/lib/ain-grpc/src/transaction.rs b/lib/ain-grpc/src/transaction.rs index 4f8d885427..2b57b17af2 100644 --- a/lib/ain-grpc/src/transaction.rs +++ b/lib/ain-grpc/src/transaction.rs @@ -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}, }; @@ -16,6 +16,22 @@ impl From for EthTransactionInfo { format!("0x{}", hex::encode(signed_tx.data())) }; + let access_list: Vec = 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), @@ -42,6 +58,21 @@ impl From 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 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(), } } } diff --git a/lib/proto/types/eth.proto b/lib/proto/types/eth.proto index 3bc4f3f57f..328259366d 100644 --- a/lib/proto/types/eth.proto +++ b/lib/proto/types/eth.proto @@ -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 {