Skip to content

Commit

Permalink
Merge branch 'main' into grw/impl-evm-mine-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
grw-ms authored Sep 18, 2023
2 parents 5983d2c + 35ac2c7 commit 5083ff0
Show file tree
Hide file tree
Showing 6 changed files with 696 additions and 183 deletions.
60 changes: 58 additions & 2 deletions SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ The `status` options are:
| [`ETH`](#eth-namespace) | [`eth_getBalance`](#eth_getbalance) | `SUPPORTED` | Returns the balance of the account of given address |
| [`ETH`](#eth-namespace) | [`eth_getBlockByHash`](#eth_getblockbyhash) | `SUPPORTED` | Returns information about a block by block hash |
| [`ETH`](#eth-namespace) | [`eth_getBlockByNumber`](#eth_getblockbynumber) | `SUPPORTED` | Returns information about a block by block number |
| `ETH` | `eth_getBlockTransactionCountByHash` | `NOT IMPLEMENTED`<br />[GitHub Issue #44](https://github.com/matter-labs/era-test-node/issues/44) | Number of transactions in a block from a block matching the given block hash |
| `ETH` | `eth_getBlockTransactionCountByNumber` | `NOT IMPLEMENTED`<br />[GitHub Issue #43](https://github.com/matter-labs/era-test-node/issues/43) | Number of transactions in a block from a block matching the given block number |
| [`ETH`](#eth-namespace) | [`eth_getBlockTransactionCountByHash`](#eth_getblocktransactioncountbyhash) | `SUPPORTED` | Number of transactions in a block from a block matching the given block hash |
| [`ETH`](#eth-namespace) | [`eth_getBlockTransactionCountByNumber`](#eth_getblocktransactioncountbynumber) | `SUPPORTED` | Number of transactions in a block from a block matching the given block number |
| `ETH` | `eth_getCompilers` | `NOT IMPLEMENTED` | Returns a list of available compilers |
| [`ETH`](#eth-namespace) | [`eth_getTransactionByHash`](#eth_gettransactionbyhash) | `SUPPORTED` | Returns the information about a transaction requested by transaction hash |
| [`ETH`](#eth-namespace) | [`eth_getTransactionCount`](#eth_gettransactioncount) | `SUPPORTED` | Returns the number of transactions sent from an address |
Expand Down Expand Up @@ -512,6 +512,62 @@ curl --request POST \
}'
```

### `eth_getBlockTransactionCountByHash`

[source](src/node.rs)

Number of transactions in a block from a block matching the given block hash

#### Arguments

+ `block_hash: H256`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": "1",
"method": "eth_getBlockTransactionCountByHash",
"params": ["0x0000000000000000000000000000000000000000000000000000000000000008"]
}'
```

### `eth_getBlockTransactionCountByNumber`

[source](src/node.rs)

Number of transactions in a block from a block matching the given block number

#### Arguments

+ `block_number: BlockNumber`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": "1",
"method": "eth_getBlockTransactionCountByNumber",
"params": ["latest"]
}'
```

### `eth_getCode`

[source](src/node.rs)
Expand Down
11 changes: 10 additions & 1 deletion src/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,16 @@ pub trait ForkSource {
&self,
block_number: zksync_types::api::BlockNumber,
full_transactions: bool,
) -> eyre::Result<Option<zksync_types::api::Block<zksync_types::api::TransactionVariant>>>;
) -> eyre::Result<Option<Block<TransactionVariant>>>;

/// Returns the transaction count for a given block hash.
fn get_block_transaction_count_by_hash(&self, block_hash: H256) -> eyre::Result<Option<U256>>;

/// Returns the transaction count for a given block number.
fn get_block_transaction_count_by_number(
&self,
block_number: zksync_types::api::BlockNumber,
) -> eyre::Result<Option<U256>>;
}

/// Holds the information about the original chain.
Expand Down
22 changes: 22 additions & 0 deletions src/http_fork_source.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::RwLock;

use eyre::Context;
use zksync_basic_types::{H256, U256};
use zksync_web3_decl::{
jsonrpsee::http_client::{HttpClient, HttpClientBuilder},
namespaces::{EthNamespaceClient, ZksNamespaceClient},
Expand Down Expand Up @@ -198,6 +199,27 @@ impl ForkSource for HttpForkSource {
})
.wrap_err("fork http client failed")
}

/// Returns the transaction count for a given block hash.
fn get_block_transaction_count_by_hash(&self, block_hash: H256) -> eyre::Result<Option<U256>> {
let client = self.create_client();
block_on(async move { client.get_block_transaction_count_by_hash(block_hash).await })
.wrap_err("fork http client failed")
}

/// Returns the transaction count for a given block number.
fn get_block_transaction_count_by_number(
&self,
block_number: zksync_types::api::BlockNumber,
) -> eyre::Result<Option<U256>> {
let client = self.create_client();
block_on(async move {
client
.get_block_transaction_count_by_number(block_number)
.await
})
.wrap_err("fork http client failed")
}
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 5083ff0

Please sign in to comment.