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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

# UNRELEASED

## Dependencies

### Frontend canister

#### feat: `get_state_info` returns last asset change timestamp and state hash

- Module hash: 15a6366a4823baf994f314a55ddbdda333dff11cbcc5114caebfe444e5eae3b6
- https://github.com/dfinity/sdk/pull/4434

# 0.30.1

### feat: asset sync now prints the target asset canister state hash in `--verbose` mode
Expand Down
8 changes: 8 additions & 0 deletions src/canisters/frontend/ic-certified-assets/assets.did
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ type ConfigureArguments = record {
max_bytes: opt opt nat64;
};

type StateInfo = record {
last_state_update_timestamp: nat64;
state_hash: opt text;
Copy link
Contributor

@ggreif ggreif Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this is hex-encoded. Did you also consider returning it as a blob?

};

type Permission = variant {
Commit;
ManagePermissions;
Expand Down Expand Up @@ -224,6 +229,9 @@ service: (asset_canister_args: opt AssetCanisterArgs) -> {
// Compute a hash over the canister content. Call until it returns Some(hash).
compute_state_hash: () -> (opt text);

// Get information about the current state of the canister
get_state_info: () -> (StateInfo) query;

// Delete a batch that has been created, or proposed for commit, but not yet committed
delete_batch: (DeleteBatchArguments) -> ();

Expand Down
10 changes: 10 additions & 0 deletions src/canisters/frontend/ic-certified-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ pub fn compute_state_hash() -> Option<String> {
with_state_mut(|s| s.compute_state_hash(&system_context))
}

pub fn get_state_info() -> StateInfo {
with_state(|s| s.get_state_info())
}

pub fn commit_proposed_batch(arg: CommitProposedBatchArguments) {
let system_context = SystemContext::new();

Expand Down Expand Up @@ -656,6 +660,12 @@ macro_rules! export_canister_methods {
$crate::compute_state_hash()
}

#[$crate::ic_certified_assets_query]
#[$crate::ic_certified_assets_candid_method(query)]
fn get_state_info() -> types::StateInfo {
$crate::get_state_info()
}

#[$crate::ic_certified_assets_update(guard = "__ic_certified_assets_can_commit")]
#[$crate::ic_certified_assets_candid_method(update)]
fn commit_proposed_batch(arg: types::CommitProposedBatchArguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,19 @@ impl State {
}
}

pub fn get_state_info(&self) -> StateInfo {
let state_hash =
if let Some(EvidenceComputation::Computed(evidence)) = &self.state_hash_computation {
Some(hex::encode(evidence.as_slice()))
} else {
None
};
StateInfo {
last_state_update_timestamp: self.last_state_update_timestamp_ns,
state_hash,
}
}

pub fn delete_batch(&mut self, arg: DeleteBatchArguments) -> Result<(), String> {
if self.batches.remove(&arg.batch_id).is_none() {
return Err("batch not found".to_string());
Expand Down
6 changes: 6 additions & 0 deletions src/canisters/frontend/ic-certified-assets/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ pub struct ConfigurationResponse {
pub max_bytes: Option<u64>,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub struct StateInfo {
pub last_state_update_timestamp: u64,
pub state_hash: Option<String>,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub struct CreateAssetArguments {
pub key: AssetKey,
Expand Down
8 changes: 8 additions & 0 deletions src/distributed/assetstorage.did
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ type ConfigureArguments = record {
max_bytes: opt opt nat64;
};

type StateInfo = record {
last_state_update_timestamp: nat64;
state_hash: opt text;
};

type Permission = variant {
Commit;
ManagePermissions;
Expand Down Expand Up @@ -224,6 +229,9 @@ service: (asset_canister_args: opt AssetCanisterArgs) -> {
// Compute a hash over the canister content. Call until it returns Some(hash).
compute_state_hash: () -> (opt text);

// Get information about the current state of the canister
get_state_info: () -> (StateInfo) query;

// Delete a batch that has been created, or proposed for commit, but not yet committed
delete_batch: (DeleteBatchArguments) -> ();

Expand Down
Binary file modified src/distributed/assetstorage.wasm.gz
Binary file not shown.
Loading