|
1 | 1 | 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 | +}; |
4 | 7 | use ic_canister_client::{CanisterClient, CanisterClientResult}; |
5 | 8 |
|
6 | 9 | use crate::EvmResult; |
7 | 10 |
|
| 11 | +type BlockWithData = Vec<(Block<H256>, Vec<(Transaction, ExeResult)>)>; |
| 12 | + |
8 | 13 | /// An EVM canister client. |
9 | 14 | #[derive(Debug)] |
10 | 15 | pub struct EvmCanisterClient<C> |
@@ -431,6 +436,47 @@ impl<C: CanisterClient> EvmCanisterClient<C> { |
431 | 436 | .await |
432 | 437 | } |
433 | 438 |
|
| 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 | + |
434 | 480 | /// Returns the chain ID used for signing replay-protected transactions. |
435 | 481 | /// See [eth_chainid] (https://eth.wiki/json-rpc/API#eth_chainid) |
436 | 482 | /// |
|
0 commit comments