Skip to content

Commit

Permalink
EVM: support for eth_accounts (#843)
Browse files Browse the repository at this point in the history
* eth_accounts

* estimateGas
  • Loading branch information
bkolad authored and preston-evans98 committed Sep 14, 2023
1 parent 9b073a6 commit 05b5965
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
11 changes: 11 additions & 0 deletions examples/demo-rollup/tests/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ impl TestClient {
Ok(ethereum_types::U256::from(resp_array))
}

async fn eth_accounts(&self) -> Vec<Address> {
self.http_client
.request("eth_accounts", rpc_params![])
.await
.unwrap()
}

async fn execute(self) -> Result<(), Box<dyn std::error::Error>> {
let contract_address = {
let deploy_contract_req = self.deploy_contract().await?;
Expand Down Expand Up @@ -189,6 +196,10 @@ async fn send_tx_test_to_eth(rpc_address: SocketAddr) -> Result<(), Box<dyn std:
let from_addr = Address::from_str("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266").unwrap();

let test_client = TestClient::new(chain_id, key, from_addr, contract, rpc_address).await;

let etc_accounts = test_client.eth_accounts().await;
assert_eq!(vec![from_addr], etc_accounts);

test_client.execute().await
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const pairArtifact = require('@uniswap/v2-periphery/build/IUniswapV2Pair.json')
async function main() {
const [owner, trader] = await ethers.getSigners()


const Usdt = await ethers.getContractFactory('Tether', owner);
const usdt = await Usdt.deploy();
const Usdc = await ethers.getContractFactory('UsdCoin', owner);
Expand Down
13 changes: 2 additions & 11 deletions full-node/sov-ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,8 @@ pub mod experimental {
},
)?;

rpc.register_async_method("eth_accounts", |_parameters, _ethereum| async move {
#[allow(unreachable_code)]
Ok::<_, ErrorObjectOwned>(todo!())
})?;

rpc.register_async_method("eth_estimateGas", |parameters, _ethereum| async move {
let mut params = parameters.sequence();
let _data: reth_rpc_types::CallRequest = params.next()?;
let _block_number: Option<reth_primitives::BlockId> = params.optional_next()?;
#[allow(unreachable_code)]
Ok::<_, ErrorObjectOwned>(todo!())
rpc.register_async_method("eth_accounts", |_parameters, ethereum| async move {
Ok::<_, ErrorObjectOwned>(ethereum.eth_rpc_config.eth_signer.signers())
})?;

Ok(())
Expand Down
10 changes: 10 additions & 0 deletions module-system/module-implementations/sov-evm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,14 @@ impl<C: sov_modules_api::Context> Evm<C> {
) -> RpcResult<reth_primitives::U256> {
unimplemented!("eth_blockNumber not implemented")
}

#[rpc_method(name = "estimateGas")]
pub fn eth_estimate_gas(
&self,
_data: reth_rpc_types::CallRequest,
_block_number: Option<reth_primitives::BlockId>,
_working_set: &mut WorkingSet<C::Storage>,
) -> RpcResult<reth_primitives::U256> {
unimplemented!("eth_sendTransaction not implemented")
}
}

0 comments on commit 05b5965

Please sign in to comment.