-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add creator dao stats to platform orchestrator (#462)
* added creator dao stats to platform orchestrator * collect existing creator dao stats and added test * fix refactor issue
- Loading branch information
1 parent
091d6c3
commit eac8b32
Showing
23 changed files
with
350 additions
and
6 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
...er/individual_user_template/src/api/cdao/send_creator_dao_stats_to_subnet_orchestrator.rs
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::collections::HashSet; | ||
|
||
use candid::Principal; | ||
use ic_cdk_macros::update; | ||
use shared_utils::common::utils::permissions::is_caller_controller; | ||
|
||
use crate::{util::subnet_orchestrator::SubnetOrchestrator, CANISTER_DATA}; | ||
|
||
#[update(guard = "is_caller_controller")] | ||
fn send_creator_dao_stats_to_subnet_orchestrator() { | ||
let root_canisters: HashSet<Principal> = CANISTER_DATA.with_borrow(|canister_data| { | ||
canister_data | ||
.cdao_canisters | ||
.iter() | ||
.map(|deployed_canisters| deployed_canisters.root) | ||
.collect() | ||
}); | ||
|
||
let subnet_orchestrator = SubnetOrchestrator::new(); | ||
|
||
if let Ok(subnet_orchestrator) = subnet_orchestrator { | ||
match subnet_orchestrator.send_creator_dao_stats(root_canisters) { | ||
Ok(()) => {} | ||
Err(e) => { | ||
ic_cdk::println!("Error sending creator dao stats to subnet orchestrator {e}") | ||
} | ||
} | ||
} else { | ||
ic_cdk::println!("Subnet Orchestrator canister id not found"); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/canister/platform_orchestrator/src/api/stats/collect_creator_dao_stats_in_the_network.rs
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use ic_cdk::notify; | ||
use ic_cdk_macros::update; | ||
|
||
use crate::{guard::is_caller::is_caller_global_admin_or_controller, CANISTER_DATA}; | ||
|
||
#[update(guard = "is_caller_global_admin_or_controller")] | ||
pub fn collect_creator_dao_stats_in_the_network() { | ||
CANISTER_DATA.with_borrow(|canister_data| { | ||
canister_data | ||
.all_subnet_orchestrator_canisters_list | ||
.iter() | ||
.for_each(|subnet_orchestrator_canister_id| { | ||
match notify( | ||
*subnet_orchestrator_canister_id, | ||
"collect_creator_dao_stats_in_the_network", | ||
(), | ||
) { | ||
Err(e) => { | ||
ic_cdk::println!( | ||
"Failed to collect data from {:?}. Error {:?}", | ||
subnet_orchestrator_canister_id, | ||
e | ||
) | ||
} | ||
_ => {} | ||
} | ||
}); | ||
}) | ||
} |
9 changes: 9 additions & 0 deletions
9
src/canister/platform_orchestrator/src/api/stats/get_creator_dao_stats.rs
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use ic_cdk_macros::query; | ||
use shared_utils::types::creator_dao_stats::CreatorDaoTokenStats; | ||
|
||
use crate::{guard::is_caller::is_caller_global_admin_or_controller, CANISTER_DATA}; | ||
|
||
#[query(guard = "is_caller_global_admin_or_controller")] | ||
pub fn get_creator_dao_stats() -> CreatorDaoTokenStats { | ||
CANISTER_DATA.with_borrow(|canister_data| canister_data.creator_dao_stats.clone()) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod collect_creator_dao_stats_in_the_network; | ||
pub mod get_creator_dao_stats; | ||
pub mod receive_creator_dao_stats_from_subnet_orchestrator; |
23 changes: 23 additions & 0 deletions
23
...platform_orchestrator/src/api/stats/receive_creator_dao_stats_from_subnet_orchestrator.rs
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use ic_cdk_macros::update; | ||
use std::collections::HashSet; | ||
|
||
use candid::Principal; | ||
use ic_cdk::caller; | ||
|
||
use crate::{utils::registered_subnet_orchestrator::RegisteredSubnetOrchestrator, CANISTER_DATA}; | ||
|
||
#[update] | ||
pub fn receive_creator_dao_stats_from_subnet_orchestrator( | ||
individual_user_profile_id: Principal, | ||
root_canister_ids: HashSet<Principal>, | ||
) -> Result<(), String> { | ||
let _registered_subnet_orchestrator = RegisteredSubnetOrchestrator::new(caller())?; | ||
CANISTER_DATA.with_borrow_mut(|canister_data| { | ||
canister_data.add_creator_dao_stats_recieved_from_subnet_orchestrator( | ||
individual_user_profile_id, | ||
root_canister_ids, | ||
); | ||
}); | ||
|
||
Ok(()) | ||
} |
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
2 changes: 2 additions & 0 deletions
2
src/canister/platform_orchestrator/src/utils/registered_subnet_orchestrator.rs
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,3 +1,5 @@ | ||
use std::collections::HashSet; | ||
|
||
use candid::{Nat, Principal}; | ||
use ic_cdk::{ | ||
api::management_canister::main::{ | ||
|
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
30 changes: 30 additions & 0 deletions
30
src/canister/user_index/src/api/stats/collect_creator_dao_stats_in_the_network.rs
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use ic_cdk::notify; | ||
use ic_cdk_macros::update; | ||
use shared_utils::common::utils::permissions::is_caller_controller; | ||
|
||
use crate::CANISTER_DATA; | ||
|
||
#[update(guard = "is_caller_controller")] | ||
pub fn collect_creator_dao_stats_in_the_network() { | ||
CANISTER_DATA.with_borrow(|canister_data| { | ||
canister_data | ||
.user_principal_id_to_canister_id_map | ||
.iter() | ||
.for_each(|(_, user_canister)| { | ||
match notify( | ||
*user_canister, | ||
"send_creator_dao_stats_to_subnet_orchestrator", | ||
(), | ||
) { | ||
Err(e) => { | ||
ic_cdk::println!( | ||
"Failed to collect data from {:?}. Error {:?}", | ||
user_canister, | ||
e | ||
) | ||
} | ||
_ => {} | ||
} | ||
}); | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod collect_creator_dao_stats_in_the_network; | ||
pub mod receive_creator_dao_stats_from_individual_canister; |
34 changes: 34 additions & 0 deletions
34
src/canister/user_index/src/api/stats/receive_creator_dao_stats_from_individual_canister.rs
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::collections::HashSet; | ||
|
||
use ic_cdk::{caller, notify}; | ||
use ic_cdk_macros::update; | ||
|
||
use candid::Principal; | ||
use shared_utils::common::types::known_principal::KnownPrincipalType; | ||
|
||
use crate::{util::types::individual_user_canister::IndividualUserCanister, CANISTER_DATA}; | ||
|
||
#[update] | ||
pub fn receive_creator_dao_stats_from_individual_canister( | ||
root_canister_ids: HashSet<Principal>, | ||
) -> Result<(), String> { | ||
let individual_user = IndividualUserCanister::new(caller())?; | ||
|
||
let platform_orchestrator_canister_id = CANISTER_DATA.with_borrow(|canister_data| { | ||
canister_data | ||
.configuration | ||
.known_principal_ids | ||
.get(&KnownPrincipalType::CanisterIdPlatformOrchestrator) | ||
.copied() | ||
}); | ||
|
||
let platform_orchestrator_canister_id = | ||
platform_orchestrator_canister_id.ok_or("Platform Orchestrator Canister Id not found")?; | ||
|
||
notify( | ||
platform_orchestrator_canister_id, | ||
"receive_creator_dao_stats_from_subnet_orchestrator", | ||
(individual_user.profile_id, root_canister_ids), | ||
) | ||
.map_err(|e| format!("failed to notify platform orchestrator {:?}", e)) | ||
} |
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,4 +1,5 @@ | ||
use std::cell::RefCell; | ||
use std::collections::HashSet; | ||
|
||
use candid::Principal; | ||
use data_model::CanisterData; | ||
|
Oops, something went wrong.