|
1 | 1 | use candid::Principal; |
2 | 2 | use did::block::{BlockResult, ExeResult}; |
3 | 3 | use did::error::Result; |
| 4 | +use did::state::{BasicAccount, FullStorageValue, Indices, StateUpdateAction}; |
4 | 5 | use did::{ |
5 | | - BasicAccount, Block, BlockNumber, Bytes, EstimateGasRequest, Transaction, TransactionReceipt, |
6 | | - H160, H256, U256, |
| 6 | + Block, BlockNumber, Bytes, EstimateGasRequest, Transaction, TransactionReceipt, H160, H256, |
| 7 | + U256, |
7 | 8 | }; |
8 | 9 | use ic_canister_client::{CanisterClient, CanisterClientResult}; |
9 | 10 |
|
10 | 11 | use crate::EvmResult; |
11 | 12 |
|
12 | | -type BlockWithData = Vec<(Block<H256>, Vec<(Transaction, ExeResult)>)>; |
| 13 | +pub type BlockWithData = Vec<(Block<H256>, Vec<(Transaction, ExeResult)>)>; |
13 | 14 |
|
14 | 15 | /// An EVM canister client. |
15 | 16 | #[derive(Debug)] |
@@ -455,6 +456,129 @@ impl<C: CanisterClient> EvmCanisterClient<C> { |
455 | 456 | .await |
456 | 457 | } |
457 | 458 |
|
| 459 | + /// Returns requested part of low-level representation of EVM state. |
| 460 | + /// Supports pagination. |
| 461 | + /// |
| 462 | + /// # Arguments |
| 463 | + /// |
| 464 | + /// * `prev_key` - returned keys will be `key > prev_key` if provided. |
| 465 | + /// * `limit` - maximum number of keys to return. |
| 466 | + /// |
| 467 | + /// # Returns |
| 468 | + /// |
| 469 | + /// - Vector of ordered pairs `(storage_key, storage_value_hash)` with `len <= limit`. |
| 470 | + /// - First `storage_key > prev_key` if `prev_key` is `Some(_)`. |
| 471 | + /// |
| 472 | + /// # Errors |
| 473 | + /// |
| 474 | + /// - If evm-canister not disabled, returns `EvmError::Internal(msg)`; |
| 475 | + /// - If caller have not `Permission::UpdateBlockchain` permission, returns `EvmError::Unauthorized`; |
| 476 | + pub async fn get_state_storage_item_hashes( |
| 477 | + &self, |
| 478 | + prev_key: Option<H256>, |
| 479 | + limit: u32, |
| 480 | + ) -> CanisterClientResult<EvmResult<Vec<(H256, u128)>>> { |
| 481 | + self.client |
| 482 | + .query("get_state_storage_item_hashes", (prev_key, limit)) |
| 483 | + .await |
| 484 | + } |
| 485 | + |
| 486 | + /// Applies the given list of low-level state changes. |
| 487 | + /// |
| 488 | + /// # Arguments |
| 489 | + /// |
| 490 | + /// * `actions` - list of operations should be applied. |
| 491 | + /// |
| 492 | + /// # Errors |
| 493 | + /// |
| 494 | + /// - If evm-canister not disabled, returns `EvmError::Internal(msg)`; |
| 495 | + /// - If caller have not `Permission::UpdateBlockchain` permission, returns `EvmError::Unauthorized`; |
| 496 | + pub async fn apply_state_storage_changes( |
| 497 | + &self, |
| 498 | + actions: Vec<StateUpdateAction<H256, FullStorageValue>>, |
| 499 | + ) -> CanisterClientResult<EvmResult<()>> { |
| 500 | + self.client |
| 501 | + .update("apply_state_storage_changes", (actions,)) |
| 502 | + .await |
| 503 | + } |
| 504 | + |
| 505 | + /// Returns requested part of low-level representation of EVM clear info. |
| 506 | + /// Supports pagination. |
| 507 | + /// |
| 508 | + /// # Arguments |
| 509 | + /// |
| 510 | + /// * `prev_key` - returned keys will be `key > prev_key` if provided. |
| 511 | + /// * `limit` - maximum number of keys to return. |
| 512 | + /// |
| 513 | + /// # Returns |
| 514 | + /// |
| 515 | + /// - Vector of ordered pairs `(key_1, key_2)` with `len <= limit`. |
| 516 | + /// - First pair `(key_1, key_2) > prev_key` if `prev_key` is `Some(_)`. |
| 517 | + /// |
| 518 | + /// # Errors |
| 519 | + /// |
| 520 | + /// - If evm-canister not disabled, returns `EvmError::Internal(msg)`; |
| 521 | + /// - If caller have not `Permission::UpdateBlockchain` permission, returns `EvmError::Unauthorized`; |
| 522 | + pub async fn get_clear_info_entries( |
| 523 | + &self, |
| 524 | + prev_key: Option<(u64, H256)>, |
| 525 | + limit: u32, |
| 526 | + ) -> CanisterClientResult<EvmResult<Vec<(u64, H256)>>> { |
| 527 | + self.client |
| 528 | + .query("get_clear_info_entries", (prev_key, limit)) |
| 529 | + .await |
| 530 | + } |
| 531 | + |
| 532 | + /// Applies the given list of low-level clear info changes. |
| 533 | + /// |
| 534 | + /// # Arguments |
| 535 | + /// |
| 536 | + /// * `actions` - list of operations should be applied. |
| 537 | + /// |
| 538 | + /// # Errors |
| 539 | + /// |
| 540 | + /// - If evm-canister not disabled, returns `EvmError::Internal(msg)`; |
| 541 | + /// - If caller have not `Permission::UpdateBlockchain` permission, returns `EvmError::Unauthorized`; |
| 542 | + pub async fn apply_clear_info_changes( |
| 543 | + &self, |
| 544 | + actions: Vec<StateUpdateAction<(u64, H256), ()>>, |
| 545 | + ) -> CanisterClientResult<EvmResult<()>> { |
| 546 | + self.client |
| 547 | + .update("apply_clear_info_changes", (actions,)) |
| 548 | + .await |
| 549 | + } |
| 550 | + |
| 551 | + /// Sets low-level storage indices. |
| 552 | + /// |
| 553 | + /// # Arguments |
| 554 | + /// |
| 555 | + /// * `indices` - indices to set. |
| 556 | + /// |
| 557 | + /// # Errors |
| 558 | + /// |
| 559 | + /// - If evm-canister not disabled, returns `EvmError::Internal(msg)`; |
| 560 | + /// - If caller have not `Permission::UpdateBlockchain` permission, returns `EvmError::Unauthorized`; |
| 561 | + pub async fn set_storage_indices( |
| 562 | + &self, |
| 563 | + indices: Indices, |
| 564 | + ) -> CanisterClientResult<EvmResult<()>> { |
| 565 | + self.client.update("set_storage_indices", (indices,)).await |
| 566 | + } |
| 567 | + |
| 568 | + /// Sets state root hash. |
| 569 | + /// |
| 570 | + /// # Arguments |
| 571 | + /// |
| 572 | + /// * `root` - root to set. |
| 573 | + /// |
| 574 | + /// # Errors |
| 575 | + /// |
| 576 | + /// - If evm-canister not disabled, returns `EvmError::Internal(msg)`; |
| 577 | + /// - If caller have not `Permission::UpdateBlockchain` permission, returns `EvmError::Unauthorized`; |
| 578 | + pub async fn set_state_root(&self, root: H256) -> CanisterClientResult<EvmResult<()>> { |
| 579 | + self.client.update("set_state_root", (root,)).await |
| 580 | + } |
| 581 | + |
458 | 582 | /// Updates the runtime configuration of the logger with a new filter in the same form as the `RUST_LOG` |
459 | 583 | /// environment variable. |
460 | 584 | /// Example of valid filters: |
|
0 commit comments