diff --git a/lib/ain-evm/src/evm.rs b/lib/ain-evm/src/evm.rs index 9c9fbe1bd0..0e8b2b4c38 100644 --- a/lib/ain-evm/src/evm.rs +++ b/lib/ain-evm/src/evm.rs @@ -98,13 +98,17 @@ impl EVMHandler { data: &[u8], gas_limit: u64, access_list: AccessList, + block_number: U256, ) -> Result> { let (state_root, block_number) = self .storage - .get_latest_block() + .get_block_by_number(&block_number) .map(|block| (block.header.state_root, block.header.number)) .unwrap_or_default(); - println!("state_root : {:#?}", state_root); + debug!( + "Calling EVM at block number : {:#x}, state_root : {:#x}", + block_number, state_root + ); let vicinity = Vicinity { block_number, @@ -183,6 +187,7 @@ impl EVMHandler { signed_tx.data(), signed_tx.gas_limit().as_u64(), signed_tx.access_list(), + block_number, ) { Ok(TxResponse { exit_reason, .. }) if exit_reason.is_succeed() => Ok(signed_tx), Ok(TxResponse { exit_reason, .. }) => { diff --git a/lib/ain-grpc/src/rpc/eth.rs b/lib/ain-grpc/src/rpc/eth.rs index 673dbc6ec3..89f49548ef 100644 --- a/lib/ain-grpc/src/rpc/eth.rs +++ b/lib/ain-grpc/src/rpc/eth.rs @@ -133,16 +133,8 @@ pub trait MetachainRPC { #[method(name = "getTransactionReceipt")] fn get_receipt(&self, hash: H256) -> RpcResult>; - /// Retrieves the number of transactions sent from a specific address. - #[method(name = "getTransactionCount")] - fn get_transaction_count( - &self, - address: H160, - block_number: Option, - ) -> RpcResult; - // ---------------------------------------- - // State + // Account state // ---------------------------------------- /// Retrieves the balance of a specific Ethereum address at a given block number. @@ -163,6 +155,14 @@ pub trait MetachainRPC { block_number: Option, ) -> RpcResult; + /// Retrieves the number of transactions sent from a specific address. + #[method(name = "eth_getTransactionCount")] + fn get_transaction_count( + &self, + address: H160, + block_number: Option, + ) -> RpcResult; + // ---------------------------------------- // Send // ---------------------------------------- @@ -182,8 +182,12 @@ pub trait MetachainRPC { // ---------------------------------------- /// Estimate gas needed for execution of given contract. - #[method(name = "estimateGas")] - fn estimate_gas(&self, input: CallRequest) -> RpcResult; + #[method(name = "eth_estimateGas")] + fn estimate_gas( + &self, + input: CallRequest, + block_number: Option, + ) -> RpcResult; /// Returns current gas_price. #[method(name = "gasPrice")] @@ -235,7 +239,7 @@ impl MetachainRPCModule { } impl MetachainRPCServer for MetachainRPCModule { - fn call(&self, input: CallRequest, _block_number: Option) -> RpcResult { + fn call(&self, input: CallRequest, block_number: Option) -> RpcResult { debug!(target:"rpc", "[RPC] Call input {:#?}", input); let CallRequest { from, @@ -255,6 +259,7 @@ impl MetachainRPCServer for MetachainRPCModule { &data.map(|d| d.0).unwrap_or_default(), gas.unwrap_or_default().as_u64(), vec![], + self.block_number_to_u256(block_number), ) .map_err(|e| Error::Custom(format!("Error calling EVM : {e:?}")))?; @@ -600,7 +605,11 @@ impl MetachainRPCServer for MetachainRPCModule { Ok(nonce) } - fn estimate_gas(&self, input: CallRequest) -> RpcResult { + fn estimate_gas( + &self, + input: CallRequest, + block_number: Option, + ) -> RpcResult { let CallRequest { from, to, @@ -610,6 +619,7 @@ impl MetachainRPCServer for MetachainRPCModule { .. } = input; + let block_number = self.block_number_to_u256(block_number); let TxResponse { used_gas, .. } = self .handler .evm @@ -620,10 +630,11 @@ impl MetachainRPCServer for MetachainRPCModule { &data.map(|d| d.0).unwrap_or_default(), gas.unwrap_or(U256::from(u64::MAX)).as_u64(), vec![], + block_number, ) .map_err(|e| Error::Custom(format!("Error calling EVM : {e:?}")))?; - debug!(target:"rpc","estimateGas: {:#?}", used_gas); + debug!(target:"rpc", "estimateGas: {:#?} at block {:#x}", used_gas, block_number); Ok(U256::from(used_gas)) }