Skip to content

Commit 3758025

Browse files
committed
AssetCanister: Allow state access by the lib consumer
1 parent 597d0a1 commit 3758025

File tree

1 file changed

+11
-2
lines changed
  • src/canisters/frontend/ic-certified-assets/src

1 file changed

+11
-2
lines changed

src/canisters/frontend/ic-certified-assets/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ thread_local! {
3232
static STATE: RefCell<State> = RefCell::new(State::default());
3333
}
3434

35+
pub fn with_state<F, R>(f: F) -> R
36+
where
37+
F: FnOnce(&State) -> R,
38+
{
39+
STATE.with(|s| f(&s.borrow()))
40+
}
41+
42+
43+
3544
#[query]
3645
#[candid_method(query)]
3746
fn api_version() -> u16 {
@@ -387,11 +396,11 @@ fn can(permission: Permission) -> Result<(), String> {
387396
})
388397
}
389398

390-
fn can_commit() -> Result<(), String> {
399+
pub fn can_commit() -> Result<(), String> {
391400
can(Permission::Commit)
392401
}
393402

394-
fn can_prepare() -> Result<(), String> {
403+
pub fn can_prepare() -> Result<(), String> {
395404
can(Permission::Prepare)
396405
}
397406

0 commit comments

Comments
 (0)