#[macro_export]
macro_rules! inject_canister_registry {
() => {
thread_local! {
pub static REGISTRY: RefCell<Registry> = RefCell::new(Registry::default());
}
use astrox_macros::registry::CanisterTrait;
use astrox_macros::registry::Registry;
use std::collections::BTreeMap;
pub fn canister_add(name: String, canister_id: Principal) {
REGISTRY.with(|s| s.borrow_mut().canister_add(name.clone(), canister_id));
on_canister_added(&name, canister_id);
}
pub fn canister_remove(name: String, canister_id: Principal) {
REGISTRY.with(|s| s.borrow_mut().canister_remove(name, canister_id));
}
pub fn canister_remove_all(name: String) {
REGISTRY.with(|s| s.borrow_mut().canister_remove_all(name));
}
pub fn canister_list() -> BTreeMap<String, Vec<Principal>> {
REGISTRY.with(|s| s.borrow().canister_list_all())
}
pub fn registry_pre_upgrade() -> Registry {
REGISTRY.with(|s| s.take().into())
}
pub fn registry_post_upgrade(stable_state: Registry) {
REGISTRY.with(|s| s.replace(stable_state));
}
};
}