Skip to content

Commit 870270d

Browse files
committed
add rpc types for eth_callMany, eth_simulateV1, eth_createAccessList
1 parent 4eddc55 commit 870270d

File tree

13 files changed

+455
-76
lines changed

13 files changed

+455
-76
lines changed

Cargo.lock

+18-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cfxcore/executor/src/state/overlay_account/state_override.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl OverlayAccount {
3737
}
3838

3939
if let Some(nonce) = acc_overrides.nonce {
40-
acc.set_nonce(&U256::from(nonce));
40+
acc.set_nonce(&U256::from(nonce.as_u64()));
4141
}
4242

4343
if let Some(code) = acc_overrides.code.as_ref() {

crates/rpc/rpc-eth-api/src/eth.rs

+17-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use cfx_rpc_eth_types::{
2-
AccountPendingTransactions, Block, BlockNumber as BlockId, BlockOverrides,
2+
AccessListResult, AccountPendingTransactions, Block,
3+
BlockNumber as BlockId, BlockOverrides, Bundle, EthCallResponse,
34
EthRpcLogFilter as Filter, FeeHistory, Header, Log, Receipt,
4-
RpcStateOverride, SyncStatus, Transaction, TransactionRequest,
5+
RpcStateOverride, SimulatePayload, SimulatedBlock, StateContext,
6+
SyncStatus, Transaction, TransactionRequest,
57
};
68
use cfx_rpc_primitives::{Bytes, Index};
79
use cfx_types::{Address, H256, H64, U256, U64};
@@ -189,12 +191,10 @@ pub trait EthApi {
189191
/// `eth_simulateV1` executes an arbitrary number of transactions on top of
190192
/// the requested state. The transactions are packed into individual
191193
/// blocks. Overrides can be provided.
192-
// #[method(name = "simulateV1")]
193-
// async fn simulate_v1(
194-
// &self,
195-
// opts: SimBlock,
196-
// block_number: Option<BlockId>,
197-
// ) -> RpcResult<Vec<SimulatedBlock>>;
194+
#[method(name = "simulateV1")]
195+
async fn simulate_v1(
196+
&self, opts: SimulatePayload, block_number: Option<BlockId>,
197+
) -> RpcResult<Vec<SimulatedBlock>>;
198198

199199
/// Executes a new message call immediately without creating a transaction
200200
/// on the block chain.
@@ -207,13 +207,11 @@ pub trait EthApi {
207207

208208
/// Simulate arbitrary number of transactions at an arbitrary blockchain
209209
/// index, with the optionality of state overrides
210-
// #[method(name = "callMany")]
211-
// async fn call_many(
212-
// &self,
213-
// bundle: Bundle,
214-
// state_context: Option<StateContext>,
215-
// state_override: Option<StateOverride>,
216-
// ) -> RpcResult<Vec<EthCallResponse>>;
210+
#[method(name = "callMany")]
211+
async fn call_many(
212+
&self, bundle: Bundle, state_context: Option<StateContext>,
213+
state_override: Option<RpcStateOverride>,
214+
) -> RpcResult<Vec<EthCallResponse>>;
217215

218216
/// Generates an access list for a transaction.
219217
///
@@ -231,12 +229,10 @@ pub trait EthApi {
231229
/// could change when the transaction is actually mined. Adding an
232230
/// accessList to your transaction does not necessary result in lower
233231
/// gas usage compared to a transaction without an access list.
234-
// #[method(name = "createAccessList")]
235-
// async fn create_access_list(
236-
// &self,
237-
// request: TransactionRequest,
238-
// block_number: Option<BlockId>,
239-
// ) -> RpcResult<AccessListResult>;
232+
#[method(name = "createAccessList")]
233+
async fn create_access_list(
234+
&self, request: TransactionRequest, block_number: Option<BlockId>,
235+
) -> RpcResult<AccessListResult>;
240236

241237
/// Generates and returns an estimate of how much gas is necessary to allow
242238
/// the transaction to complete.

crates/rpc/rpc-eth-impl/src/eth.rs

+28-20
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ use cfx_rpc_cfx_types::{
1010
};
1111
use cfx_rpc_eth_api::EthApiServer;
1212
use cfx_rpc_eth_types::{
13-
AccountOverride, AccountPendingTransactions, Block, BlockNumber as BlockId,
14-
BlockOverrides, EthRpcLogFilter, EthRpcLogFilter as Filter, EvmOverrides,
15-
FeeHistory, Header, Log, Receipt, RpcStateOverride, SyncInfo, SyncStatus,
16-
Transaction, TransactionRequest,
13+
AccessListResult, AccountOverride, AccountPendingTransactions, Block,
14+
BlockNumber as BlockId, BlockOverrides, Bundle, EthCallResponse,
15+
EthRpcLogFilter, EthRpcLogFilter as Filter, EvmOverrides, FeeHistory,
16+
Header, Log, Receipt, RpcStateOverride, SimulatePayload, SimulatedBlock,
17+
StateContext, SyncInfo, SyncStatus, Transaction, TransactionRequest,
1718
};
1819
use cfx_rpc_primitives::{Bytes, Index, U64 as HexU64};
1920
use cfx_rpc_utils::error::{
@@ -1281,11 +1282,13 @@ impl EthApiServer for EthApi {
12811282
/// `eth_simulateV1` executes an arbitrary number of transactions on top of
12821283
/// the requested state. The transactions are packed into individual
12831284
/// blocks. Overrides can be provided.
1284-
// async fn simulate_v1(
1285-
// &self,
1286-
// opts: SimBlock,
1287-
// block_number: Option<BlockId>,
1288-
// ) -> RpcResult<Vec<SimulatedBlock>>;
1285+
async fn simulate_v1(
1286+
&self, opts: SimulatePayload, block_number: Option<BlockId>,
1287+
) -> RpcResult<Vec<SimulatedBlock>> {
1288+
let _ = block_number;
1289+
let _ = opts;
1290+
Err(jsonrpsee_internal_error("Not implemented"))
1291+
}
12891292

12901293
/// Executes a new message call immediately without creating a transaction
12911294
/// on the block chain.
@@ -1306,12 +1309,15 @@ impl EthApiServer for EthApi {
13061309

13071310
/// Simulate arbitrary number of transactions at an arbitrary blockchain
13081311
/// index, with the optionality of state overrides
1309-
// async fn call_many(
1310-
// &self,
1311-
// bundle: Bundle,
1312-
// state_context: Option<StateContext>,
1313-
// state_override: Option<StateOverride>,
1314-
// ) -> RpcResult<Vec<EthCallResponse>>;
1312+
async fn call_many(
1313+
&self, bundle: Bundle, state_context: Option<StateContext>,
1314+
state_override: Option<RpcStateOverride>,
1315+
) -> RpcResult<Vec<EthCallResponse>> {
1316+
let _ = bundle;
1317+
let _ = state_context;
1318+
let _ = state_override;
1319+
Err(jsonrpsee_internal_error("Not implemented"))
1320+
}
13151321

13161322
/// Generates an access list for a transaction.
13171323
///
@@ -1329,11 +1335,13 @@ impl EthApiServer for EthApi {
13291335
/// could change when the transaction is actually mined. Adding an
13301336
/// accessList to your transaction does not necessary result in lower
13311337
/// gas usage compared to a transaction without an access list.
1332-
// async fn create_access_list(
1333-
// &self,
1334-
// request: TransactionRequest,
1335-
// block_number: Option<BlockId>,
1336-
// ) -> RpcResult<AccessListResult>;
1338+
async fn create_access_list(
1339+
&self, request: TransactionRequest, block_number: Option<BlockId>,
1340+
) -> RpcResult<AccessListResult> {
1341+
let _ = block_number;
1342+
let _ = request;
1343+
Err(jsonrpsee_internal_error("Not implemented"))
1344+
}
13371345

13381346
/// Generates and returns an estimate of how much gas is necessary to allow
13391347
/// the transaction to complete.

crates/rpc/rpc-eth-types/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ cfx-rpc-primitives = { workspace = true }
2727
cfx-rpc-cfx-types = { workspace = true }
2828
cfx-parity-trace-types = { workspace = true }
2929
jsonrpsee = { workspace = true, features = ["jsonrpsee-types"] }
30-
similar-asserts = { workspace = true }
30+
similar-asserts = { workspace = true }
31+
32+
[features]
33+
default = ["serde"]
34+
serde = []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use cfx_types::U256;
2+
use primitives::AccessList;
3+
4+
/// Access list with gas used appended.
5+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
6+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7+
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
8+
pub struct AccessListWithGasUsed {
9+
/// List with accounts accessed during transaction.
10+
pub access_list: AccessList,
11+
/// Estimated gas used with access list.
12+
pub gas_used: U256,
13+
}
14+
15+
/// `AccessListResult` for handling errors from `eth_createAccessList`
16+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
17+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18+
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
19+
pub struct AccessListResult {
20+
/// List with accounts accessed during transaction.
21+
pub access_list: AccessList,
22+
/// Estimated gas used with access list.
23+
pub gas_used: U256,
24+
/// Optional error message if the transaction failed.
25+
#[cfg_attr(
26+
feature = "serde",
27+
serde(default, skip_serializing_if = "Option::is_none")
28+
)]
29+
pub error: Option<String>,
30+
}
31+
32+
impl AccessListResult {
33+
/// Ensures the result is OK, returning [`AccessListWithGasUsed`] if so, or
34+
/// an error message if not.
35+
pub fn ensure_ok(self) -> Result<AccessListWithGasUsed, String> {
36+
match self.error {
37+
Some(err) => Err(err),
38+
None => Ok(AccessListWithGasUsed {
39+
access_list: self.access_list,
40+
gas_used: self.gas_used,
41+
}),
42+
}
43+
}
44+
45+
/// Checks if there is an error in the result.
46+
#[inline]
47+
pub const fn is_err(&self) -> bool { self.error.is_some() }
48+
}

crates/rpc/rpc-eth-types/src/block_number.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use serde::{
2828
use std::{convert::TryFrom, fmt};
2929

3030
/// Represents rpc api block number param.
31-
#[derive(Debug, PartialEq, Clone, Hash, Eq)]
31+
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
3232
pub enum BlockNumber {
3333
/// Hash
3434
Hash {

0 commit comments

Comments
 (0)