7 releases

0.2.5 Aug 22, 2022
0.2.4 Jul 12, 2022
0.2.2 May 12, 2022
0.1.0 Feb 3, 2022

#51 in #internet-computer

Download history 5/week @ 2024-12-14 2/week @ 2025-01-04 9/week @ 2025-01-11 1/week @ 2025-01-18 8/week @ 2025-02-01 17/week @ 2025-02-08 12/week @ 2025-02-15 27/week @ 2025-02-22 14/week @ 2025-03-01 5/week @ 2025-03-08 33/week @ 2025-03-15 26/week @ 2025-03-22 5/week @ 2025-03-29

70 downloads per month

Apache-2.0

415KB
7.5K SLoC

Certified Assets Library

Rust support for asset certification.

Certified assets can also be served from any Rust canister by including this library.

Adding to a canister

[dependencies]
ic-certified-assets = "0.2.2"

The assets are preserved over upgrades by including the corresponding functions in the init/pre_upgrade/upgrade hooks which can be mixed with the other state from the canister:

#[derive(Clone, Debug, CandidType, Deserialize)]
struct StableState {
  my_state: MyState,
  assets: crate::assets::StableState,
}

#[init]
fn init() {
  crate::assets::init();
}

#[pre_upgrade]
fn pre_upgrade() {
  let stable_state = STATE.with(|s| StableState {
    my_state: s.my_state,
    assets: crate::assets::pre_upgrade(),
  });
  ic_cdk::storage::stable_save((stable_state,)).expect("failed to save stable state");
}

#[post_upgrade]
fn post_upgrade() {
  let (StableState { assets, my_state },): (StableState,) =
                                         ic_cdk::storage::stable_restore().expect("failed to restore stable state");
  crate::assets::post_upgrade(assets);
  STATE.with(|s| {
      s.my_state = my_state;
  };
}

Uploading assets

cd assets
icx-asset --pem ~/.config/dfx/identity/default/identity.pem --replica https://ic0.app sync <canister_id> .

Dependencies

~7–15MB
~185K SLoC