Skip to content

Commit 0287613

Browse files
authored
Merge pull request #246 from bitfinity-network/feat/upgrade-info
feat: upgrade info types
2 parents 6c06fbf + eaec59c commit 0287613

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/did/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub mod http;
3030
pub mod rpc;
3131
#[cfg(test)]
3232
mod test_utils;
33+
pub mod upgrade_info;
3334
pub mod utils;
3435

3536
pub use block::Block;

src/did/src/upgrade_info.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::borrow::Cow;
2+
3+
use candid::{CandidType, Decode, Encode};
4+
use ic_stable_structures::{Bound, Storable};
5+
use serde::Deserialize;
6+
7+
use crate::build::BuildData;
8+
9+
#[derive(CandidType, Deserialize, Clone, Debug)]
10+
/// Information about a canister upgrade, tracking deployment details and blockchain state.
11+
pub struct UpgradeInfo {
12+
/// Compilation and build information for the deployed canister version
13+
pub build_data: BuildData,
14+
/// Unix timestamp (in seconds) when the upgrade was deployed.
15+
pub deploy_ts: u64,
16+
/// The blockchain block number at the time the upgrade was performed.
17+
pub last_block_number: u64,
18+
}
19+
20+
impl Storable for UpgradeInfo {
21+
const BOUND: Bound = Bound::Unbounded;
22+
23+
fn to_bytes(&self) -> std::borrow::Cow<[u8]> {
24+
Cow::from(Encode!(&self).expect("Failed to encode UpgradeInfo"))
25+
}
26+
27+
fn from_bytes(bytes: Cow<[u8]>) -> Self {
28+
Decode!(&bytes, UpgradeInfo).expect("Failed to decode UpgradeInfo")
29+
}
30+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use did::send_raw_transaction::SendRawTransactionRequest;
99
use did::state::BasicAccount;
1010
use did::transaction::StorableExecutionResult;
1111
use did::unsafe_blocks::ValidateUnsafeBlockArgs;
12+
use did::upgrade_info::UpgradeInfo;
1213
use did::{
1314
Block, BlockConfirmationData, BlockConfirmationResult, BlockConfirmationStrategy, BlockNumber,
1415
BlockchainBlockInfo, BlockchainStorageLimits, Bytes, EstimateGasRequest, EvmStats, FeeHistory,
@@ -926,4 +927,9 @@ impl<C: CanisterClient> EvmCanisterClient<C> {
926927
pub async fn get_blockchain_block_info(&self) -> CanisterClientResult<BlockchainBlockInfo> {
927928
self.client.query("get_blockchain_block_info", ()).await
928929
}
930+
931+
/// Returns the details of the last `count` canister upgrades.
932+
pub async fn get_upgrade_info(&self, count: u64) -> CanisterClientResult<UpgradeInfo> {
933+
self.client.query("get_upgrade_info", (count,)).await
934+
}
929935
}

0 commit comments

Comments
 (0)