Skip to content

Commit

Permalink
feat: implement eth_estimateGas and zks_estimateFee (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
MexicanAce authored Aug 11, 2023
1 parent 3539ad0 commit 4ef5a96
Show file tree
Hide file tree
Showing 9 changed files with 547 additions and 53 deletions.
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"recommendations": [
"rust-lang.rust-analyzer",
"humao.rest-client",
"vadimcn.vscode-lldb"
],
}
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ lint:
cargo fmt --all -- --check
cargo clippy -Zunstable-options -- -D warnings --allow clippy::unwrap_used

# Fix lint errors for Rust code
lint-fix:
cargo clippy --fix
cargo fmt

# Run unit tests for Rust code
test:
cargo test
Expand Down
2 changes: 1 addition & 1 deletion SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
| `EVM` | `evm_setTime` | NOT IMPLEMENTED | Sets the internal clock time to the given timestamp |
| `EVM` | `evm_snapshot` | NOT IMPLEMENTED | Snapshot the state of the blockchain at the current block |
| [`ETH`](#eth-namespace) | [`eth_chainId`](#eth_chainid) | SUPPORTED | Returns the currently configured chain id |
| [`ETH`](#eth-namespace) | [`eth_estimateGas`](#eth_estimategas) | PARTIALLY | Generates and returns an estimate of how much gas is necessary for the transaction to complete |
| [`ETH`](#eth-namespace) | [`eth_estimateGas`](#eth_estimategas) | SUPPORTED | Generates and returns an estimate of how much gas is necessary for the transaction to complete |
| [`ETH`](#eth-namespace) | [`eth_gasPrice`](#eth_gasprice) | SUPPORTED | Returns the current price per gas in wei |
| [`ETH`](#eth-namespace) | [`eth_getBalance`](#eth_getbalance) | SUPPORTED | Returns the balance of the account of given address |
| [`ETH`](#eth-namespace) | [`eth_getBlockByNumber`](#eth_getblockbynumber) | PARTIALLY | Returns information about a block by block number |
Expand Down
2 changes: 1 addition & 1 deletion src/deps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fmt;
use self::system_contracts::COMPILED_IN_SYSTEM_CONTRACTS;

/// In-memory storage.
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct InMemoryStorage {
pub(crate) state: HashMap<StorageKey, StorageValue>,
pub(crate) factory_deps: HashMap<H256, Vec<u8>>,
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async fn build_json_http(
node: InMemoryNode,
net: NetNamespace,
config_api: ConfigurationApiNamespace,
zks: ZkMockNamespaceImpl,
) -> tokio::task::JoinHandle<()> {
let (sender, recv) = oneshot::channel::<()>();

Expand All @@ -116,7 +117,7 @@ async fn build_json_http(
io.extend_with(node.to_delegate());
io.extend_with(net.to_delegate());
io.extend_with(config_api.to_delegate());
io.extend_with(ZkMockNamespaceImpl.to_delegate());
io.extend_with(zks.to_delegate());

io
};
Expand Down Expand Up @@ -292,14 +293,15 @@ async fn main() -> anyhow::Result<()> {
}

let net = NetNamespace::new(L2ChainId(TEST_NODE_NETWORK_ID));

let config_api = ConfigurationApiNamespace::new(node.get_inner());
let zks = ZkMockNamespaceImpl::new(node.get_inner());

let threads = build_json_http(
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), opt.port),
node,
net,
config_api,
zks,
)
.await;

Expand Down
Loading

0 comments on commit 4ef5a96

Please sign in to comment.