diff --git a/src/did/src/lib.rs b/src/did/src/lib.rs index 40ae49bd..4a7a4da0 100644 --- a/src/did/src/lib.rs +++ b/src/did/src/lib.rs @@ -30,6 +30,7 @@ pub mod http; pub mod rpc; #[cfg(test)] mod test_utils; +pub mod upgrade_info; pub mod utils; pub use block::Block; diff --git a/src/did/src/upgrade_info.rs b/src/did/src/upgrade_info.rs new file mode 100644 index 00000000..2630898a --- /dev/null +++ b/src/did/src/upgrade_info.rs @@ -0,0 +1,30 @@ +use std::borrow::Cow; + +use candid::{CandidType, Decode, Encode}; +use ic_stable_structures::{Bound, Storable}; +use serde::Deserialize; + +use crate::build::BuildData; + +#[derive(CandidType, Deserialize, Clone, Debug)] +/// Information about a canister upgrade, tracking deployment details and blockchain state. +pub struct UpgradeInfo { + /// Compilation and build information for the deployed canister version + pub build_data: BuildData, + /// Unix timestamp (in seconds) when the upgrade was deployed. + pub deploy_ts: u64, + /// The blockchain block number at the time the upgrade was performed. + pub last_block_number: u64, +} + +impl Storable for UpgradeInfo { + const BOUND: Bound = Bound::Unbounded; + + fn to_bytes(&self) -> std::borrow::Cow<[u8]> { + Cow::from(Encode!(&self).expect("Failed to encode UpgradeInfo")) + } + + fn from_bytes(bytes: Cow<[u8]>) -> Self { + Decode!(&bytes, UpgradeInfo).expect("Failed to decode UpgradeInfo") + } +} diff --git a/src/evm-canister-client/src/client.rs b/src/evm-canister-client/src/client.rs index 8e9b2eb6..5611a89f 100644 --- a/src/evm-canister-client/src/client.rs +++ b/src/evm-canister-client/src/client.rs @@ -9,6 +9,7 @@ use did::send_raw_transaction::SendRawTransactionRequest; use did::state::BasicAccount; use did::transaction::StorableExecutionResult; use did::unsafe_blocks::ValidateUnsafeBlockArgs; +use did::upgrade_info::UpgradeInfo; use did::{ Block, BlockConfirmationData, BlockConfirmationResult, BlockConfirmationStrategy, BlockNumber, BlockchainBlockInfo, BlockchainStorageLimits, Bytes, EstimateGasRequest, EvmStats, FeeHistory, @@ -926,4 +927,9 @@ impl EvmCanisterClient { pub async fn get_blockchain_block_info(&self) -> CanisterClientResult { self.client.query("get_blockchain_block_info", ()).await } + + /// Returns the details of the last `count` canister upgrades. + pub async fn get_upgrade_info(&self, count: u64) -> CanisterClientResult { + self.client.query("get_upgrade_info", (count,)).await + } }