Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-medicala-yral committed Dec 4, 2024
2 parents 92a9fd5 + 5e7d840 commit 7a7f964
Show file tree
Hide file tree
Showing 40 changed files with 1,747 additions and 471 deletions.
15 changes: 14 additions & 1 deletion scripts/canisters/local_deploy/install_all_canisters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ then
cargo test
fi


dfx canister install platform_orchestrator --argument "(record {
version = \"v1.0.0\"
})"

dfx canister install post_cache --argument "(record {
known_principal_ids = opt vec {
record {
Expand All @@ -67,6 +72,10 @@ dfx canister install post_cache --argument "(record {

dfx canister install user_index --argument "(record {
known_principal_ids = opt vec {
record {
variant { CanisterIdPlatformOrchestrator };
principal \"$(dfx canister id platform_orchestrator)\";
};
record {
variant { UserIdGlobalSuperAdmin };
principal \"$(dfx identity get-principal)\";
Expand All @@ -92,5 +101,9 @@ dfx canister install user_index --argument "(record {
};
version= \"v1.0.0\"
})"

scripts/canisters/local_deploy/create_pool_of_individual_canister_user_index.sh

dfx canister update-settings user_index --set-controller $(dfx canister id platform_orchestrator) --yes
dfx canister call platform_orchestrator register_new_subnet_orchestrator "(principal \"$(dfx canister id user_index)\", true)"


Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ char=$(hexdump -ve '1/1 "%.2x"' "$wasm")
char_escaped=$(printf "%s" "$char" | sed 's/../\\&/g')

# Create a shell script with the escaped hexadecimal string
printf "(\"v2.2.0\", blob \"%s\")" "$char_escaped" > argument
dfx canister call user_index start_upgrades_for_individual_canisters --argument-file argument
printf "(record {version = \"v2.2.0\"; canister = variant {IndividualUserWasm}; wasm_blob = blob \"%s\"})" "$char_escaped" > argument
dfx canister call platform_orchestrator upgrade_canisters_in_network --argument-file argument
17 changes: 9 additions & 8 deletions scripts/canisters/local_deploy/upgrade_all_canisters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ while getopts "sh" arg; do
esac
done

dfx build individual_user_template
gzip -f -1 ./target/wasm32-unknown-unknown/release/individual_user_template.wasm
dfx build user_index
gzip -f -1 ./target/wasm32-unknown-unknown/release/user_index.wasm
dfx build post_cache
gzip -f -1 ./target/wasm32-unknown-unknown/release/post_cache.wasm
dfx build platform_orchestrator
Expand All @@ -35,11 +31,16 @@ then
cargo test
fi

dfx canister install platform_orchestrator --mode upgrade --argument "(record {
version= \"v2.2.0\"
})"

dfx canister install post_cache --mode upgrade --argument "(record {
version= \"v1.1.0\"
})"
dfx canister install user_index --mode upgrade --argument "(record {
version= \"v1.1.0\"
})"

scripts/canisters/local_deploy/start_upgrades.sh
scripts/canisters/local_deploy/upgrade_subnet_orchestrator.sh

sleep 2

scripts/canisters/local_deploy/start_upgrades_for_individual_canisters.sh
19 changes: 19 additions & 0 deletions scripts/canisters/local_deploy/upgrade_subnet_orchestrator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# !/bin/bash


dfx build user_index

# Specify the path to your Wasm.gz file
wasm=".dfx/local/canisters/user_index/user_index.wasm.gz"



# Use xxd to convert the file content to a hexadecimal string
char=$(hexdump -ve '1/1 "%.2x"' "$wasm")

# Escape special characters in the hexadecimal string
char_escaped=$(printf "%s" "$char" | sed 's/../\\&/g')

