Skip to content

Commit 51b61a2

Browse files
authored
EPROD-563 blockchain update methods and disable evm method (#71)
1 parent ebe09ff commit 51b61a2

1 file changed

Lines changed: 48 additions & 2 deletions

File tree

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

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
use candid::Principal;
2-
use did::block::BlockResult;
3-
use did::{BasicAccount, BlockNumber, Bytes, Transaction, TransactionReceipt, H160, H256, U256};
2+
use did::block::{BlockResult, ExeResult};
3+
use did::error::Result;
4+
use did::{
5+
BasicAccount, Block, BlockNumber, Bytes, Transaction, TransactionReceipt, H160, H256, U256,
6+
};
47
use ic_canister_client::{CanisterClient, CanisterClientResult};
58

69
use crate::EvmResult;
710

11+
type BlockWithData = Vec<(Block<H256>, Vec<(Transaction, ExeResult)>)>;
12+
813
/// An EVM canister client.
914
#[derive(Debug)]
1015
pub struct EvmCanisterClient<C>
@@ -431,6 +436,47 @@ impl<C: CanisterClient> EvmCanisterClient<C> {
431436
.await
432437
}
433438

439+
/// Revert the blockchain to a certain block, identified by the provided number.
440+
///
441+
/// # Arguments
442+
///
443+
/// * `block_number` - The block number to revert to.
444+
///
445+
/// # Returns
446+
///
447+
/// - The new last block.
448+
pub async fn revert_blockchain_to_block(
449+
&self,
450+
block_number: u64,
451+
) -> CanisterClientResult<Result<u64>> {
452+
self.client
453+
.update("revert_blockchain_to_block", (block_number,))
454+
.await
455+
}
456+
457+
/// Append blocks to the blockchain. If the blocks already exist in the blockchain, they will be overwritten.
458+
///
459+
/// # Arguments
460+
///
461+
/// * `blocks_with_data` - The blocks to append to the blockchain.
462+
pub async fn append_blockchain_blocks(
463+
&self,
464+
blocks_with_data: BlockWithData,
465+
) -> CanisterClientResult<Result<()>> {
466+
self.client
467+
.update("append_blockchain_blocks", (blocks_with_data,))
468+
.await
469+
}
470+
471+
/// Disable or enable the EVM. This function requires admin permissions.
472+
///
473+
/// # Arguments
474+
///
475+
/// * `disabled` - Whether to disable or enable the EVM.
476+
pub async fn admin_disable_evm(&self, disabled: bool) -> CanisterClientResult<Result<()>> {
477+
self.client.update("admin_disable_evm", (disabled,)).await
478+
}
479+
434480
/// Returns the chain ID used for signing replay-protected transactions.
435481
/// See [eth_chainid] (https://eth.wiki/json-rpc/API#eth_chainid)
436482
///

0 commit comments

Comments
 (0)