-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,861 additions
and
2,302 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,68 @@ | ||
use std::cell::RefCell; | ||
use std::collections::{BTreeMap, HashMap}; | ||
use std::collections::{BTreeMap, BTreeSet}; | ||
|
||
use calimero_context_config::icp::repr::ICRepr; | ||
use calimero_context_config::icp::types::{ICApplication, ICCapability, ICRequest, ICSigned}; | ||
use calimero_context_config::types::{ContextId, ContextIdentity, SignerId}; | ||
use candid::{CandidType, Principal}; | ||
use guard::Guard; | ||
use serde::{Deserialize, Serialize}; | ||
use serde::Deserialize; | ||
|
||
use crate::types::{ | ||
ICApplication, ICCapability, ICContextId, ICContextIdentity, ICPSigned, ICSignerId, Request, | ||
}; | ||
mod guard; | ||
mod mutate; | ||
mod query; | ||
mod sys; | ||
|
||
pub mod guard; | ||
pub mod mutate; | ||
pub mod query; | ||
pub mod sys; | ||
pub mod types; | ||
use guard::Guard; | ||
|
||
#[derive(CandidType, Serialize, Deserialize, Clone, Debug)] | ||
thread_local! { | ||
pub static CONTEXT_CONFIGS: RefCell<Option<ContextConfigs>> = RefCell::new(None); | ||
} | ||
|
||
#[derive(CandidType, Deserialize, Debug)] | ||
pub struct Context { | ||
pub application: Guard<ICApplication>, | ||
pub members: Guard<Vec<ICContextIdentity>>, | ||
pub members: Guard<BTreeSet<ICRepr<ContextIdentity>>>, | ||
pub proxy: Guard<Principal>, | ||
} | ||
|
||
#[derive(CandidType, Deserialize, Clone, Debug)] | ||
#[derive(CandidType, Deserialize, Debug)] | ||
pub struct ContextConfigs { | ||
pub contexts: HashMap<ICContextId, Context>, | ||
pub contexts: BTreeMap<ICRepr<ContextId>, Context>, | ||
pub proxy_code: Option<Vec<u8>>, | ||
pub owner: Principal, | ||
pub ledger_id: Principal, | ||
} | ||
|
||
impl Default for ContextConfigs { | ||
fn default() -> Self { | ||
Self { | ||
contexts: HashMap::new(), | ||
#[ic_cdk::init] | ||
fn init() { | ||
CONTEXT_CONFIGS.with(|state| { | ||
*state.borrow_mut() = Some(ContextConfigs { | ||
contexts: BTreeMap::new(), | ||
proxy_code: None, | ||
owner: ic_cdk::api::caller(), | ||
ledger_id: Principal::anonymous(), | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
thread_local! { | ||
pub static CONTEXT_CONFIGS: RefCell<ContextConfigs> = RefCell::new(ContextConfigs::default()); | ||
fn with_state<F, R>(f: F) -> R | ||
where | ||
F: FnOnce(&ContextConfigs) -> R, | ||
{ | ||
CONTEXT_CONFIGS.with(|configs| { | ||
let configs = configs.borrow(); | ||
f(configs.as_ref().expect("cannister is being upgraded")) | ||
}) | ||
} | ||
|
||
#[ic_cdk::init] | ||
fn init() { | ||
CONTEXT_CONFIGS.with(|state| { | ||
*state.borrow_mut() = ContextConfigs::default(); | ||
}); | ||
fn with_state_mut<F, R>(f: F) -> R | ||
where | ||
F: FnOnce(&mut ContextConfigs) -> R, | ||
{ | ||
CONTEXT_CONFIGS.with(|configs| { | ||
let mut configs = configs.borrow_mut(); | ||
f(configs.as_mut().expect("cannister is being upgraded")) | ||
}) | ||
} | ||
|
||
ic_cdk::export_candid!(); |
Oops, something went wrong.