Skip to content

Commit c0f8ef1

Browse files
authored
Merge pull request #244 from bitfinity-network/add_missing_evm_calls
Add missing methods to evm client
2 parents ec4128f + 78ef78f commit c0f8ef1

1 file changed

Lines changed: 67 additions & 2 deletions

File tree

src/evm-canister-client/src/client.rs

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use did::transaction::StorableExecutionResult;
1111
use did::unsafe_blocks::ValidateUnsafeBlockArgs;
1212
use did::{
1313
Block, BlockConfirmationData, BlockConfirmationResult, BlockConfirmationStrategy, BlockNumber,
14-
BlockchainBlockInfo, BlockchainStorageLimits, Bytes, EstimateGasRequest, EvmStats, H160, H256,
15-
Transaction, TransactionReceipt, U64, U256,
14+
BlockchainBlockInfo, BlockchainStorageLimits, Bytes, EstimateGasRequest, EvmStats, FeeHistory,
15+
H160, H256, Transaction, TransactionReceipt, U64, U256,
1616
};
1717
use ic_canister_client::{CanisterClient, CanisterClientResult};
1818
pub use ic_log::writer::{Log, Logs};
@@ -317,6 +317,55 @@ impl<C: CanisterClient> EvmCanisterClient<C> {
317317
.await
318318
}
319319

320+
/// Returns the maximum priority fee per gas that should be paid by a transaction
321+
/// to be included in the next block.
322+
///
323+
/// It uses a default gas ratio threshold of 75% to determine if a block is nearly empty.
324+
///
325+
/// Returns error variant only if there's no block data available.
326+
///
327+
/// See <https://docs.alchemy.com/reference/eth-maxpriorityfeepergas>.
328+
pub async fn eth_max_priority_fee_per_gas(&self) -> CanisterClientResult<EvmResult<U256>> {
329+
self.client.query("eth_max_priority_fee_per_gas", ()).await
330+
}
331+
332+
/// Reports the fee history, for the given amount of blocks, up until the
333+
/// newest block provided.
334+
///
335+
/// # JSON RPC
336+
///
337+
/// This method can also be called through PRC method [`eth_feeHistory`](evm_core::rpc::EthRpc::eth_fee_history).
338+
///
339+
/// # Ethereum spec
340+
///
341+
/// See <https://docs.alchemy.com/reference/eth-feehistory>.
342+
pub async fn eth_fee_history(
343+
&self,
344+
block_count: u64,
345+
newest_block: BlockNumber,
346+
reward_percentiles: Option<Vec<f64>>,
347+
) -> CanisterClientResult<EvmResult<FeeHistory>> {
348+
self.client
349+
.query(
350+
"eth_fee_history",
351+
(block_count, newest_block, reward_percentiles),
352+
)
353+
.await
354+
}
355+
356+
/// Returns an estimate of the current price per gas in wei.
357+
///
358+
/// # JSON RPC
359+
///
360+
/// This method can also be called by [`eth_gasPrice`](evm_core::rpc::EthRpc::eth_gas_price) JSON RPC method.
361+
///
362+
/// # Ethereum spec
363+
///
364+
/// See <https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gasprice>.
365+
pub async fn eth_gas_price(&self) -> CanisterClientResult<EvmResult<U256>> {
366+
self.client.query("eth_gas_price", ()).await
367+
}
368+
320369
/// Execute a call on the EVM without modifying the state
321370
/// See [eth_call](https://eth.wiki/json-rpc/API#eth_call)
322371
///
@@ -431,6 +480,12 @@ impl<C: CanisterClient> EvmCanisterClient<C> {
431480
self.client.query("get_evm_global_state", ()).await
432481
}
433482

483+
/// Returns the max pool size. This is the maximum amount of transactions
484+
/// that can be in the pool.
485+
pub async fn get_max_tx_pool_size(&self) -> CanisterClientResult<usize> {
486+
self.client.query("get_max_tx_pool_size", ()).await
487+
}
488+
434489
/// Sets the global state of the EVM.
435490
pub async fn admin_set_evm_global_state(
436491
&self,
@@ -493,6 +548,16 @@ impl<C: CanisterClient> EvmCanisterClient<C> {
493548
.await
494549
}
495550

551+
/// Sets the coinbase address.
552+
pub async fn admin_set_coinbase(&self, coinbase: H160) -> CanisterClientResult<EvmResult<()>> {
553+
self.client.update("admin_set_coinbase", (coinbase,)).await
554+
}
555+
556+
/// Removes all transactions from the transaction pool.
557+
pub async fn admin_clear_pool(&self) -> CanisterClientResult<EvmResult<()>> {
558+
self.client.update("admin_clear_pool", ()).await
559+
}
560+
496561
/// Returns whether unsafe blocks are enabled
497562
pub async fn is_unsafe_blocks_enabled(&self) -> CanisterClientResult<bool> {
498563
self.client.query("is_unsafe_blocks_enabled", ()).await

0 commit comments

Comments
 (0)