# Create a shell script with the escaped hexadecimal string
printf "(record {version = \"v2.2.0\"; canister = variant {SubnetOrchestratorWasm}; wasm_blob = blob \"%s\"})" "$char_escaped" > argument
dfx canister call platform_orchestrator upgrade_canisters_in_network --argument-file argument
34 changes: 18 additions & 16 deletions src/canister/individual_user_template/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,11 @@ type Result_19 = variant { Ok : vec record { nat64; nat8 }; Err : text };
type Result_2 = variant { Ok : bool; Err : CdaoTokenError };
type Result_20 = variant { Ok; Err : MigrationErrors };
type Result_21 = variant { Ok; Err : AirdropError };
type Result_22 = variant { Ok : IndividualUserCreatorDaoEntry; Err : text };
type Result_23 = variant { Committed : Committed; Aborted : record {} };
type Result_24 = variant { Ok : Ok; Err : GovernanceError };
type Result_25 = variant { Ok; Err : CdaoTokenError };
type Result_26 = variant { Ok : text; Err : text };
type Result_22 = variant { Ok : text; Err : text };
type Result_23 = variant { Ok : IndividualUserCreatorDaoEntry; Err : text };
type Result_24 = variant { Committed : Committed; Aborted : record {} };
type Result_25 = variant { Ok : Ok; Err : GovernanceError };
type Result_26 = variant { Ok; Err : CdaoTokenError };
type Result_27 = variant {
Ok : UserProfileDetailsForFrontend;
Err : UpdateProfileDetailsError;
Expand All @@ -408,10 +408,10 @@ type RoomDetails = record {
};
type SessionType = variant { AnonymousSession; RegisteredSession };
type SettleNeuronsFundParticipationRequest = record {
result : opt Result_23;
result : opt Result_24;
nns_proposal_id : opt nat64;
};
type SettleNeuronsFundParticipationResponse = record { result : opt Result_24 };
type SettleNeuronsFundParticipationResponse = record { result : opt Result_25 };
type SlotDetails = record { room_details : vec record { nat64; RoomDetails } };
type SnsInitPayload = record {
url : opt text;
Expand Down Expand Up @@ -565,6 +565,7 @@ service : (IndividualUserTemplateInitArgs) -> {
) -> ();
clear_snapshot : () -> ();
create_a_namespace : (text) -> (Result_4);
delete_all_creator_token : () -> ();
delete_key_value_pair : (nat64, text) -> (Result_5);
delete_multiple_key_value_pairs : (nat64, vec text) -> (Result_6);
deploy_cdao_sns : (SnsInitPayload, nat64) -> (Result_7);
Expand Down Expand Up @@ -631,20 +632,21 @@ service : (IndividualUserTemplateInitArgs) -> {
receive_bet_winnings_when_distributed : (nat64, BetOutcomeForBetMaker) -> ();
receive_data_from_hotornot : (principal, nat64, vec Post) -> (Result_20);
request_airdrop : (principal, opt blob, nat, principal) -> (Result_21);
reset_ml_feed_cache : () -> (Result_22);
return_cycles_to_user_index_canister : (opt nat) -> ();
save_snapshot_json : () -> (nat32);
send_creator_dao_stats_to_subnet_orchestrator : () -> (Result_22);
send_creator_dao_stats_to_subnet_orchestrator : () -> (Result_23);
set_controller_as_subnet_orchestrator : (principal) -> ();
settle_neurons_fund_participation : (
SettleNeuronsFundParticipationRequest,
) -> (SettleNeuronsFundParticipationResponse);
transfer_token_to_user_canister : (principal, principal, opt blob, nat) -> (
Result_25,
Result_26,
);
transfer_tokens_and_posts : (principal, principal) -> (Result_20);
update_last_access_time : () -> (Result_26);
update_last_access_time : () -> (Result_22);
update_last_canister_functionality_access_time : () -> ();
update_ml_feed_cache : (vec MLFeedCacheItem) -> (Result_26);
update_ml_feed_cache : (vec MLFeedCacheItem) -> (Result_22);
update_post_add_view_details : (nat64, PostViewDetailsFromFrontend) -> ();
update_post_as_ready_to_view : (nat64) -> ();
update_post_increment_share_count : (nat64) -> (nat64);
Expand All @@ -661,11 +663,11 @@ service : (IndividualUserTemplateInitArgs) -> {
update_profiles_that_follow_me_toggle_list_with_specified_profile : (
FollowerArg,
) -> (Result_8);
update_referrer_details : (UserCanisterDetails) -> (Result_26);
update_session_type : (SessionType) -> (Result_26);
update_success_history : (SuccessHistoryItemV1) -> (Result_26);
update_user_propensity : (float64) -> (Result_26);
update_watch_history : (WatchHistoryItem) -> (Result_26);
update_referrer_details : (UserCanisterDetails) -> (Result_22);
update_session_type : (SessionType) -> (Result_22);
update_success_history : (SuccessHistoryItemV1) -> (Result_22);
update_user_propensity : (float64) -> (Result_22);
update_watch_history : (WatchHistoryItem) -> (Result_22);
update_well_known_principal : (KnownPrincipalType, principal) -> ();
upgrade_creator_dao_governance_canisters : (blob) -> (Result_28);
write_key_value_pair : (nat64, text, text) -> (Result_5);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use ic_cdk::api::management_canister::main::{deposit_cycles, CanisterIdRecord};
use ic_cdk_macros::update;
use shared_utils::{
canister_specific::individual_user_template::types::{
cdao::DeployedCdaoCanisters, session::SessionType,
},
common::utils::permissions::is_caller_controller,
};

use crate::CANISTER_DATA;

use super::{
request_cycles_from_subnet_orchestrator,
utils::uninstall_code_and_return_empty_canisters_to_subnet_backup_pool, SubnetOrchestrator,
};

#[update(guard = "is_caller_controller")]
pub fn delete_all_creator_token() {
let session_type_opt = CANISTER_DATA.with_borrow(|canister_data| canister_data.session_type);

if let Some(session_type) = session_type_opt {
if matches!(session_type, SessionType::RegisteredSession) {
return;
}
}

let deployed_canisters =
CANISTER_DATA.with_borrow(|canister_data| canister_data.cdao_canisters.clone());

deployed_canisters
.iter()
.for_each(|deployed_cdao_canisters| {
delete_sns_creator_token(deployed_cdao_canisters);
});

CANISTER_DATA.with_borrow_mut(|canister_data| {
canister_data.cdao_canisters = vec![];
})
}

pub fn delete_sns_creator_token(deployed_canisters: &DeployedCdaoCanisters) {
let canister_ids = deployed_canisters.get_canister_ids();

const UNINSTALL_RECHARGE_AMOUNT: u128 = 300_000_000_000;

ic_cdk::spawn(async move {
let _ = request_cycles_from_subnet_orchestrator(5 * UNINSTALL_RECHARGE_AMOUNT).await;
for canister_id in canister_ids.iter() {
let _ = deposit_cycles(
CanisterIdRecord {
canister_id: *canister_id,
},
UNINSTALL_RECHARGE_AMOUNT,
)
.await;
}
uninstall_code_and_return_empty_canisters_to_subnet_backup_pool(canister_ids).await;
});
}
Loading

0 comments on commit 7a7f964

Please sign in to comment.