Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/did/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions src/did/src/upgrade_info.rs
Original file line number Diff line number Diff line change
@@ -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")
}
}
6 changes: 6 additions & 0 deletions src/evm-canister-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -926,4 +927,9 @@ impl<C: CanisterClient> EvmCanisterClient<C> {
pub async fn get_blockchain_block_info(&self) -> CanisterClientResult<BlockchainBlockInfo> {
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<UpgradeInfo> {
self.client.query("get_upgrade_info", (count,)).await
}
}