From 0243a62ba72d3d51c3e1030cb842f3fee3034bf6 Mon Sep 17 00:00:00 2001 From: Saikat Das Date: Thu, 17 Aug 2023 10:11:20 +0530 Subject: [PATCH] feat: push canister metrics to cycle monitoring infrastructure (#191) * build: bump serde * build: add rust toolchain yaml to declaritively specify rust toolchain to use * refactor: clean up all warnings from Clippy * refactor: move know principals to configuration field * chore: intermediate save * docs: move docs to their own folder * chore: intermediate save. test repo * feat: implement pinging an external endpoint to export canister metrics * chore: canister deploy with quill --- Cargo.lock | 8 +- Cargo.toml | 2 +- default.nix | 8 +- hot_or_not.md => notes/commands.md | 27 --- notes/hot_or_not.md | 45 ++++ notes/talking_points.md | 11 + rust-toolchain.toml | 4 + .../local_sns_deploy/upgrade_all_canisters.sh | 89 -------- sns | 2 +- .../src/api/canister_lifecycle/init.rs | 4 +- .../api/user_signup/are_signups_enabled.rs | 10 +- .../api/user_signup/toggle_signups_enabled.rs | 6 +- ...list_of_all_well_known_principal_values.rs | 4 +- .../get_well_known_principal_value.rs | 2 +- .../src/api/canister_lifecycle/init.rs | 4 +- ...ser_posts_from_individual_user_canister.rs | 2 +- ...ed_up_data_to_individual_users_canister.rs | 25 ++- ...estore_data_back_to_user_index_canister.rs | 8 +- .../get_well_known_principal_value.rs | 4 +- ...te_locally_stored_well_known_principals.rs | 19 +- src/canister/individual_user_template/can.did | 1 + .../backup_data_to_backup_canister.rs | 33 ++- .../src/api/canister_lifecycle/init.rs | 33 ++- .../api/canister_lifecycle/post_upgrade.rs | 36 +++- ...pals_that_follow_this_profile_paginated.rs | 24 +-- ...incipals_this_profile_follows_paginated.rs | 24 +-- ...llow_toggle_list_with_specified_profile.rs | 8 +- ...w_me_toggle_list_with_specified_profile.rs | 38 ++-- .../receive_bet_from_bet_makers_canister.rs | 2 +- ...enqueue_timers_for_pending_bet_outcomes.rs | 6 +- ...bulate_hot_or_not_outcome_for_post_slot.rs | 6 +- ...get_entire_individual_post_detail_by_id.rs | 3 +- .../post/get_individual_post_details_by_id.rs | 2 +- ...ts_of_this_user_profile_with_pagination.rs | 2 +- .../src/api/profile/get_profile_details.rs | 2 +- .../profile/update_profile_display_details.rs | 2 +- .../api/token/get_rewarded_for_signing_up.rs | 2 +- .../get_well_known_principal_value.rs | 6 +- ...te_locally_stored_well_known_principals.rs | 27 +-- .../src/data_model/mod.rs | 6 +- .../src/data_model/version_details.rs | 2 +- .../src/api/feed/remove_all_feed_entries.rs | 3 +- ...ome_feed_posts_from_publishing_canister.rs | 2 +- .../get_well_known_principal_value.rs | 6 +- ...te_locally_stored_well_known_principals.rs | 3 +- .../backup_all_individual_user_canisters.rs | 7 +- ...ackup_canister_and_restore_data_to_heap.rs | 5 +- .../src/api/canister_lifecycle/init.rs | 2 +- .../api/canister_lifecycle/post_upgrade.rs | 14 +- .../get_index_details_last_upgrade_status.rs | 2 +- ...upgrade_user_canisters_with_latest_wasm.rs | 46 ++-- ...dividual_user_canister_with_latest_wasm.rs | 17 +- ...name_corresponding_to_user_principal_id.rs | 23 +- .../get_well_known_principal_value.rs | 6 +- ...te_locally_stored_well_known_principals.rs | 3 +- .../src/data_model/canister_upgrade/mod.rs | 33 ++- .../canister_upgrade/upgrade_status.rs | 32 --- .../src/data_model/configuration/mod.rs | 11 + src/canister/user_index/src/data_model/mod.rs | 5 +- src/canister/user_index/src/lib.rs | 2 +- .../src/util/canister_management.rs | 4 + ...five_hundred_tokens_as_referral_rewards.rs | 8 +- ...n_the_canisters_to_their_original_state.rs | 22 +- ...uccessfully_to_individual_user_canister.rs | 22 +- ...ster_tops_up_the_canisters_that_need_it.rs | 2 +- ...or_not_feed_scores_match_expected_value.rs | 52 ++--- ...following_lists_are_accordingly_updated.rs | 13 +- ...eated_post_then_expected_outcomes_occur.rs | 22 +- ...onal_canister_and_updated_in_user_index.rs | 2 +- ...l_known_principals_and_update_canisters.rs | 40 ++-- src/lib/shared_utils/src/access_control.rs | 2 +- .../individual_user_template/types/arg.rs | 11 +- .../types/configuration.rs | 6 + .../types/follow/mod.rs | 52 ++--- .../types/hot_or_not/mod.rs | 50 ++--- .../individual_user_template/types/mod.rs | 1 + .../types/post/mod.rs | 204 +++++++++--------- .../individual_user_template/types/token.rs | 5 +- src/lib/shared_utils/src/common/mod.rs | 1 + src/lib/shared_utils/src/common/timer/mod.rs | 1 + .../src/common/timer/send_metrics.rs | 73 +++++++ .../common/types/utility_token/token_event.rs | 2 +- .../stable_memory_serializer_deserializer.rs | 4 +- src/lib/shared_utils/src/constant.rs | 5 +- src/lib/test_utils/src/setup/env/v1.rs | 24 +-- .../src/setup/test_constants/mod.rs | 32 +-- talking_points.md | 15 -- 87 files changed, 747 insertions(+), 699 deletions(-) rename hot_or_not.md => notes/commands.md (51%) create mode 100644 notes/hot_or_not.md create mode 100644 notes/talking_points.md create mode 100644 rust-toolchain.toml delete mode 100755 scripts/canisters/local_sns_deploy/upgrade_all_canisters.sh delete mode 100644 src/canister/user_index/src/data_model/canister_upgrade/upgrade_status.rs create mode 100644 src/canister/user_index/src/data_model/configuration/mod.rs create mode 100644 src/lib/shared_utils/src/canister_specific/individual_user_template/types/configuration.rs create mode 100644 src/lib/shared_utils/src/common/timer/mod.rs create mode 100644 src/lib/shared_utils/src/common/timer/send_metrics.rs delete mode 100644 talking_points.md diff --git a/Cargo.lock b/Cargo.lock index 77bf68b1..296f87d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1012,9 +1012,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.171" +version = "1.0.173" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" +checksum = "e91f70896d6720bc714a4a57d22fc91f1db634680e65c8efe13323f1fa38d53f" dependencies = [ "serde_derive", ] @@ -1030,9 +1030,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.171" +version = "1.0.173" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" +checksum = "a6250dde8342e0232232be9ca3db7aa40aceb5a3e5dd9bddbc00d99a007cde49" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 1eb0a34a..9eee09bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,6 @@ ic-cdk-timers = "0.2.0" ic-stable-structures = "0.5.6" ic-test-state-machine-client = "2.2.1" rmp-serde = "1.1.1" -serde = "1.0.171" +serde = "1.0.173" shared_utils = { path = "./src/lib/shared_utils" } test_utils = { path = "./src/lib/test_utils" } \ No newline at end of file diff --git a/default.nix b/default.nix index 5c212c6b..5575064f 100644 --- a/default.nix +++ b/default.nix @@ -9,8 +9,8 @@ dfx-env.overrideAttrs (old: { nativeBuildInputs = with pkgs; old.nativeBuildInputs ++ [ rustup pkg-config openssl protobuf cmake cachix killall jq coreutils bc python3Full ]; - shellHook = '' - rustup toolchain install stable - rustup target add wasm32-unknown-unknown - ''; + # shellHook = '' + # rustup toolchain install stable + # rustup target add wasm32-unknown-unknown + # ''; }) diff --git a/hot_or_not.md b/notes/commands.md similarity index 51% rename from hot_or_not.md rename to notes/commands.md index 366bb1fa..6b07a4de 100644 --- a/hot_or_not.md +++ b/notes/commands.md @@ -1,24 +1,3 @@ -# Architecture - -```mermaid - flowchart - UserClient[User Client Device] - UserIndex[(User Index)] - IndividualUserCanister[(Individual User
Canister)] - ContentIndex[(Content Index)] - GlobalConfiguration[(Global Configuration)] - DataBackup[(Data Backup)] - - - UserIndex -- 1 --> IndividualUserCanister - IndividualUserCanister -- n --> UserIndex - IndividualUserCanister -- sync new
posts --> ContentIndex - IndividualUserCanister -- backup before
upgrades --> DataBackup - UserClient -- get provisioned
individual canister --> UserIndex - UserClient -- get content --> ContentIndex - UserClient -- talk to own
and others' canisters --> IndividualUserCanister -``` - # Commonly used dfx commands ## Try upgrading a canister to the latest wasm manually @@ -44,9 +23,3 @@ `dfx canister --network=ic call aanaa-xaaaa-aaaah-aaeiq-cai burn "(record { canister_id= principal \"$(dfx identity get-wallet --network ic)\"; amount= (1000000000000:nat64)})"` Burn XTC to cycles operation burns 2B cycles - -## Next Items - -- Remove any controller except itself -- Add additional known canisters for sns root and governance and ensure that canister upgrade parameters retain existing entries and only upsert new entries -- Add multiple upgrades at a time diff --git a/notes/hot_or_not.md b/notes/hot_or_not.md new file mode 100644 index 00000000..f25de565 --- /dev/null +++ b/notes/hot_or_not.md @@ -0,0 +1,45 @@ +# Current Architecture + +```mermaid + flowchart + UserClient[User Client Device] + UserIndex[(User Index)] + IndividualUserCanister[(Individual User
Canister)] + ContentIndex[(Content Index)] + GlobalConfiguration[(Global Configuration)] + DataBackup[(Data Backup)] + + + UserIndex -- 1 --> IndividualUserCanister + IndividualUserCanister -- n --> UserIndex + IndividualUserCanister -- sync new
posts --> ContentIndex + IndividualUserCanister -- backup before
upgrades --> DataBackup + UserClient -- get provisioned
individual canister --> UserIndex + UserClient -- get content --> ContentIndex + UserClient -- talk to own
and others' canisters --> IndividualUserCanister +``` + +## Upcoming Architecture + +```mermaid + flowchart + PlatformOrchestrator[Platform Orchestrator] + CanisterRegistry[(Canister Registry)] + UserClient[User Client Device] + UserIndex[(User Index)] + IndividualUserCanister[(Individual User
Canister)] + ContentIndex[(Content Index)] + + subgraph OrchestratorSubnet[Orchestrator Subnet] + PlatformOrchestrator <-- 1 --> CanisterRegistry + end + subgraph UserSubnet[User Subnet] + PlatformOrchestrator --> UserIndex + UserIndex -- 1 --> IndividualUserCanister + IndividualUserCanister -- n --> UserIndex + IndividualUserCanister <-- sync new
posts --> ContentIndex + UserClient -- get provisioned
individual canister --> UserIndex + UserClient -- get content --> IndividualUserCanister + UserClient -- talk to own
and others' canisters --> IndividualUserCanister + end +``` diff --git a/notes/talking_points.md b/notes/talking_points.md new file mode 100644 index 00000000..b7c456a5 --- /dev/null +++ b/notes/talking_points.md @@ -0,0 +1,11 @@ +# Canister side + +- Short term - Adopt the ic-stable-structures to leverage stable memory for data storage. Should tentatively reduce our costs in half essentially cutting upgrade cost to near zero +- Short term - Implement a active canister reclamation solution that reclaims fleet canisters from idle users who've abandoned their accounts and reuses them for new signups. Archive existing users data to a archival solution and restore to a new canister on future activation. Should also significantly reduce costs, letting us reclaim 40-70% of our approximate fleet on a regular basis. +- Long term - Invest in running nodes and become node providers essentially being able to pay for cycles with IC earned, in a way hosting our app on our own hardware, IC providing the software stack +- Long term - Stake significant portions of the SNS DAO treasury into neurons and using the maturity from those neurons to pay for cycles. + +# REDUCED CYCLE COSTS + +- Sustained use discounts +- Subnet rentals with lower cycle costs per the entire subnet diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..28e3eeaf --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +profile = "default" +targets = [ "wasm32-unknown-unknown" ] \ No newline at end of file diff --git a/scripts/canisters/local_sns_deploy/upgrade_all_canisters.sh b/scripts/canisters/local_sns_deploy/upgrade_all_canisters.sh deleted file mode 100755 index 8e73dfaf..00000000 --- a/scripts/canisters/local_sns_deploy/upgrade_all_canisters.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -usage() { - printf "Usage: \n[-s Skip test] \n[-h Display help] \n"; - exit 0; -} - -skip_test=false - -while getopts "sh" arg; do - case $arg in - s) - skip_test=true - ;; - h) - usage - ;; - esac -done - -dfx build individual_user_template -gzip -f -1 ./target/wasm32-unknown-unknown/release/individual_user_template.wasm -dfx build user_index -dfx build configuration -dfx build data_backup -dfx build post_cache - -if [[ $skip_test != true ]] -then - cargo test -fi - -source ./sns-testing/constants.sh normal - -cd .. - -quill sns \ - --canister-ids-file "./sns-testing/sns_canister_ids.json" \ - --pem-file "${PEM_FILE}" \ - make-upgrade-canister-proposal \ - --summary "This proposal upgrades test canister" \ - --title "Upgrade configuration canister" \ - --url "https://hotornot.wtf/" \ - --target-canister-id $(dfx canister id configuration) \ - --wasm-path ./.dfx/local/canisters/configuration/configuration.wasm.gz \ - --canister-upgrade-arg "(record {})" \ -"$(./sns-testing/developer_neuron_id.sh)" > msg.json -quill --insecure-local-dev-mode send --yes msg.json | grep -v "new_canister_wasm" - -quill sns \ - --canister-ids-file "./sns-testing/sns_canister_ids.json" \ - --pem-file "${PEM_FILE}" \ - make-upgrade-canister-proposal \ - --summary "This proposal upgrades data_backup canister" \ - --title "Upgrade data_backup canister" \ - --url "https://hotornot.wtf/" \ - --target-canister-id $(dfx canister id data_backup) \ - --wasm-path ./.dfx/local/canisters/data_backup/data_backup.wasm.gz \ - --canister-upgrade-arg "(record {})" \ -"$(./sns-testing/developer_neuron_id.sh)" > msg.json -quill --insecure-local-dev-mode send --yes msg.json | grep -v "new_canister_wasm" - -quill sns \ - --canister-ids-file "./sns-testing/sns_canister_ids.json" \ - --pem-file "${PEM_FILE}" \ - make-upgrade-canister-proposal \ - --summary "This proposal upgrades post_cache canister" \ - --title "Upgrade post_cache canister" \ - --url "https://hotornot.wtf/" \ - --target-canister-id $(dfx canister id post_cache) \ - --wasm-path ./.dfx/local/canisters/post_cache/post_cache.wasm.gz \ - --canister-upgrade-arg "(record {})" \ -"$(./sns-testing/developer_neuron_id.sh)" > msg.json -quill --insecure-local-dev-mode send --yes msg.json | grep -v "new_canister_wasm" - -quill sns \ - --canister-ids-file "./sns-testing/sns_canister_ids.json" \ - --pem-file "${PEM_FILE}" \ - make-upgrade-canister-proposal \ - --summary "This proposal upgrades user_index canister" \ - --title "Upgrade user_index canister" \ - --url "https://hotornot.wtf/" \ - --target-canister-id $(dfx canister id user_index) \ - --wasm-path ./.dfx/local/canisters/user_index/user_index.wasm.gz \ - --canister-upgrade-arg "(record {})" \ -"$(./sns-testing/developer_neuron_id.sh)" > msg.json -quill --insecure-local-dev-mode send --yes msg.json | grep -v "new_canister_wasm" - diff --git a/sns b/sns index a49bffea..c1490e84 160000 --- a/sns +++ b/sns @@ -1 +1 @@ -Subproject commit a49bffeaab5688af30a0225784cb4036c657262c +Subproject commit c1490e846b29ee3d2e62f80cf6885a3f75e74780 diff --git a/src/canister/configuration/src/api/canister_lifecycle/init.rs b/src/canister/configuration/src/api/canister_lifecycle/init.rs index 35adaeca..27004728 100644 --- a/src/canister/configuration/src/api/canister_lifecycle/init.rs +++ b/src/canister/configuration/src/api/canister_lifecycle/init.rs @@ -18,7 +18,7 @@ fn init_impl(init_args: ConfigurationInitArgs, data: &mut CanisterData) { .iter() .for_each(|(principal_belongs_to, principal_id)| { data.known_principal_ids - .insert(principal_belongs_to.clone(), principal_id.clone()); + .insert(principal_belongs_to.clone(), *principal_id); }); data.signups_enabled = init_args.signups_enabled.unwrap_or(data.signups_enabled); @@ -101,6 +101,6 @@ mod test { .unwrap(), &get_mock_canister_id_user_index() ); - assert_eq!(data.signups_enabled, true); + assert!(data.signups_enabled); } } diff --git a/src/canister/configuration/src/api/user_signup/are_signups_enabled.rs b/src/canister/configuration/src/api/user_signup/are_signups_enabled.rs index 74a653d2..bdc8ac8e 100644 --- a/src/canister/configuration/src/api/user_signup/are_signups_enabled.rs +++ b/src/canister/configuration/src/api/user_signup/are_signups_enabled.rs @@ -19,12 +19,14 @@ mod test { #[test] fn test_are_signups_enabled_impl() { - let mut canister_data = CanisterData::default(); + let mut canister_data = CanisterData { + signups_enabled: true, + ..Default::default() + }; - canister_data.signups_enabled = true; - assert_eq!(are_signups_enabled_impl(&canister_data), true); + assert!(are_signups_enabled_impl(&canister_data)); canister_data.signups_enabled = false; - assert_eq!(are_signups_enabled_impl(&canister_data), false); + assert!(!are_signups_enabled_impl(&canister_data)); } } diff --git a/src/canister/configuration/src/api/user_signup/toggle_signups_enabled.rs b/src/canister/configuration/src/api/user_signup/toggle_signups_enabled.rs index f7a76405..6455dc46 100644 --- a/src/canister/configuration/src/api/user_signup/toggle_signups_enabled.rs +++ b/src/canister/configuration/src/api/user_signup/toggle_signups_enabled.rs @@ -55,15 +55,15 @@ mod test { // super admin should be allowed to toggle let result = toggle_signups_enabled_impl(admin_caller, &mut canister_data); assert!(result.is_ok()); - assert_eq!(canister_data.signups_enabled, true); + assert!(canister_data.signups_enabled); let result = toggle_signups_enabled_impl(admin_caller, &mut canister_data); assert!(result.is_ok()); - assert_eq!(canister_data.signups_enabled, false); + assert!(!canister_data.signups_enabled); // non super admin should not be allowed to toggle let non_admin_caller = get_mock_user_alice_principal_id(); let result = toggle_signups_enabled_impl(non_admin_caller, &mut canister_data); assert!(result.is_err()); - assert_eq!(canister_data.signups_enabled, false); + assert!(!canister_data.signups_enabled); } } diff --git a/src/canister/configuration/src/api/well_known_principal/get_current_list_of_all_well_known_principal_values.rs b/src/canister/configuration/src/api/well_known_principal/get_current_list_of_all_well_known_principal_values.rs index a39d9614..8f89ef10 100644 --- a/src/canister/configuration/src/api/well_known_principal/get_current_list_of_all_well_known_principal_values.rs +++ b/src/canister/configuration/src/api/well_known_principal/get_current_list_of_all_well_known_principal_values.rs @@ -8,7 +8,7 @@ use crate::CANISTER_DATA; fn get_current_list_of_all_well_known_principal_values() -> Vec<(KnownPrincipalType, Principal)> { CANISTER_DATA.with(|canister_data_ref_cell| { let known_principal_ids = &canister_data_ref_cell.borrow().known_principal_ids; - get_current_list_of_all_well_known_principal_values_impl(&known_principal_ids) + get_current_list_of_all_well_known_principal_values_impl(known_principal_ids) }) } @@ -17,7 +17,7 @@ fn get_current_list_of_all_well_known_principal_values_impl( ) -> Vec<(KnownPrincipalType, Principal)> { known_principal_ids .iter() - .map(|(known_principal_type, principal)| (known_principal_type.clone(), principal.clone())) + .map(|(known_principal_type, principal)| (known_principal_type.clone(), *principal)) .collect() } diff --git a/src/canister/configuration/src/api/well_known_principal/get_well_known_principal_value.rs b/src/canister/configuration/src/api/well_known_principal/get_well_known_principal_value.rs index ca5593b6..c65a4db0 100644 --- a/src/canister/configuration/src/api/well_known_principal/get_well_known_principal_value.rs +++ b/src/canister/configuration/src/api/well_known_principal/get_well_known_principal_value.rs @@ -19,7 +19,7 @@ fn get_well_known_principal_value_impl( canister_data .known_principal_ids .get(principal_type) - .map(|principal| principal.clone()) + .copied() } #[cfg(test)] diff --git a/src/canister/data_backup/src/api/canister_lifecycle/init.rs b/src/canister/data_backup/src/api/canister_lifecycle/init.rs index a66ad1e9..d67d7ae9 100644 --- a/src/canister/data_backup/src/api/canister_lifecycle/init.rs +++ b/src/canister/data_backup/src/api/canister_lifecycle/init.rs @@ -18,7 +18,7 @@ fn init_impl(init_args: DataBackupInitArgs, data: &mut HeapData) { .iter() .for_each(|(principal_belongs_to, principal_id)| { data.known_principal_ids - .insert(principal_belongs_to.clone(), principal_id.clone()); + .insert(principal_belongs_to.clone(), *principal_id); }); init_args @@ -27,7 +27,7 @@ fn init_impl(init_args: DataBackupInitArgs, data: &mut HeapData) { .iter() .for_each(|(principal, access_roles)| { data.access_control_list - .insert(principal.clone(), access_roles.clone()); + .insert(*principal, access_roles.clone()); }); } diff --git a/src/canister/data_backup/src/api/individual_user_backup/receive_all_user_posts_from_individual_user_canister.rs b/src/canister/data_backup/src/api/individual_user_backup/receive_all_user_posts_from_individual_user_canister.rs index 7d63b82f..562dd8bc 100644 --- a/src/canister/data_backup/src/api/individual_user_backup/receive_all_user_posts_from_individual_user_canister.rs +++ b/src/canister/data_backup/src/api/individual_user_backup/receive_all_user_posts_from_individual_user_canister.rs @@ -55,7 +55,7 @@ fn receive_all_user_posts_from_individual_user_canister_impl( existing_entry .canister_data .all_created_posts - .insert(post.id.clone(), post.clone()); + .insert(post.id, post.clone()); }); canister_data.user_principal_id_to_all_user_data_map.insert( diff --git a/src/canister/data_backup/src/api/individual_user_backup/restore_backed_up_data_to_individual_users_canister.rs b/src/canister/data_backup/src/api/individual_user_backup/restore_backed_up_data_to_individual_users_canister.rs index cc19bb8a..d4eed6ff 100644 --- a/src/canister/data_backup/src/api/individual_user_backup/restore_backed_up_data_to_individual_users_canister.rs +++ b/src/canister/data_backup/src/api/individual_user_backup/restore_backed_up_data_to_individual_users_canister.rs @@ -16,13 +16,12 @@ async fn restore_backed_up_data_to_individual_users_canister( let caller_principal_id = ic_cdk::caller(); if !(CANISTER_DATA.with(|canister_data_ref_cell| { - canister_data_ref_cell + *canister_data_ref_cell .borrow() .heap_data .known_principal_ids .get(&KnownPrincipalType::UserIdGlobalSuperAdmin) .unwrap() - .clone() == caller_principal_id })) { return "Unauthorized".to_string(); @@ -48,7 +47,7 @@ async fn restore_backed_up_data_to_individual_users_canister( send_principals_that_follow_me(&users_data).await; send_profile_data(&users_data).await; - return "Success".to_string(); + "Success".to_string() } const CHUNK_SIZE: usize = 10; @@ -56,7 +55,7 @@ const CHUNK_SIZE: usize = 10; async fn send_profile_data(users_data: &AllUserData) { let canister_id_to_send_to = users_data.user_canister_id; - let _response: () = call::call( + let _: () = call::call( canister_id_to_send_to, "receive_my_profile_from_data_backup_canister", (users_data.canister_data.profile.clone(),), @@ -72,7 +71,7 @@ async fn send_principals_that_follow_me(users_data: &AllUserData) { .canister_data .principals_that_follow_me .iter() - .map(|principal_that_follow_me| principal_that_follow_me.clone()) + .copied() .collect::>(); let principals_that_follow_me_vec_chunks = principals_that_follow_me_vec @@ -80,7 +79,7 @@ async fn send_principals_that_follow_me(users_data: &AllUserData) { .collect::>(); for chunk in principals_that_follow_me_vec_chunks { - let _response: () = call::call( + let _: () = call::call( canister_id_to_send_to, "receive_principals_that_follow_me_from_data_backup_canister", (chunk.to_vec(),), @@ -97,7 +96,7 @@ async fn send_principals_i_follow(users_data: &AllUserData) { .canister_data .principals_i_follow .iter() - .map(|principal_i_follow| principal_i_follow.clone()) + .copied() .collect::>(); let principals_i_follow_vec_chunks = principals_i_follow_vec @@ -105,7 +104,7 @@ async fn send_principals_i_follow(users_data: &AllUserData) { .collect::>(); for chunk in principals_i_follow_vec_chunks { - let _response: () = call::call( + let _: () = call::call( canister_id_to_send_to, "receive_principals_i_follow_from_data_backup_canister", (chunk.to_vec(),), @@ -131,7 +130,7 @@ async fn send_utility_token_history(users_data: &AllUserData) { .collect::>(); for chunk in all_utility_token_transactions_chunks { - let _response: () = call::call( + let _: () = call::call( canister_id_to_send_to, "receive_my_utility_token_transaction_history_from_data_backup_canister", (chunk.to_vec(),), @@ -144,7 +143,7 @@ async fn send_utility_token_history(users_data: &AllUserData) { async fn send_utility_token_balance(users_data: &AllUserData) { let canister_id_to_send_to = users_data.user_canister_id; - let _response: () = call::call( + let _: () = call::call( canister_id_to_send_to, "receive_my_utility_token_balance_from_data_backup_canister", (users_data.canister_data.token_data.utility_token_balance,), @@ -159,14 +158,14 @@ async fn send_posts(users_data: &AllUserData) { let all_created_posts_vec = users_data .canister_data .all_created_posts - .iter() - .map(|(_id, post)| post.clone()) + .values() + .cloned() .collect::>(); let all_created_posts_chunks = all_created_posts_vec.chunks(CHUNK_SIZE).collect::>(); for chunk in all_created_posts_chunks { - let _response: () = call::call( + let _: () = call::call( canister_id_to_send_to, "receive_my_created_posts_from_data_backup_canister", (chunk.to_vec(),), diff --git a/src/canister/data_backup/src/api/user_index_backup/send_restore_data_back_to_user_index_canister.rs b/src/canister/data_backup/src/api/user_index_backup/send_restore_data_back_to_user_index_canister.rs index cc871058..f40f0fe2 100644 --- a/src/canister/data_backup/src/api/user_index_backup/send_restore_data_back_to_user_index_canister.rs +++ b/src/canister/data_backup/src/api/user_index_backup/send_restore_data_back_to_user_index_canister.rs @@ -9,26 +9,24 @@ fn send_restore_data_back_to_user_index_canister() { let caller_principal_id = ic_cdk::caller(); if !(CANISTER_DATA.with(|canister_data_ref_cell| { - canister_data_ref_cell + *canister_data_ref_cell .borrow() .heap_data .known_principal_ids .get(&KnownPrincipalType::UserIdGlobalSuperAdmin) .unwrap() - .clone() == caller_principal_id })) { return; } CANISTER_DATA.with(|canister_data_ref_cell| { - let user_index_canister_id = canister_data_ref_cell + let user_index_canister_id = *canister_data_ref_cell .borrow() .heap_data .known_principal_ids .get(&KnownPrincipalType::CanisterIdUserIndex) - .unwrap() - .clone(); + .unwrap(); canister_data_ref_cell .borrow() diff --git a/src/canister/data_backup/src/api/well_known_principal/get_well_known_principal_value.rs b/src/canister/data_backup/src/api/well_known_principal/get_well_known_principal_value.rs index bcc8fc18..88f4a03f 100644 --- a/src/canister/data_backup/src/api/well_known_principal/get_well_known_principal_value.rs +++ b/src/canister/data_backup/src/api/well_known_principal/get_well_known_principal_value.rs @@ -8,7 +8,7 @@ use crate::{data::heap_data::HeapData, CANISTER_DATA}; fn get_well_known_principal_value(principal_type: KnownPrincipalType) -> Option { CANISTER_DATA.with(|canister_data_ref_cell| { let canister_data = &canister_data_ref_cell.borrow().heap_data; - get_well_known_principal_value_impl(&principal_type, &canister_data) + get_well_known_principal_value_impl(&principal_type, canister_data) }) } @@ -19,7 +19,7 @@ fn get_well_known_principal_value_impl( canister_data .known_principal_ids .get(principal_type) - .map(|principal| principal.clone()) + .copied() } #[cfg(test)] diff --git a/src/canister/data_backup/src/api/well_known_principal/update_locally_stored_well_known_principals.rs b/src/canister/data_backup/src/api/well_known_principal/update_locally_stored_well_known_principals.rs index 18daec33..061ba7c6 100644 --- a/src/canister/data_backup/src/api/well_known_principal/update_locally_stored_well_known_principals.rs +++ b/src/canister/data_backup/src/api/well_known_principal/update_locally_stored_well_known_principals.rs @@ -6,17 +6,14 @@ use crate::CANISTER_DATA; pub async fn update_locally_stored_well_known_principals() { // extract the canister ID of the configuration canister from well-known principals - let config_canister_id = CANISTER_DATA - .with(|canister_data_ref_cell| { - canister_data_ref_cell - .borrow() - .heap_data - .known_principal_ids - .clone() - }) - .get(&KnownPrincipalType::CanisterIdConfiguration) - .expect("Failed to get the canister id of the configuration canister") - .clone(); + let config_canister_id = CANISTER_DATA.with(|canister_data_ref_cell| { + *canister_data_ref_cell + .borrow() + .heap_data + .known_principal_ids + .get(&KnownPrincipalType::CanisterIdConfiguration) + .expect("Failed to get the canister id of the configuration canister") + }); // fetch the well-known principals from the configuration canister let (well_known_principals,): (Vec<(KnownPrincipalType, Principal)>,) = call::call( diff --git a/src/canister/individual_user_template/can.did b/src/canister/individual_user_template/can.did index 91919f05..0ad57e8d 100644 --- a/src/canister/individual_user_template/can.did +++ b/src/canister/individual_user_template/can.did @@ -89,6 +89,7 @@ type HotOrNotOutcomePayoutEvent = variant { }; type IndividualUserTemplateInitArgs = record { known_principal_ids : opt vec record { KnownPrincipalType; principal }; + url_to_send_canister_metrics_to : opt text; profile_owner : opt principal; upgrade_version_number : opt nat64; }; diff --git a/src/canister/individual_user_template/src/api/backup_and_restore/backup_data_to_backup_canister.rs b/src/canister/individual_user_template/src/api/backup_and_restore/backup_data_to_backup_canister.rs index e9f14b1a..6933419d 100644 --- a/src/canister/individual_user_template/src/api/backup_and_restore/backup_data_to_backup_canister.rs +++ b/src/canister/individual_user_template/src/api/backup_and_restore/backup_data_to_backup_canister.rs @@ -56,11 +56,13 @@ async fn backup_data_to_backup_canister( return; } - let data_backup_canister_id = CANISTER_DATA - .with(|canister_data_ref_cell| canister_data_ref_cell.borrow().known_principal_ids.clone()) - .get(&KnownPrincipalType::CanisterIdDataBackup) - .unwrap() - .clone(); + let data_backup_canister_id = CANISTER_DATA.with(|canister_data_ref_cell| { + *canister_data_ref_cell + .borrow() + .known_principal_ids + .get(&KnownPrincipalType::CanisterIdDataBackup) + .unwrap() + }); ic_cdk::print(format!( "🥫 Backing up data for canister with id: {}", @@ -92,8 +94,8 @@ async fn send_profile_data( return; } - let _response: () = call::call( - data_backup_canister_id.clone(), + let _: () = call::call( + *data_backup_canister_id, "receive_profile_details_from_individual_user_canister", (profile_data, *canister_owner_principal_id, *canister_id), ) @@ -108,16 +110,13 @@ async fn send_all_created_posts( let all_created_posts = CANISTER_DATA .with(|canister_data_ref_cell| canister_data_ref_cell.borrow().all_created_posts.clone()); - let all_created_posts_vec = all_created_posts - .iter() - .map(|(_id, post)| post.clone()) - .collect::>(); + let all_created_posts_vec = all_created_posts.values().cloned().collect::>(); let all_created_posts_chunks = all_created_posts_vec.chunks(CHUNK_SIZE).collect::>(); for chunk in all_created_posts_chunks { - let _response: () = call::call( - data_backup_canister_id.clone(), + let _: () = call::call( + *data_backup_canister_id, "receive_all_user_posts_from_individual_user_canister", (chunk.to_vec(), *canister_owner_principal_id), ) @@ -133,8 +132,8 @@ async fn send_all_token_data( let token_data = CANISTER_DATA .with(|canister_data_ref_cell| canister_data_ref_cell.borrow().my_token_balance.clone()); - let _response: () = call::call( - data_backup_canister_id.clone(), + let _: () = call::call( + *data_backup_canister_id, "receive_current_token_balance_from_individual_user_canister", (token_data.utility_token_balance, *canister_owner_principal_id), ) @@ -152,8 +151,8 @@ async fn send_all_token_data( .collect::>(); for chunk in all_token_transactions_chunks { - let _response: () = call::call( - data_backup_canister_id.clone(), + let _: () = call::call( + *data_backup_canister_id, "receive_all_token_transactions_from_individual_user_canister", (chunk.to_vec(), *canister_owner_principal_id), ) diff --git a/src/canister/individual_user_template/src/api/canister_lifecycle/init.rs b/src/canister/individual_user_template/src/api/canister_lifecycle/init.rs index 2751c058..e792833b 100644 --- a/src/canister/individual_user_template/src/api/canister_lifecycle/init.rs +++ b/src/canister/individual_user_template/src/api/canister_lifecycle/init.rs @@ -1,5 +1,8 @@ use crate::{data_model::CanisterData, CANISTER_DATA}; -use shared_utils::canister_specific::individual_user_template::types::arg::IndividualUserTemplateInitArgs; +use shared_utils::{ + canister_specific::individual_user_template::types::arg::IndividualUserTemplateInitArgs, + common::timer::send_metrics::enqueue_timer_for_calling_metrics_rest_api, +}; #[ic_cdk::init] #[candid::candid_method(init)] @@ -8,6 +11,8 @@ fn init(init_args: IndividualUserTemplateInitArgs) { let mut data = canister_data_ref_cell.borrow_mut(); init_impl(init_args, &mut data); }); + + send_canister_metrics(); } fn init_impl(init_args: IndividualUserTemplateInitArgs, data: &mut CanisterData) { @@ -17,10 +22,26 @@ fn init_impl(init_args: IndividualUserTemplateInitArgs, data: &mut CanisterData) .iter() .for_each(|(principal_belongs_to, principal_id)| { data.known_principal_ids - .insert(principal_belongs_to.clone(), principal_id.clone()); + .insert(principal_belongs_to.clone(), *principal_id); }); data.profile.principal_id = init_args.profile_owner; + + data.configuration.url_to_send_canister_metrics_to = init_args.url_to_send_canister_metrics_to; +} + +pub fn send_canister_metrics() { + let url_to_send_canister_metrics_to = CANISTER_DATA.with(|canister_data_ref_cell| { + canister_data_ref_cell + .borrow() + .configuration + .url_to_send_canister_metrics_to + .clone() + }); + + if let Some(url_to_send_canister_metrics_to) = url_to_send_canister_metrics_to { + enqueue_timer_for_calling_metrics_rest_api(url_to_send_canister_metrics_to); + } } #[cfg(test)] @@ -55,6 +76,9 @@ mod test { known_principal_ids: Some(known_principal_ids), profile_owner: Some(get_mock_user_alice_principal_id()), upgrade_version_number: Some(0), + url_to_send_canister_metrics_to: Some( + "http://metrics-url.com/receive-metrics".to_string(), + ), }; let mut data = CanisterData::default(); @@ -85,5 +109,10 @@ mod test { data.profile.principal_id, Some(get_mock_user_alice_principal_id()) ); + + assert_eq!( + data.configuration.url_to_send_canister_metrics_to, + Some("http://metrics-url.com/receive-metrics".to_string()) + ); } } diff --git a/src/canister/individual_user_template/src/api/canister_lifecycle/post_upgrade.rs b/src/canister/individual_user_template/src/api/canister_lifecycle/post_upgrade.rs index d3015bfe..29332fdc 100644 --- a/src/canister/individual_user_template/src/api/canister_lifecycle/post_upgrade.rs +++ b/src/canister/individual_user_template/src/api/canister_lifecycle/post_upgrade.rs @@ -1,6 +1,9 @@ use std::time::Duration; -use shared_utils::common::utils::stable_memory_serializer_deserializer; +use shared_utils::{ + canister_specific::individual_user_template::types::arg::IndividualUserTemplateInitArgs, + common::utils::stable_memory_serializer_deserializer, +}; use crate::{ api::{ @@ -11,13 +14,15 @@ use crate::{ CANISTER_DATA, }; -use super::pre_upgrade::BUFFER_SIZE_BYTES; +use super::{init::send_canister_metrics, pre_upgrade::BUFFER_SIZE_BYTES}; #[ic_cdk::post_upgrade] fn post_upgrade() { restore_data_from_stable_memory(); + save_upgrade_args_to_memory(); refetch_well_known_principals(); reenqueue_timers_for_pending_bet_outcomes(); + send_canister_metrics(); } fn restore_data_from_stable_memory() { @@ -35,6 +40,33 @@ fn restore_data_from_stable_memory() { } } +fn save_upgrade_args_to_memory() { + let upgrade_args = ic_cdk::api::call::arg_data::<(IndividualUserTemplateInitArgs,)>().0; + + CANISTER_DATA.with(|canister_data_ref_cell| { + let mut canister_data_ref_cell = canister_data_ref_cell.borrow_mut(); + + if let Some(known_principal_ids) = upgrade_args.known_principal_ids { + canister_data_ref_cell.known_principal_ids = known_principal_ids; + } + + if let Some(profile_owner) = upgrade_args.profile_owner { + canister_data_ref_cell.profile.principal_id = Some(profile_owner); + } + + if let Some(upgrade_version_number) = upgrade_args.upgrade_version_number { + canister_data_ref_cell.version_details.version_number = upgrade_version_number; + } + + if let Some(url_to_send_canister_metrics_to) = upgrade_args.url_to_send_canister_metrics_to + { + canister_data_ref_cell + .configuration + .url_to_send_canister_metrics_to = Some(url_to_send_canister_metrics_to); + } + }); +} + const DELAY_FOR_REFETCHING_WELL_KNOWN_PRINCIPALS: Duration = Duration::from_secs(1); fn refetch_well_known_principals() { ic_cdk_timers::set_timer(DELAY_FOR_REFETCHING_WELL_KNOWN_PRINCIPALS, || { diff --git a/src/canister/individual_user_template/src/api/follow/get_principals_that_follow_this_profile_paginated.rs b/src/canister/individual_user_template/src/api/follow/get_principals_that_follow_this_profile_paginated.rs index 44c56105..1839b070 100644 --- a/src/canister/individual_user_template/src/api/follow/get_principals_that_follow_this_profile_paginated.rs +++ b/src/canister/individual_user_template/src/api/follow/get_principals_that_follow_this_profile_paginated.rs @@ -64,8 +64,8 @@ mod test { (0..25).for_each(|id: u64| { let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), }; canister_data.follow_data.follower.add(follow_entry_detail); }); @@ -83,8 +83,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() @@ -104,8 +104,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() @@ -126,8 +126,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() @@ -148,8 +148,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() @@ -170,8 +170,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() diff --git a/src/canister/individual_user_template/src/api/follow/get_principals_this_profile_follows_paginated.rs b/src/canister/individual_user_template/src/api/follow/get_principals_this_profile_follows_paginated.rs index 5682675d..f12384b0 100644 --- a/src/canister/individual_user_template/src/api/follow/get_principals_this_profile_follows_paginated.rs +++ b/src/canister/individual_user_template/src/api/follow/get_principals_this_profile_follows_paginated.rs @@ -62,8 +62,8 @@ mod test { (0..25).for_each(|id: u64| { let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), }; canister_data.follow_data.following.add(follow_entry_detail); }); @@ -79,8 +79,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() @@ -98,8 +98,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() @@ -118,8 +118,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() @@ -138,8 +138,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() @@ -158,8 +158,8 @@ mod test { .map(|id: u64| ( id, FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), } )) .collect::>() diff --git a/src/canister/individual_user_template/src/api/follow/update_profiles_i_follow_toggle_list_with_specified_profile.rs b/src/canister/individual_user_template/src/api/follow/update_profiles_i_follow_toggle_list_with_specified_profile.rs index 868d1de2..f39b9444 100644 --- a/src/canister/individual_user_template/src/api/follow/update_profiles_i_follow_toggle_list_with_specified_profile.rs +++ b/src/canister/individual_user_template/src/api/follow/update_profiles_i_follow_toggle_list_with_specified_profile.rs @@ -124,8 +124,8 @@ mod test { (0..MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST).for_each(|id: u64| { let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), }; canister_data.follow_data.following.add(follow_entry_detail); }); @@ -136,10 +136,10 @@ mod test { let follow_entry_detail = FollowEntryDetail { principal_id: Principal::self_authenticating( - &(MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST + 1).to_ne_bytes(), + (MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST + 1).to_ne_bytes(), ), canister_id: Principal::self_authenticating( - &(MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST + 1).to_ne_bytes(), + (MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST + 1).to_ne_bytes(), ), }; canister_data.follow_data.following.add(follow_entry_detail); diff --git a/src/canister/individual_user_template/src/api/follow/update_profiles_that_follow_me_toggle_list_with_specified_profile.rs b/src/canister/individual_user_template/src/api/follow/update_profiles_that_follow_me_toggle_list_with_specified_profile.rs index aae38ab0..b6fdc11c 100644 --- a/src/canister/individual_user_template/src/api/follow/update_profiles_that_follow_me_toggle_list_with_specified_profile.rs +++ b/src/canister/individual_user_template/src/api/follow/update_profiles_that_follow_me_toggle_list_with_specified_profile.rs @@ -92,8 +92,8 @@ mod test { calling_canister_principal = get_mock_user_alice_canister_id(); (0..MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST).for_each(|id: u64| { let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&id.to_ne_bytes()), - canister_id: Principal::self_authenticating(&id.to_ne_bytes()), + principal_id: Principal::self_authenticating(id.to_ne_bytes()), + canister_id: Principal::self_authenticating(id.to_ne_bytes()), }; canister_data.follow_data.follower.add(follow_entry_detail); }); @@ -108,10 +108,10 @@ mod test { let follow_entry_detail = FollowEntryDetail { principal_id: Principal::self_authenticating( - &(MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST + 1).to_ne_bytes(), + (MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST + 1).to_ne_bytes(), ), canister_id: Principal::self_authenticating( - &(MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST + 1).to_ne_bytes(), + (MAX_USERS_IN_FOLLOWER_FOLLOWING_LIST + 1).to_ne_bytes(), ), }; canister_data.follow_data.follower.add(follow_entry_detail); @@ -140,15 +140,12 @@ mod test { ); assert!(result.is_ok()); - assert_eq!(*result.as_ref().unwrap(), true); - assert_eq!(canister_data.follow_data.follower.len(), 1 as usize); - assert_eq!( - canister_data - .follow_data - .follower - .contains(&follow_entry_detail), - true - ); + assert!(*result.as_ref().unwrap()); + assert_eq!(canister_data.follow_data.follower.len(), 1_usize); + assert!(canister_data + .follow_data + .follower + .contains(&follow_entry_detail)); let result = update_profiles_that_follow_me_toggle_list_with_specified_profile_impl( &mut canister_data, @@ -157,14 +154,11 @@ mod test { ); assert!(result.is_ok()); - assert_eq!(*result.as_ref().unwrap(), false); - assert_eq!(canister_data.follow_data.follower.len(), 0 as usize); - assert_eq!( - canister_data - .follow_data - .follower - .contains(&follow_entry_detail), - false - ); + assert!(!(*result.as_ref().unwrap())); + assert_eq!(canister_data.follow_data.follower.len(), 0_usize); + assert!(!canister_data + .follow_data + .follower + .contains(&follow_entry_detail)); } } diff --git a/src/canister/individual_user_template/src/api/hot_or_not_bet/receive_bet_from_bet_makers_canister.rs b/src/canister/individual_user_template/src/api/hot_or_not_bet/receive_bet_from_bet_makers_canister.rs index a947e885..54ad7a45 100644 --- a/src/canister/individual_user_template/src/api/hot_or_not_bet/receive_bet_from_bet_makers_canister.rs +++ b/src/canister/individual_user_template/src/api/hot_or_not_bet/receive_bet_from_bet_makers_canister.rs @@ -67,7 +67,7 @@ fn receive_bet_from_bet_makers_canister_impl( bet_maker_canister_id, bet_amount, &bet_direction, - ¤t_time, + current_time, ) } diff --git a/src/canister/individual_user_template/src/api/hot_or_not_bet/reenqueue_timers_for_pending_bet_outcomes.rs b/src/canister/individual_user_template/src/api/hot_or_not_bet/reenqueue_timers_for_pending_bet_outcomes.rs index 49e5c2c1..a242341e 100644 --- a/src/canister/individual_user_template/src/api/hot_or_not_bet/reenqueue_timers_for_pending_bet_outcomes.rs +++ b/src/canister/individual_user_template/src/api/hot_or_not_bet/reenqueue_timers_for_pending_bet_outcomes.rs @@ -66,7 +66,7 @@ fn reenqueue_timers_for_these_posts( CANISTER_DATA.with(|canister_data_ref_cell| { tabulate_hot_or_not_outcome_for_post_slot( &mut canister_data_ref_cell.borrow_mut(), - post_id.clone(), + post_id, slot_number + 1, ); }); @@ -145,7 +145,7 @@ mod test { video_uid: "video#0001".to_string(), status: PostStatus::ReadyToView, created_at: post_0_creation_time - .checked_add(Duration::from_secs((1 * 60) * 60)) + .checked_add(Duration::from_secs(60 * 60)) .unwrap(), likes: HashSet::new(), share_count: 0, @@ -170,7 +170,7 @@ mod test { assert_eq!(posts_that_have_pending_outcomes[0], 1); let current_time = post_0_creation_time - .checked_add(Duration::from_secs(((48 * 60) + 0) * 60)) + .checked_add(Duration::from_secs((48 * 60) * 60)) .unwrap(); let posts_that_have_pending_outcomes = diff --git a/src/canister/individual_user_template/src/api/hot_or_not_bet/tabulate_hot_or_not_outcome_for_post_slot.rs b/src/canister/individual_user_template/src/api/hot_or_not_bet/tabulate_hot_or_not_outcome_for_post_slot.rs index e4965199..e3358e8b 100644 --- a/src/canister/individual_user_template/src/api/hot_or_not_bet/tabulate_hot_or_not_outcome_for_post_slot.rs +++ b/src/canister/individual_user_template/src/api/hot_or_not_bet/tabulate_hot_or_not_outcome_for_post_slot.rs @@ -18,16 +18,16 @@ pub fn tabulate_hot_or_not_outcome_for_post_slot( let this_canister_id = ic_cdk::id(); let post_to_tabulate_results_for = canister_data.all_created_posts.get_mut(&post_id).unwrap(); - let mut token_balance = &mut canister_data.my_token_balance; + let token_balance = &mut canister_data.my_token_balance; post_to_tabulate_results_for.tabulate_hot_or_not_outcome_for_slot( &this_canister_id, &slot_id, - &mut token_balance, + token_balance, ¤t_time, ); - inform_participants_of_outcome(&post_to_tabulate_results_for, &slot_id); + inform_participants_of_outcome(post_to_tabulate_results_for, &slot_id); } fn inform_participants_of_outcome(post: &Post, slot_id: &u8) { diff --git a/src/canister/individual_user_template/src/api/post/get_entire_individual_post_detail_by_id.rs b/src/canister/individual_user_template/src/api/post/get_entire_individual_post_detail_by_id.rs index e0391625..213394b6 100644 --- a/src/canister/individual_user_template/src/api/post/get_entire_individual_post_detail_by_id.rs +++ b/src/canister/individual_user_template/src/api/post/get_entire_individual_post_detail_by_id.rs @@ -11,12 +11,11 @@ pub fn get_entire_individual_post_detail_by_id(post_id: u64) -> Result let api_caller = ic_cdk::caller(); let super_admin_user = CANISTER_DATA.with(|canister_data_ref_cell| { - canister_data_ref_cell + *canister_data_ref_cell .borrow() .known_principal_ids .get(&KnownPrincipalType::UserIdGlobalSuperAdmin) .unwrap() - .clone() }); if api_caller != super_admin_user { diff --git a/src/canister/individual_user_template/src/api/post/get_individual_post_details_by_id.rs b/src/canister/individual_user_template/src/api/post/get_individual_post_details_by_id.rs index 59187614..074fad0a 100644 --- a/src/canister/individual_user_template/src/api/post/get_individual_post_details_by_id.rs +++ b/src/canister/individual_user_template/src/api/post/get_individual_post_details_by_id.rs @@ -31,7 +31,7 @@ pub fn get_individual_post_details_by_id(post_id: u64) -> PostDetailsForFrontend following_count: following.len() as u64, principal_id: profile.principal_id.unwrap(), profile_picture_url: profile.profile_picture_url.clone(), - profile_stats: profile.profile_stats.clone(), + profile_stats: profile.profile_stats, unique_user_name: profile.unique_user_name.clone(), lifetime_earnings: token_balance.lifetime_earnings, }, diff --git a/src/canister/individual_user_template/src/api/post/get_posts_of_this_user_profile_with_pagination.rs b/src/canister/individual_user_template/src/api/post/get_posts_of_this_user_profile_with_pagination.rs index ee7a164c..74da76fa 100644 --- a/src/canister/individual_user_template/src/api/post/get_posts_of_this_user_profile_with_pagination.rs +++ b/src/canister/individual_user_template/src/api/post/get_posts_of_this_user_profile_with_pagination.rs @@ -54,7 +54,7 @@ fn get_posts_of_this_user_profile_with_pagination( following_count: following.len() as u64, principal_id: profile.principal_id.unwrap(), profile_picture_url: profile.profile_picture_url.clone(), - profile_stats: profile.profile_stats.clone(), + profile_stats: profile.profile_stats, unique_user_name: profile.unique_user_name.clone(), lifetime_earnings: token_balance.lifetime_earnings, }, diff --git a/src/canister/individual_user_template/src/api/profile/get_profile_details.rs b/src/canister/individual_user_template/src/api/profile/get_profile_details.rs index e16f719f..b80867b8 100644 --- a/src/canister/individual_user_template/src/api/profile/get_profile_details.rs +++ b/src/canister/individual_user_template/src/api/profile/get_profile_details.rs @@ -13,7 +13,7 @@ fn get_profile_details() -> UserProfileDetailsForFrontend { display_name: profile.display_name.clone(), unique_user_name: profile.unique_user_name.clone(), profile_picture_url: profile.profile_picture_url.clone(), - profile_stats: profile.profile_stats.clone(), + profile_stats: profile.profile_stats, followers_count: canister_data_ref_cell.borrow().follow_data.follower.len() as u64, following_count: canister_data_ref_cell.borrow().follow_data.following.len() as u64, lifetime_earnings: token_balance.lifetime_earnings, diff --git a/src/canister/individual_user_template/src/api/profile/update_profile_display_details.rs b/src/canister/individual_user_template/src/api/profile/update_profile_display_details.rs index df34b0aa..8b0f849b 100644 --- a/src/canister/individual_user_template/src/api/profile/update_profile_display_details.rs +++ b/src/canister/individual_user_template/src/api/profile/update_profile_display_details.rs @@ -43,7 +43,7 @@ fn update_profile_display_details( display_name: profile.display_name.clone(), unique_user_name: profile.unique_user_name.clone(), profile_picture_url: profile.profile_picture_url.clone(), - profile_stats: profile.profile_stats.clone(), + profile_stats: profile.profile_stats, followers_count: canister_data_ref_cell .borrow() .principals_that_follow_me diff --git a/src/canister/individual_user_template/src/api/token/get_rewarded_for_signing_up.rs b/src/canister/individual_user_template/src/api/token/get_rewarded_for_signing_up.rs index 48b236d5..e36ac412 100644 --- a/src/canister/individual_user_template/src/api/token/get_rewarded_for_signing_up.rs +++ b/src/canister/individual_user_template/src/api/token/get_rewarded_for_signing_up.rs @@ -29,7 +29,7 @@ fn get_rewarded_for_signing_up() { CANISTER_DATA.with(|canister_data_ref_cell| { let mut canister_data_ref = canister_data_ref_cell.borrow_mut(); - let my_principal_id = canister_data_ref.profile.principal_id.unwrap().clone(); + let my_principal_id = canister_data_ref.profile.principal_id.unwrap(); let my_token_balance = &mut canister_data_ref.my_token_balance; let signup_reward_amount = diff --git a/src/canister/individual_user_template/src/api/well_known_principal/get_well_known_principal_value.rs b/src/canister/individual_user_template/src/api/well_known_principal/get_well_known_principal_value.rs index f8c6581f..46750f04 100644 --- a/src/canister/individual_user_template/src/api/well_known_principal/get_well_known_principal_value.rs +++ b/src/canister/individual_user_template/src/api/well_known_principal/get_well_known_principal_value.rs @@ -8,7 +8,7 @@ use crate::CANISTER_DATA; fn get_well_known_principal_value(principal_type: KnownPrincipalType) -> Option { CANISTER_DATA.with(|canister_data_ref_cell| { let known_principal_ids = &canister_data_ref_cell.borrow().known_principal_ids; - get_well_known_principal_value_impl(&principal_type, &known_principal_ids) + get_well_known_principal_value_impl(&principal_type, known_principal_ids) }) } @@ -16,9 +16,7 @@ fn get_well_known_principal_value_impl( principal_type: &KnownPrincipalType, known_principal_ids: &KnownPrincipalMap, ) -> Option { - known_principal_ids - .get(principal_type) - .map(|principal| principal.clone()) + known_principal_ids.get(principal_type).copied() } #[cfg(test)] diff --git a/src/canister/individual_user_template/src/api/well_known_principal/update_locally_stored_well_known_principals.rs b/src/canister/individual_user_template/src/api/well_known_principal/update_locally_stored_well_known_principals.rs index c06dc293..94eab767 100644 --- a/src/canister/individual_user_template/src/api/well_known_principal/update_locally_stored_well_known_principals.rs +++ b/src/canister/individual_user_template/src/api/well_known_principal/update_locally_stored_well_known_principals.rs @@ -6,26 +6,13 @@ use crate::CANISTER_DATA; pub async fn update_locally_stored_well_known_principals() { // extract the canister ID of the configuration canister from well-known principals - // let config_canister_id = CANISTER_DATA.with(|canister_data_ref_cell| { - // canister_data_ref_cell - // .borrow() - // .known_principal_ids - // .get(&KnownPrincipalType::CanisterIdConfiguration) - // .unwrap() - // .clone() - // }); - - let config_canister_id = match option_env!("DFX_NETWORK") { - Some("ic") => Principal::from_text("efsfj-sqaaa-aaaap-qatwa-cai").unwrap(), - _ => CANISTER_DATA.with(|canister_data_ref_cell| { - canister_data_ref_cell - .borrow() - .known_principal_ids - .get(&KnownPrincipalType::CanisterIdConfiguration) - .unwrap() - .clone() - }), - }; + let config_canister_id = CANISTER_DATA.with(|canister_data_ref_cell| { + *canister_data_ref_cell + .borrow() + .known_principal_ids + .get(&KnownPrincipalType::CanisterIdConfiguration) + .unwrap() + }); // * Fetch the well-known principals from the configuration canister let (well_known_principals,): (Vec<(KnownPrincipalType, Principal)>,) = call::call( diff --git a/src/canister/individual_user_template/src/data_model/mod.rs b/src/canister/individual_user_template/src/data_model/mod.rs index 26ec14e8..2f99bd28 100644 --- a/src/canister/individual_user_template/src/data_model/mod.rs +++ b/src/canister/individual_user_template/src/data_model/mod.rs @@ -5,8 +5,8 @@ use ic_cdk::api::management_canister::provisional::CanisterId; use serde::Serialize; use shared_utils::{ canister_specific::individual_user_template::types::{ - follow::FollowData, hot_or_not::PlacedBetDetail, post::Post, profile::UserProfile, - token::TokenBalance, + configuration::IndividualUserConfiguration, follow::FollowData, + hot_or_not::PlacedBetDetail, post::Post, profile::UserProfile, token::TokenBalance, }, common::types::{ app_primitive_type::PostId, known_principal::KnownPrincipalMap, @@ -23,6 +23,8 @@ pub struct CanisterData { // Key is Post ID pub all_created_posts: BTreeMap, pub all_hot_or_not_bets_placed: BTreeMap<(CanisterId, PostId), PlacedBetDetail>, + #[serde(default)] + pub configuration: IndividualUserConfiguration, pub follow_data: FollowData, pub known_principal_ids: KnownPrincipalMap, pub my_token_balance: TokenBalance, diff --git a/src/canister/individual_user_template/src/data_model/version_details.rs b/src/canister/individual_user_template/src/data_model/version_details.rs index 3897c43c..d826846b 100644 --- a/src/canister/individual_user_template/src/data_model/version_details.rs +++ b/src/canister/individual_user_template/src/data_model/version_details.rs @@ -3,5 +3,5 @@ use serde::Serialize; #[derive(Default, CandidType, Deserialize, Serialize)] pub struct VersionDetails { - version_number: u64, + pub version_number: u64, } diff --git a/src/canister/post_cache/src/api/feed/remove_all_feed_entries.rs b/src/canister/post_cache/src/api/feed/remove_all_feed_entries.rs index 6c7a3462..a55166ea 100644 --- a/src/canister/post_cache/src/api/feed/remove_all_feed_entries.rs +++ b/src/canister/post_cache/src/api/feed/remove_all_feed_entries.rs @@ -10,12 +10,11 @@ fn remove_all_feed_entries() { let api_caller = ic_cdk::caller(); let super_admin_user = CANISTER_DATA.with(|canister_data_ref_cell| { - canister_data_ref_cell + *canister_data_ref_cell .borrow() .known_principal_ids .get(&KnownPrincipalType::UserIdGlobalSuperAdmin) .unwrap() - .clone() }); if api_caller != super_admin_user { diff --git a/src/canister/post_cache/src/api/home_feed/receive_top_home_feed_posts_from_publishing_canister.rs b/src/canister/post_cache/src/api/home_feed/receive_top_home_feed_posts_from_publishing_canister.rs index 31d2ec1e..e3dd2597 100644 --- a/src/canister/post_cache/src/api/home_feed/receive_top_home_feed_posts_from_publishing_canister.rs +++ b/src/canister/post_cache/src/api/home_feed/receive_top_home_feed_posts_from_publishing_canister.rs @@ -77,7 +77,7 @@ mod test { assert_eq!( posts_index_sorted_by_home_feed_score .iter() - .nth(0) + .next() .unwrap() .post_id, 3 diff --git a/src/canister/post_cache/src/api/well_known_principal/get_well_known_principal_value.rs b/src/canister/post_cache/src/api/well_known_principal/get_well_known_principal_value.rs index f8c6581f..46750f04 100644 --- a/src/canister/post_cache/src/api/well_known_principal/get_well_known_principal_value.rs +++ b/src/canister/post_cache/src/api/well_known_principal/get_well_known_principal_value.rs @@ -8,7 +8,7 @@ use crate::CANISTER_DATA; fn get_well_known_principal_value(principal_type: KnownPrincipalType) -> Option { CANISTER_DATA.with(|canister_data_ref_cell| { let known_principal_ids = &canister_data_ref_cell.borrow().known_principal_ids; - get_well_known_principal_value_impl(&principal_type, &known_principal_ids) + get_well_known_principal_value_impl(&principal_type, known_principal_ids) }) } @@ -16,9 +16,7 @@ fn get_well_known_principal_value_impl( principal_type: &KnownPrincipalType, known_principal_ids: &KnownPrincipalMap, ) -> Option { - known_principal_ids - .get(principal_type) - .map(|principal| principal.clone()) + known_principal_ids.get(principal_type).copied() } #[cfg(test)] diff --git a/src/canister/post_cache/src/api/well_known_principal/update_locally_stored_well_known_principals.rs b/src/canister/post_cache/src/api/well_known_principal/update_locally_stored_well_known_principals.rs index edfa6ec4..59956f41 100644 --- a/src/canister/post_cache/src/api/well_known_principal/update_locally_stored_well_known_principals.rs +++ b/src/canister/post_cache/src/api/well_known_principal/update_locally_stored_well_known_principals.rs @@ -7,12 +7,11 @@ use crate::CANISTER_DATA; pub async fn update_locally_stored_well_known_principals() { // extract the canister ID of the configuration canister from well-known principals let config_canister_id = CANISTER_DATA.with(|canister_data_ref_cell| { - canister_data_ref_cell + *canister_data_ref_cell .borrow() .known_principal_ids .get(&KnownPrincipalType::CanisterIdConfiguration) .unwrap() - .clone() }); // fetch the well-known principals from the configuration canister diff --git a/src/canister/user_index/src/api/backup_and_restore/backup_all_individual_user_canisters.rs b/src/canister/user_index/src/api/backup_and_restore/backup_all_individual_user_canisters.rs index 66c959e6..6c114ef2 100644 --- a/src/canister/user_index/src/api/backup_and_restore/backup_all_individual_user_canisters.rs +++ b/src/canister/user_index/src/api/backup_and_restore/backup_all_individual_user_canisters.rs @@ -30,12 +30,9 @@ async fn backup_all_individual_user_canisters() { for (user_principal_id, user_canister_principal_id) in all_individual_user_canister_ids.iter() { let upgrade_response: CallResult<()> = call::call( - user_canister_principal_id.clone(), + *user_canister_principal_id, "backup_data_to_backup_canister", - ( - user_principal_id.clone(), - user_canister_principal_id.clone(), - ), + (*user_principal_id, *user_canister_principal_id), ) .await; upgrade_response.ok(); diff --git a/src/canister/user_index/src/api/backup_and_restore/receive_data_from_backup_canister_and_restore_data_to_heap.rs b/src/canister/user_index/src/api/backup_and_restore/receive_data_from_backup_canister_and_restore_data_to_heap.rs index 146d7d5d..eb919885 100644 --- a/src/canister/user_index/src/api/backup_and_restore/receive_data_from_backup_canister_and_restore_data_to_heap.rs +++ b/src/canister/user_index/src/api/backup_and_restore/receive_data_from_backup_canister_and_restore_data_to_heap.rs @@ -30,12 +30,11 @@ fn receive_data_from_backup_canister_and_restore_data_to_heap_impl( user_canister_id: Principal, unique_user_name: String, ) { - if !(canister_data + if *canister_data .known_principal_ids .get(&KnownPrincipalType::CanisterIdDataBackup) .unwrap() - .clone() - == caller_principal_id) + != caller_principal_id { return; } diff --git a/src/canister/user_index/src/api/canister_lifecycle/init.rs b/src/canister/user_index/src/api/canister_lifecycle/init.rs index 0e2d924c..11105abc 100644 --- a/src/canister/user_index/src/api/canister_lifecycle/init.rs +++ b/src/canister/user_index/src/api/canister_lifecycle/init.rs @@ -18,7 +18,7 @@ fn init_impl(init_args: UserIndexInitArgs, data: &mut CanisterData) { .iter() .for_each(|(principal_belongs_to, principal_id)| { data.known_principal_ids - .insert(principal_belongs_to.clone(), principal_id.clone()); + .insert(principal_belongs_to.clone(), *principal_id); }); } diff --git a/src/canister/user_index/src/api/canister_lifecycle/post_upgrade.rs b/src/canister/user_index/src/api/canister_lifecycle/post_upgrade.rs index 16da6ef3..403512a9 100644 --- a/src/canister/user_index/src/api/canister_lifecycle/post_upgrade.rs +++ b/src/canister/user_index/src/api/canister_lifecycle/post_upgrade.rs @@ -7,7 +7,7 @@ use crate::{ upgrade_individual_user_template::update_user_index_upgrade_user_canisters_with_latest_wasm, well_known_principal::update_locally_stored_well_known_principals, }, - data_model::CanisterData, + data_model::{configuration::Configuration, CanisterData}, CANISTER_DATA, }; @@ -18,6 +18,18 @@ fn post_upgrade() { restore_data_from_stable_memory(); refetch_well_known_principals(); upgrade_all_indexed_user_canisters(); + + CANISTER_DATA.with(|canister_data_ref_cell| { + let well_known_principals = canister_data_ref_cell.borrow().known_principal_ids.clone(); + + canister_data_ref_cell.borrow_mut().configuration = Configuration { + known_principal_ids: well_known_principals, + signups_open_on_this_subnet: false, + url_to_send_canister_metrics_to: + "https://receive-canister-metrics-and-push-to-timeseries-d-74gsa5ifla-uc.a.run.app/receive-metrics" + .to_string(), + }; + }); } fn restore_data_from_stable_memory() { diff --git a/src/canister/user_index/src/api/upgrade_individual_user_template/get_index_details_last_upgrade_status.rs b/src/canister/user_index/src/api/upgrade_individual_user_template/get_index_details_last_upgrade_status.rs index 297807ea..e25f6f85 100644 --- a/src/canister/user_index/src/api/upgrade_individual_user_template/get_index_details_last_upgrade_status.rs +++ b/src/canister/user_index/src/api/upgrade_individual_user_template/get_index_details_last_upgrade_status.rs @@ -1,4 +1,4 @@ -use crate::{data_model::canister_upgrade::upgrade_status::UpgradeStatus, CANISTER_DATA}; +use crate::{data_model::canister_upgrade::UpgradeStatus, CANISTER_DATA}; #[ic_cdk::query] #[candid::candid_method(query)] diff --git a/src/canister/user_index/src/api/upgrade_individual_user_template/update_user_index_upgrade_user_canisters_with_latest_wasm.rs b/src/canister/user_index/src/api/upgrade_individual_user_template/update_user_index_upgrade_user_canisters_with_latest_wasm.rs index 8656c9ba..af4ea586 100644 --- a/src/canister/user_index/src/api/upgrade_individual_user_template/update_user_index_upgrade_user_canisters_with_latest_wasm.rs +++ b/src/canister/user_index/src/api/upgrade_individual_user_template/update_user_index_upgrade_user_canisters_with_latest_wasm.rs @@ -11,7 +11,11 @@ use shared_utils::{ constant::{CYCLES_THRESHOLD_TO_INITIATE_RECHARGE, INDIVIDUAL_USER_CANISTER_RECHARGE_AMOUNT}, }; -use crate::{data_model::CanisterData, util::canister_management, CANISTER_DATA}; +use crate::{ + data_model::{configuration::Configuration, CanisterData}, + util::canister_management, + CANISTER_DATA, +}; pub async fn upgrade_user_canisters_with_latest_wasm() { let mut upgrade_count = 0; @@ -31,6 +35,9 @@ pub async fn upgrade_user_canisters_with_latest_wasm() { .clone() }); + let configuration = CANISTER_DATA + .with(|canister_data_ref_cell| canister_data_ref_cell.borrow().configuration.clone()); + for (user_principal_id, user_canister_id) in user_principal_id_to_canister_id_map.iter() { let is_canister_below_threshold_balance = is_canister_below_threshold_balance(user_canister_id).await; @@ -45,8 +52,13 @@ pub async fn upgrade_user_canisters_with_latest_wasm() { } } - let upgrade_result = - upgrade_user_canister(user_canister_id, saved_upgrade_status.version_number).await; + let upgrade_result = upgrade_user_canister( + user_principal_id, + user_canister_id, + saved_upgrade_status.version_number, + &configuration, + ) + .await; if upgrade_result.is_err() { let err = upgrade_result.err().unwrap(); @@ -106,45 +118,53 @@ async fn is_canister_below_threshold_balance(canister_id: &Principal) -> bool { return true; } - return false; + false } async fn recharge_canister(canister_id: &Principal) -> Result<(), String> { - Ok(main::deposit_cycles( + main::deposit_cycles( CanisterIdRecord { canister_id: *canister_id, }, INDIVIDUAL_USER_CANISTER_RECHARGE_AMOUNT, ) .await - .map_err(|e| e.1)?) + .map_err(|e| e.1) } -async fn upgrade_user_canister(canister_id: &Principal, version_number: u64) -> Result<(), String> { - Ok(canister_management::upgrade_individual_user_canister( +async fn upgrade_user_canister( + user_principal_id: &Principal, + canister_id: &Principal, + version_number: u64, + configuration: &Configuration, +) -> Result<(), String> { + canister_management::upgrade_individual_user_canister( *canister_id, CanisterInstallMode::Upgrade, IndividualUserTemplateInitArgs { - known_principal_ids: None, - profile_owner: None, + known_principal_ids: Some(configuration.known_principal_ids.clone()), + profile_owner: Some(*user_principal_id), upgrade_version_number: Some(version_number + 1), + url_to_send_canister_metrics_to: Some( + configuration.url_to_send_canister_metrics_to.clone(), + ), }, ) .await - .map_err(|e| e.1)?) + .map_err(|e| e.1) } fn update_upgrade_status( canister_data: &mut CanisterData, upgrade_count: u32, - failed_canister_ids: &Vec<(Principal, Principal, String)>, + failed_canister_ids: &[(Principal, Principal, String)], version_number: Option, last_run_on: Option, ) { let mut last_run_upgrade_status = canister_data.last_run_upgrade_status.clone(); last_run_upgrade_status.successful_upgrade_count = upgrade_count; - last_run_upgrade_status.failed_canister_ids = failed_canister_ids.clone(); + last_run_upgrade_status.failed_canister_ids = failed_canister_ids.to_owned(); last_run_upgrade_status.version_number = version_number.unwrap_or(canister_data.last_run_upgrade_status.version_number); last_run_upgrade_status.last_run_on = diff --git a/src/canister/user_index/src/api/upgrade_individual_user_template/upgrade_specific_individual_user_canister_with_latest_wasm.rs b/src/canister/user_index/src/api/upgrade_individual_user_template/upgrade_specific_individual_user_canister_with_latest_wasm.rs index 45ddbaf9..713f66af 100644 --- a/src/canister/user_index/src/api/upgrade_individual_user_template/upgrade_specific_individual_user_canister_with_latest_wasm.rs +++ b/src/canister/user_index/src/api/upgrade_individual_user_template/upgrade_specific_individual_user_canister_with_latest_wasm.rs @@ -21,10 +21,9 @@ async fn upgrade_specific_individual_user_canister_with_latest_wasm( let known_principal_ids = CANISTER_DATA .with(|canister_data_ref_cell| canister_data_ref_cell.borrow().known_principal_ids.clone()); - if known_principal_ids + if *known_principal_ids .get(&KnownPrincipalType::UserIdGlobalSuperAdmin) .unwrap() - .clone() != api_caller { return "Unauthorized caller".to_string(); @@ -37,8 +36,11 @@ async fn upgrade_specific_individual_user_canister_with_latest_wasm( .clone() }); + let configuration = CANISTER_DATA + .with(|canister_data_ref_cell| canister_data_ref_cell.borrow().configuration.clone()); + match canister_management::upgrade_individual_user_canister( - user_canister_id.clone(), + user_canister_id, upgrade_mode.unwrap_or(CanisterInstallMode::Upgrade), IndividualUserTemplateInitArgs { known_principal_ids: Some(CANISTER_DATA.with(|canister_data_ref_cell| { @@ -46,15 +48,12 @@ async fn upgrade_specific_individual_user_canister_with_latest_wasm( })), profile_owner: Some(user_principal_id), upgrade_version_number: Some(saved_upgrade_status.version_number + 1), + url_to_send_canister_metrics_to: Some(configuration.url_to_send_canister_metrics_to), }, ) .await { - Ok(_) => { - return "Success".to_string(); - } - Err(e) => { - return e.1; - } + Ok(_) => "Success".to_string(), + Err(e) => e.1, } } diff --git a/src/canister/user_index/src/api/user_record/update_index_with_unique_user_name_corresponding_to_user_principal_id.rs b/src/canister/user_index/src/api/user_record/update_index_with_unique_user_name_corresponding_to_user_principal_id.rs index 23caf5f2..5d6bac25 100644 --- a/src/canister/user_index/src/api/user_record/update_index_with_unique_user_name_corresponding_to_user_principal_id.rs +++ b/src/canister/user_index/src/api/user_record/update_index_with_unique_user_name_corresponding_to_user_principal_id.rs @@ -51,7 +51,7 @@ fn update_index_with_unique_user_name_corresponding_to_user_principal_id_impl( canister_data .unique_user_name_to_user_principal_id_map - .insert(unique_user_name.clone(), user_principal_id.clone()); + .insert(unique_user_name.clone(), user_principal_id); Ok(()) } @@ -75,8 +75,8 @@ mod test { let result = update_index_with_unique_user_name_corresponding_to_user_principal_id_impl( unique_user_name_1.clone(), - user_principal_id.clone(), - request_makers_canister_id.clone(), + user_principal_id, + request_makers_canister_id, &mut canister_data, ); assert!(result.is_err()); @@ -85,14 +85,13 @@ mod test { SetUniqueUsernameError::UserCanisterEntryDoesNotExist ); - canister_data.user_principal_id_to_canister_id_map.insert( - user_principal_id.clone(), - request_makers_canister_id.clone(), - ); + canister_data + .user_principal_id_to_canister_id_map + .insert(user_principal_id, request_makers_canister_id); let result = update_index_with_unique_user_name_corresponding_to_user_principal_id_impl( unique_user_name_1.clone(), - user_principal_id.clone(), + user_principal_id, get_mock_user_bob_canister_id(), &mut canister_data, ); @@ -108,8 +107,8 @@ mod test { let result = update_index_with_unique_user_name_corresponding_to_user_principal_id_impl( unique_user_name_1.clone(), - user_principal_id.clone(), - request_makers_canister_id.clone(), + user_principal_id, + request_makers_canister_id, &mut canister_data, ); assert!(result.is_err()); @@ -120,8 +119,8 @@ mod test { let result = update_index_with_unique_user_name_corresponding_to_user_principal_id_impl( unique_user_name_2.clone(), - user_principal_id.clone(), - request_makers_canister_id.clone(), + user_principal_id, + request_makers_canister_id, &mut canister_data, ); assert!(result.is_ok()); diff --git a/src/canister/user_index/src/api/well_known_principal/get_well_known_principal_value.rs b/src/canister/user_index/src/api/well_known_principal/get_well_known_principal_value.rs index f8c6581f..46750f04 100644 --- a/src/canister/user_index/src/api/well_known_principal/get_well_known_principal_value.rs +++ b/src/canister/user_index/src/api/well_known_principal/get_well_known_principal_value.rs @@ -8,7 +8,7 @@ use crate::CANISTER_DATA; fn get_well_known_principal_value(principal_type: KnownPrincipalType) -> Option { CANISTER_DATA.with(|canister_data_ref_cell| { let known_principal_ids = &canister_data_ref_cell.borrow().known_principal_ids; - get_well_known_principal_value_impl(&principal_type, &known_principal_ids) + get_well_known_principal_value_impl(&principal_type, known_principal_ids) }) } @@ -16,9 +16,7 @@ fn get_well_known_principal_value_impl( principal_type: &KnownPrincipalType, known_principal_ids: &KnownPrincipalMap, ) -> Option { - known_principal_ids - .get(principal_type) - .map(|principal| principal.clone()) + known_principal_ids.get(principal_type).copied() } #[cfg(test)] diff --git a/src/canister/user_index/src/api/well_known_principal/update_locally_stored_well_known_principals.rs b/src/canister/user_index/src/api/well_known_principal/update_locally_stored_well_known_principals.rs index edfa6ec4..59956f41 100644 --- a/src/canister/user_index/src/api/well_known_principal/update_locally_stored_well_known_principals.rs +++ b/src/canister/user_index/src/api/well_known_principal/update_locally_stored_well_known_principals.rs @@ -7,12 +7,11 @@ use crate::CANISTER_DATA; pub async fn update_locally_stored_well_known_principals() { // extract the canister ID of the configuration canister from well-known principals let config_canister_id = CANISTER_DATA.with(|canister_data_ref_cell| { - canister_data_ref_cell + *canister_data_ref_cell .borrow() .known_principal_ids .get(&KnownPrincipalType::CanisterIdConfiguration) .unwrap() - .clone() }); // fetch the well-known principals from the configuration canister diff --git a/src/canister/user_index/src/data_model/canister_upgrade/mod.rs b/src/canister/user_index/src/data_model/canister_upgrade/mod.rs index d31da6e7..12a05a4c 100644 --- a/src/canister/user_index/src/data_model/canister_upgrade/mod.rs +++ b/src/canister/user_index/src/data_model/canister_upgrade/mod.rs @@ -1 +1,32 @@ -pub mod upgrade_status; +use std::{ + fmt::Display, + time::{SystemTime, UNIX_EPOCH}, +}; + +use candid::{CandidType, Deserialize, Principal}; +use serde::Serialize; + +#[derive(CandidType, Deserialize, Clone, Serialize, Debug)] +pub struct UpgradeStatus { + pub version_number: u64, + pub last_run_on: SystemTime, + pub successful_upgrade_count: u32, + pub failed_canister_ids: Vec<(Principal, Principal, String)>, +} + +impl Display for UpgradeStatus { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:#?}", self) + } +} + +impl Default for UpgradeStatus { + fn default() -> Self { + Self { + version_number: 0, + last_run_on: UNIX_EPOCH, + successful_upgrade_count: 0, + failed_canister_ids: Vec::new(), + } + } +} diff --git a/src/canister/user_index/src/data_model/canister_upgrade/upgrade_status.rs b/src/canister/user_index/src/data_model/canister_upgrade/upgrade_status.rs deleted file mode 100644 index 12a05a4c..00000000 --- a/src/canister/user_index/src/data_model/canister_upgrade/upgrade_status.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::{ - fmt::Display, - time::{SystemTime, UNIX_EPOCH}, -}; - -use candid::{CandidType, Deserialize, Principal}; -use serde::Serialize; - -#[derive(CandidType, Deserialize, Clone, Serialize, Debug)] -pub struct UpgradeStatus { - pub version_number: u64, - pub last_run_on: SystemTime, - pub successful_upgrade_count: u32, - pub failed_canister_ids: Vec<(Principal, Principal, String)>, -} - -impl Display for UpgradeStatus { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:#?}", self) - } -} - -impl Default for UpgradeStatus { - fn default() -> Self { - Self { - version_number: 0, - last_run_on: UNIX_EPOCH, - successful_upgrade_count: 0, - failed_canister_ids: Vec::new(), - } - } -} diff --git a/src/canister/user_index/src/data_model/configuration/mod.rs b/src/canister/user_index/src/data_model/configuration/mod.rs new file mode 100644 index 00000000..d0236df8 --- /dev/null +++ b/src/canister/user_index/src/data_model/configuration/mod.rs @@ -0,0 +1,11 @@ +use candid::{CandidType, Deserialize}; +use serde::Serialize; +use shared_utils::common::types::known_principal::KnownPrincipalMap; + +#[derive(Default, Deserialize, CandidType, Serialize, Clone)] +pub struct Configuration { + pub known_principal_ids: KnownPrincipalMap, + pub signups_open_on_this_subnet: bool, + #[serde(default)] + pub url_to_send_canister_metrics_to: String, +} diff --git a/src/canister/user_index/src/data_model/mod.rs b/src/canister/user_index/src/data_model/mod.rs index 535f1978..bfac88e1 100644 --- a/src/canister/user_index/src/data_model/mod.rs +++ b/src/canister/user_index/src/data_model/mod.rs @@ -4,12 +4,15 @@ use candid::{CandidType, Deserialize, Principal}; use serde::Serialize; use shared_utils::common::types::known_principal::KnownPrincipalMap; -use self::canister_upgrade::upgrade_status::UpgradeStatus; +use self::{canister_upgrade::UpgradeStatus, configuration::Configuration}; pub mod canister_upgrade; +pub mod configuration; #[derive(Default, CandidType, Deserialize, Serialize)] pub struct CanisterData { + #[serde(default)] + pub configuration: Configuration, pub last_run_upgrade_status: UpgradeStatus, pub known_principal_ids: KnownPrincipalMap, pub user_principal_id_to_canister_id_map: BTreeMap, diff --git a/src/canister/user_index/src/lib.rs b/src/canister/user_index/src/lib.rs index 94f2598c..c7862fac 100644 --- a/src/canister/user_index/src/lib.rs +++ b/src/canister/user_index/src/lib.rs @@ -1,7 +1,7 @@ use std::cell::RefCell; use candid::{export_service, Principal}; -use data_model::{canister_upgrade::upgrade_status::UpgradeStatus, CanisterData}; +use data_model::{canister_upgrade::UpgradeStatus, CanisterData}; use ic_cdk::api::management_canister::main::CanisterInstallMode; use shared_utils::{ canister_specific::user_index::types::args::UserIndexInitArgs, diff --git a/src/canister/user_index/src/util/canister_management.rs b/src/canister/user_index/src/util/canister_management.rs index 5c8a8ef4..86ff6239 100644 --- a/src/canister/user_index/src/util/canister_management.rs +++ b/src/canister/user_index/src/util/canister_management.rs @@ -37,12 +37,16 @@ pub async fn create_users_canister(profile_owner: Principal) -> Principal { .await .unwrap(); + let configuration = CANISTER_DATA + .with(|canister_data_ref_cell| canister_data_ref_cell.borrow().configuration.clone()); + let individual_user_tempalate_init_args = IndividualUserTemplateInitArgs { profile_owner: Some(profile_owner), known_principal_ids: Some(CANISTER_DATA.with(|canister_data_ref_cell| { canister_data_ref_cell.borrow().known_principal_ids.clone() })), upgrade_version_number: Some(0), + url_to_send_canister_metrics_to: Some(configuration.url_to_send_canister_metrics_to), }; // * encode argument for user canister init lifecycle method diff --git a/src/lib/integration_tests/tests/authentication/when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousand_utility_tokens_for_signing_up_and_the_referrer_and_referee_receive_five_hundred_tokens_as_referral_rewards.rs b/src/lib/integration_tests/tests/authentication/when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousand_utility_tokens_for_signing_up_and_the_referrer_and_referee_receive_five_hundred_tokens_as_referral_rewards.rs index c00cb22e..204eaf11 100644 --- a/src/lib/integration_tests/tests/authentication/when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousand_utility_tokens_for_signing_up_and_the_referrer_and_referee_receive_five_hundred_tokens_as_referral_rewards.rs +++ b/src/lib/integration_tests/tests/authentication/when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousand_utility_tokens_for_signing_up_and_the_referrer_and_referee_receive_five_hundred_tokens_as_referral_rewards.rs @@ -105,7 +105,7 @@ fn when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousan alice_canister_id, Principal::anonymous(), "get_user_utility_token_transaction_history_with_pagination", - candid::encode_args((0 as u64, 10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let response: Result< @@ -164,7 +164,7 @@ fn when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousan let alice_utility_token_balance_after_referral = state_machine .query_call( - alice_canister_id.into(), + alice_canister_id, Principal::anonymous(), "get_utility_token_balance", candid::encode_one(()).unwrap(), @@ -204,7 +204,7 @@ fn when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousan alice_canister_id, Principal::anonymous(), "get_user_utility_token_transaction_history_with_pagination", - candid::encode_args((0 as u64, 10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let response: Result< @@ -273,7 +273,7 @@ fn when_a_new_user_signs_up_from_a_referral_then_the_new_user_is_given_a_thousan bob_canister_id, Principal::anonymous(), "get_user_utility_token_transaction_history_with_pagination", - candid::encode_args((0 as u64, 10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let response: Result< diff --git a/src/lib/integration_tests/tests/backup_and_restore/when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_relevant_data_and_when_restored_they_return_the_canisters_to_their_original_state.rs b/src/lib/integration_tests/tests/backup_and_restore/when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_relevant_data_and_when_restored_they_return_the_canisters_to_their_original_state.rs index e2f27056..6f15624c 100644 --- a/src/lib/integration_tests/tests/backup_and_restore/when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_relevant_data_and_when_restored_they_return_the_canisters_to_their_original_state.rs +++ b/src/lib/integration_tests/tests/backup_and_restore/when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_relevant_data_and_when_restored_they_return_the_canisters_to_their_original_state.rs @@ -27,14 +27,12 @@ fn when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_re ) { let state_machine = get_new_state_machine(); let known_principal_map = get_initialized_env_with_provisioned_known_canisters(&state_machine); - let user_index_canister_id = known_principal_map + let user_index_canister_id = *known_principal_map .get(&KnownPrincipalType::CanisterIdUserIndex) - .unwrap() - .clone(); - let data_backup_canister_id = known_principal_map + .unwrap(); + let data_backup_canister_id = *known_principal_map .get(&KnownPrincipalType::CanisterIdDataBackup) - .unwrap() - .clone(); + .unwrap(); let alice_principal_id = get_mock_user_alice_principal_id(); let alice_unique_username = "cool_alice_1234".to_string(); let alice_display_name = "Alice".to_string(); @@ -201,7 +199,7 @@ fn when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_re alice_canister_id, Principal::anonymous(), "get_individual_post_details_by_id", - candid::encode_args((0 as u64,)).unwrap(), + candid::encode_args((0_u64,)).unwrap(), ) .map(|reply_payload| { let post_details: PostDetailsForFrontend = match reply_payload { @@ -227,7 +225,7 @@ fn when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_re bob_canister_id, Principal::anonymous(), "get_individual_post_details_by_id", - candid::encode_args((0 as u64,)).unwrap(), + candid::encode_args((0_u64,)).unwrap(), ) .map(|reply_payload| { let post_details: PostDetailsForFrontend = match reply_payload { @@ -347,7 +345,7 @@ fn when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_re assert!(alice_post_0.description == "alice post 0 - description"); assert!(alice_post_0.hashtags == vec!["alice-tag-0".to_string(), "alice-tag-1".to_string()]); assert!(alice_post_0.video_uid == "alice-video-0"); - assert!(alice_post_0.creator_consent_for_inclusion_in_hot_or_not == true); + assert!(alice_post_0.creator_consent_for_inclusion_in_hot_or_not); let alice_post_1 = alice_backup_details .canister_data .all_created_posts @@ -356,7 +354,7 @@ fn when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_re assert!(alice_post_1.description == "alice post 1 - description"); assert!(alice_post_1.hashtags == vec!["alice-tag-2".to_string(), "alice-tag-3".to_string()]); assert!(alice_post_1.video_uid == "alice-video-1"); - assert!(alice_post_1.creator_consent_for_inclusion_in_hot_or_not == true); + assert!(alice_post_1.creator_consent_for_inclusion_in_hot_or_not); let token_data = alice_backup_details.canister_data.token_data; assert_eq!(token_data.utility_token_balance, 1500); assert_eq!(token_data.utility_token_transaction_history.len(), 2); @@ -424,7 +422,7 @@ fn when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_re assert!(bob_post_0.description == "bob post 0 - description"); assert!(bob_post_0.hashtags == vec!["bob-tag-0".to_string(), "bob-tag-1".to_string()]); assert!(bob_post_0.video_uid == "bob-video-0"); - assert!(bob_post_0.creator_consent_for_inclusion_in_hot_or_not == true); + assert!(bob_post_0.creator_consent_for_inclusion_in_hot_or_not); let bob_post_1 = bob_backup_details .canister_data .all_created_posts @@ -433,7 +431,7 @@ fn when_backups_are_run_on_all_the_individual_user_canisters_they_capture_all_re assert!(bob_post_1.description == "bob post 1 - description"); assert!(bob_post_1.hashtags == vec!["bob-tag-2".to_string(), "bob-tag-3".to_string()]); assert!(bob_post_1.video_uid == "bob-video-1"); - assert!(bob_post_1.creator_consent_for_inclusion_in_hot_or_not == true); + assert!(bob_post_1.creator_consent_for_inclusion_in_hot_or_not); let token_data = bob_backup_details.canister_data.token_data; assert_eq!(token_data.utility_token_balance, 1500); assert_eq!(token_data.utility_token_transaction_history.len(), 2); diff --git a/src/lib/integration_tests/tests/backup_and_restore/when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_to_backup_canister_and_reinitializing_canister_then_data_restored_successfully_to_individual_user_canister.rs b/src/lib/integration_tests/tests/backup_and_restore/when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_to_backup_canister_and_reinitializing_canister_then_data_restored_successfully_to_individual_user_canister.rs index 45541570..26d54a00 100644 --- a/src/lib/integration_tests/tests/backup_and_restore/when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_to_backup_canister_and_reinitializing_canister_then_data_restored_successfully_to_individual_user_canister.rs +++ b/src/lib/integration_tests/tests/backup_and_restore/when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_to_backup_canister_and_reinitializing_canister_then_data_restored_successfully_to_individual_user_canister.rs @@ -28,14 +28,12 @@ fn when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_ ) { let state_machine = get_new_state_machine(); let known_principal_map = get_initialized_env_with_provisioned_known_canisters(&state_machine); - let user_index_canister_id = known_principal_map + let user_index_canister_id = *known_principal_map .get(&KnownPrincipalType::CanisterIdUserIndex) - .unwrap() - .clone(); - let data_backup_canister_id = known_principal_map + .unwrap(); + let data_backup_canister_id = *known_principal_map .get(&KnownPrincipalType::CanisterIdDataBackup) - .unwrap() - .clone(); + .unwrap(); let alice_principal_id = get_mock_user_alice_principal_id(); let alice_unique_username = "cool_alice_1234".to_string(); let alice_display_name = "Alice".to_string(); @@ -304,7 +302,7 @@ fn when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_ assert!(alice_post_0.description == "alice post 0 - description"); assert!(alice_post_0.hashtags == vec!["alice-tag-0".to_string(), "alice-tag-1".to_string()]); assert!(alice_post_0.video_uid == "alice-video-0"); - assert!(alice_post_0.creator_consent_for_inclusion_in_hot_or_not == true); + assert!(alice_post_0.creator_consent_for_inclusion_in_hot_or_not); let alice_post_1 = alice_backup_details .canister_data .all_created_posts @@ -313,7 +311,7 @@ fn when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_ assert!(alice_post_1.description == "alice post 1 - description"); assert!(alice_post_1.hashtags == vec!["alice-tag-2".to_string(), "alice-tag-3".to_string()]); assert!(alice_post_1.video_uid == "alice-video-1"); - assert!(alice_post_1.creator_consent_for_inclusion_in_hot_or_not == true); + assert!(alice_post_1.creator_consent_for_inclusion_in_hot_or_not); let token_data = alice_backup_details.canister_data.token_data; assert_eq!(token_data.utility_token_balance, 1500); assert_eq!(token_data.utility_token_transaction_history.len(), 2); @@ -373,7 +371,7 @@ fn when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_ alice_canister_id, Principal::anonymous(), "get_posts_of_this_user_profile_with_pagination", - candid::encode_args((0 as u64, 10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let posts_response: Result, GetPostsOfUserProfileError> = @@ -420,7 +418,7 @@ fn when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_ alice_canister_id, Principal::anonymous(), "get_individual_post_details_by_id", - candid::encode_one(0 as u64).unwrap(), + candid::encode_one(0_u64).unwrap(), ) .map(|reply_payload| { let post_details: PostDetailsForFrontend = match reply_payload { @@ -446,7 +444,7 @@ fn when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_ alice_canister_id, Principal::anonymous(), "get_individual_post_details_by_id", - candid::encode_args((1 as u64,)).unwrap(), + candid::encode_args((1_u64,)).unwrap(), ) .map(|reply_payload| { let post_details: PostDetailsForFrontend = match reply_payload { @@ -490,7 +488,7 @@ fn when_restoring_all_data_to_an_individual_user_canister_after_backing_up_data_ alice_canister_id, Principal::anonymous(), "get_user_utility_token_transaction_history_with_pagination", - candid::encode_args((0 as u64, 10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let utility_token_transaction_history: Result< diff --git a/src/lib/integration_tests/tests/cycle_management/when_canister_cycle_balance_is_below_the_configured_or_freezing_threshold_then_running_topup_function_in_user_index_canister_tops_up_the_canisters_that_need_it.rs b/src/lib/integration_tests/tests/cycle_management/when_canister_cycle_balance_is_below_the_configured_or_freezing_threshold_then_running_topup_function_in_user_index_canister_tops_up_the_canisters_that_need_it.rs index f1f103b8..3534482e 100644 --- a/src/lib/integration_tests/tests/cycle_management/when_canister_cycle_balance_is_below_the_configured_or_freezing_threshold_then_running_topup_function_in_user_index_canister_tops_up_the_canisters_that_need_it.rs +++ b/src/lib/integration_tests/tests/cycle_management/when_canister_cycle_balance_is_below_the_configured_or_freezing_threshold_then_running_topup_function_in_user_index_canister_tops_up_the_canisters_that_need_it.rs @@ -62,7 +62,7 @@ fn when_canister_cycle_balance_is_below_the_configured_or_freezing_threshold_the alice_canister_id, *user_index_canister_id, "return_cycles_to_user_index_canister", - candid::encode_one(Some(1_000_000_000_000 as u128)).unwrap(), + candid::encode_one(Some(1_000_000_000_000_u128)).unwrap(), ) .unwrap(); diff --git a/src/lib/integration_tests/tests/feed/when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_feed_and_hot_or_not_feed_scores_match_expected_value.rs b/src/lib/integration_tests/tests/feed/when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_feed_and_hot_or_not_feed_scores_match_expected_value.rs index 9a6edd26..f1b63d04 100644 --- a/src/lib/integration_tests/tests/feed/when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_feed_and_hot_or_not_feed_scores_match_expected_value.rs +++ b/src/lib/integration_tests/tests/feed/when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_feed_and_hot_or_not_feed_scores_match_expected_value.rs @@ -133,7 +133,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -156,7 +156,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -198,7 +198,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -221,7 +221,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -256,14 +256,14 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe }) .unwrap(); - assert_eq!(like_status, true); + assert!(like_status); let returned_posts: Vec = state_machine .query_call( *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -286,7 +286,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -346,7 +346,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -369,7 +369,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -411,7 +411,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -434,7 +434,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -493,7 +493,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -516,7 +516,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -558,7 +558,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -581,7 +581,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -616,14 +616,14 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe }) .unwrap(); - assert_eq!(like_status, true); + assert!(like_status); let returned_posts: Vec = state_machine .query_call( *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -646,7 +646,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -688,7 +688,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -711,7 +711,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -770,7 +770,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -793,7 +793,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -835,7 +835,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -858,7 +858,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -900,7 +900,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_home_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -923,7 +923,7 @@ fn when_bob_charlie_dan_interact_with_alice_created_post_then_calculated_home_fe *post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { diff --git a/src/lib/integration_tests/tests/follow/when_alice_follows_bob_and_bob_follows_charlie_then_all_their_follow_and_following_lists_are_accordingly_updated.rs b/src/lib/integration_tests/tests/follow/when_alice_follows_bob_and_bob_follows_charlie_then_all_their_follow_and_following_lists_are_accordingly_updated.rs index 401d1778..8054e8c4 100644 --- a/src/lib/integration_tests/tests/follow/when_alice_follows_bob_and_bob_follows_charlie_then_all_their_follow_and_following_lists_are_accordingly_updated.rs +++ b/src/lib/integration_tests/tests/follow/when_alice_follows_bob_and_bob_follows_charlie_then_all_their_follow_and_following_lists_are_accordingly_updated.rs @@ -21,10 +21,9 @@ fn when_alice_follows_bob_and_bob_follows_charlie_then_all_their_follow_and_foll ) { let state_machine = get_new_state_machine(); let known_principal_map = get_initialized_env_with_provisioned_known_canisters(&state_machine); - let user_index_canister_id = known_principal_map + let user_index_canister_id = *known_principal_map .get(&KnownPrincipalType::CanisterIdUserIndex) - .unwrap() - .clone(); + .unwrap(); let alice_principal_id = get_mock_user_alice_principal_id(); let bob_principal_id = get_mock_user_bob_principal_id(); let charlie_principal_id = get_mock_user_charlie_principal_id(); @@ -92,7 +91,7 @@ fn when_alice_follows_bob_and_bob_follows_charlie_then_all_their_follow_and_foll }) .unwrap(); - assert_eq!(follow_status, true); + assert!(follow_status); let follow_status = state_machine .query_call( @@ -110,7 +109,7 @@ fn when_alice_follows_bob_and_bob_follows_charlie_then_all_their_follow_and_foll }) .unwrap(); - assert_eq!(follow_status, true); + assert!(follow_status); let followee_arg = FolloweeArg { followee_canister_id: charlie_canister_id, @@ -133,7 +132,7 @@ fn when_alice_follows_bob_and_bob_follows_charlie_then_all_their_follow_and_foll }) .unwrap(); - assert_eq!(follow_status, false); + assert!(!follow_status); // Bob follows Charlie let followee_arg = FolloweeArg { @@ -159,7 +158,7 @@ fn when_alice_follows_bob_and_bob_follows_charlie_then_all_their_follow_and_foll }) .unwrap(); - assert_eq!(follow_status, true); + assert!(follow_status); // Alice's following list should contain Bob let alice_following_list = state_machine diff --git a/src/lib/integration_tests/tests/hot_or_not/when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_occur.rs b/src/lib/integration_tests/tests/hot_or_not/when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_occur.rs index cb2c51de..7d2cf9db 100644 --- a/src/lib/integration_tests/tests/hot_or_not/when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_occur.rs +++ b/src/lib/integration_tests/tests/hot_or_not/when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_occur.rs @@ -35,18 +35,16 @@ use test_utils::setup::{ fn when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_occur() { let state_machine = get_new_state_machine(); let known_principal_map = get_initialized_env_with_provisioned_known_canisters(&state_machine); - let user_index_canister_id = known_principal_map + let user_index_canister_id = *known_principal_map .get(&KnownPrincipalType::CanisterIdUserIndex) - .unwrap() - .clone(); + .unwrap(); println!( "🧪 user_index_canister_id: {:?}", user_index_canister_id.to_text() ); - let post_cache_canister_id = known_principal_map + let post_cache_canister_id = *known_principal_map .get(&KnownPrincipalType::CanisterIdPostCache) - .unwrap() - .clone(); + .unwrap(); println!( "🧪 post_cache_canister_id: {:?}", post_cache_canister_id.to_text() @@ -143,7 +141,7 @@ fn when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_o post_cache_canister_id, Principal::anonymous(), "get_top_posts_aggregated_from_canisters_on_this_network_for_hot_or_not_feed", - candid::encode_args((0 as u64,10 as u64)).unwrap(), + candid::encode_args((0_u64,10_u64)).unwrap(), ) .map(|reply_payload| { let returned_posts: Result, TopPostsFetchError> = match reply_payload { @@ -313,7 +311,7 @@ fn when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_o alice_canister_id, Principal::anonymous(), "get_user_utility_token_transaction_history_with_pagination", - candid::encode_args((0 as u64, 10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let alice_token_transaction_history: Result< @@ -377,7 +375,7 @@ fn when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_o bob_canister_id, Principal::anonymous(), "get_user_utility_token_transaction_history_with_pagination", - candid::encode_args((0 as u64, 10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let bob_token_transaction_history: Result< @@ -459,14 +457,14 @@ fn when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_o .unwrap(); println!("🧪 charlie_token_balance: {}", charlie_token_balance); - assert_eq!(charlie_token_balance, 1000 - 100 + 0); + assert_eq!(charlie_token_balance, 1000 - 100); let charlie_token_transaction_history = state_machine .query_call( charlie_canister_id, Principal::anonymous(), "get_user_utility_token_transaction_history_with_pagination", - candid::encode_args((0 as u64, 10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let charlie_token_transaction_history: Result< @@ -555,7 +553,7 @@ fn when_bob_charlie_dan_place_bet_on_alice_created_post_then_expected_outcomes_o dan_canister_id, Principal::anonymous(), "get_user_utility_token_transaction_history_with_pagination", - candid::encode_args((0 as u64, 10 as u64)).unwrap(), + candid::encode_args((0_u64, 10_u64)).unwrap(), ) .map(|reply_payload| { let dan_token_transaction_history: Result< diff --git a/src/lib/integration_tests/tests/profile/when_setting_unique_username_then_new_username_persisted_in_personal_canister_and_updated_in_user_index.rs b/src/lib/integration_tests/tests/profile/when_setting_unique_username_then_new_username_persisted_in_personal_canister_and_updated_in_user_index.rs index f54d162f..a4231b89 100644 --- a/src/lib/integration_tests/tests/profile/when_setting_unique_username_then_new_username_persisted_in_personal_canister_and_updated_in_user_index.rs +++ b/src/lib/integration_tests/tests/profile/when_setting_unique_username_then_new_username_persisted_in_personal_canister_and_updated_in_user_index.rs @@ -79,7 +79,7 @@ fn when_setting_unique_username_then_new_username_persisted_in_personal_canister }) .unwrap(); - assert_eq!(is_alice_username_taken, true); + assert!(is_alice_username_taken); println!( "🧪 profile_details_from_user_canister: {:?}", diff --git a/src/lib/integration_tests/tests/upgrade/on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_canisters.rs b/src/lib/integration_tests/tests/upgrade/on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_canisters.rs index bd754baa..cc9f4a43 100644 --- a/src/lib/integration_tests/tests/upgrade/on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_canisters.rs +++ b/src/lib/integration_tests/tests/upgrade/on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_canisters.rs @@ -90,10 +90,9 @@ fn on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_ca }; canister_installer( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdConfiguration) - .unwrap() - .clone(), + .unwrap(), get_canister_wasm(KnownPrincipalType::CanisterIdConfiguration), candid::encode_one(ConfigurationInitArgs { known_principal_ids: Some(known_principal_map_with_all_canisters.clone()), @@ -110,16 +109,14 @@ fn on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_ca ); incomplete_known_principal_map.insert( KnownPrincipalType::CanisterIdConfiguration, - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdConfiguration) - .unwrap() - .clone(), + .unwrap(), ); canister_installer( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdConfiguration) - .unwrap() - .clone(), + .unwrap(), get_canister_wasm(KnownPrincipalType::CanisterIdConfiguration), candid::encode_one(ConfigurationInitArgs { known_principal_ids: Some(incomplete_known_principal_map.clone()), @@ -131,10 +128,9 @@ fn on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_ca let user_index_canister_id_from_configuration_canister: Option = state_machine .query_call( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdConfiguration) - .unwrap() - .clone(), + .unwrap(), Principal::anonymous(), "get_well_known_principal_value", candid::encode_one(KnownPrincipalType::CanisterIdUserIndex).unwrap(), @@ -152,10 +148,9 @@ fn on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_ca assert!(user_index_canister_id_from_configuration_canister.is_some()); canister_installer( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdDataBackup) - .unwrap() - .clone(), + .unwrap(), get_canister_wasm(KnownPrincipalType::CanisterIdDataBackup), candid::encode_one(DataBackupInitArgs { known_principal_ids: Some(incomplete_known_principal_map.clone()), @@ -167,10 +162,9 @@ fn on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_ca let user_index_canister_id_from_data_backup_canister: Option = state_machine .query_call( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdDataBackup) - .unwrap() - .clone(), + .unwrap(), Principal::anonymous(), "get_well_known_principal_value", candid::encode_one(KnownPrincipalType::CanisterIdUserIndex).unwrap(), @@ -191,10 +185,9 @@ fn on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_ca // * Upgrade data backup canister state_machine .upgrade_canister( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdDataBackup) - .unwrap() - .clone(), + .unwrap(), get_canister_wasm(KnownPrincipalType::CanisterIdDataBackup), candid::encode_one(DataBackupInitArgs { ..Default::default() @@ -209,10 +202,9 @@ fn on_every_upgrade_fetch_the_latest_list_of_well_known_principals_and_update_ca let user_index_canister_id_from_data_backup_canister: Option = state_machine .query_call( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdDataBackup) - .unwrap() - .clone(), + .unwrap(), Principal::anonymous(), "get_well_known_principal_value", candid::encode_one(KnownPrincipalType::CanisterIdUserIndex).unwrap(), diff --git a/src/lib/shared_utils/src/access_control.rs b/src/lib/shared_utils/src/access_control.rs index f3726495..9e5d054e 100644 --- a/src/lib/shared_utils/src/access_control.rs +++ b/src/lib/shared_utils/src/access_control.rs @@ -100,7 +100,7 @@ mod test { UserAccessRole::CanisterAdmin, user_id, ); - assert_eq!(result, true); + assert!(result); } #[test] diff --git a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/arg.rs b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/arg.rs index bbcd3bea..8a7b356c 100644 --- a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/arg.rs +++ b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/arg.rs @@ -9,16 +9,7 @@ pub struct IndividualUserTemplateInitArgs { pub known_principal_ids: Option, pub profile_owner: Option, pub upgrade_version_number: Option, -} - -impl IndividualUserTemplateInitArgs { - pub fn new(profile_owner: Principal) -> Self { - Self { - known_principal_ids: Some(KnownPrincipalMap::default()), - profile_owner: Some(profile_owner), - upgrade_version_number: Some(0), - } - } + pub url_to_send_canister_metrics_to: Option, } #[derive(Deserialize, CandidType, Clone)] diff --git a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/configuration.rs b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/configuration.rs new file mode 100644 index 00000000..ddbc06ae --- /dev/null +++ b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/configuration.rs @@ -0,0 +1,6 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Default, Deserialize, Serialize)] +pub struct IndividualUserConfiguration { + pub url_to_send_canister_metrics_to: Option, +} diff --git a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/follow/mod.rs b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/follow/mod.rs index 09fc14cb..fe9271fa 100644 --- a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/follow/mod.rs +++ b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/follow/mod.rs @@ -47,6 +47,10 @@ impl FollowList { pub fn len(&self) -> usize { self.members.len() } + + pub fn is_empty(&self) -> bool { + self.members.is_empty() + } } pub type FollowEntryId = u64; @@ -69,15 +73,15 @@ mod test { let mut follow_list = FollowList::default(); let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), - canister_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), + principal_id: Principal::self_authenticating((0u64).to_ne_bytes()), + canister_id: Principal::self_authenticating((0u64).to_ne_bytes()), }; let follow_entry_id = follow_list.add(follow_entry_detail.clone()); assert_eq!(follow_entry_id, 0); assert_eq!(follow_list.len(), 1); - assert_eq!(follow_list.contains(&follow_entry_detail), true); + assert!(follow_list.contains(&follow_entry_detail)); } #[test] @@ -85,21 +89,21 @@ mod test { let mut follow_list = FollowList::default(); let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), - canister_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), + principal_id: Principal::self_authenticating((0u64).to_ne_bytes()), + canister_id: Principal::self_authenticating((0u64).to_ne_bytes()), }; let follow_entry_id = follow_list.add(follow_entry_detail.clone()); assert_eq!(follow_entry_id, 0); assert_eq!(follow_list.len(), 1); - assert_eq!(follow_list.contains(&follow_entry_detail), true); + assert!(follow_list.contains(&follow_entry_detail)); let follow_entry_id = follow_list.remove(&follow_entry_detail); assert_eq!(follow_entry_id, Some(0)); assert_eq!(follow_list.len(), 0); - assert_eq!(follow_list.contains(&follow_entry_detail), false); + assert!(!follow_list.contains(&follow_entry_detail)); } #[test] @@ -107,27 +111,27 @@ mod test { let mut follow_list = FollowList::default(); let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), - canister_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), + principal_id: Principal::self_authenticating((0u64).to_ne_bytes()), + canister_id: Principal::self_authenticating((0u64).to_ne_bytes()), }; let follow_entry_id = follow_list.add(follow_entry_detail.clone()); assert_eq!(follow_entry_id, 0); assert_eq!(follow_list.len(), 1); - assert_eq!(follow_list.contains(&follow_entry_detail), true); + assert!(follow_list.contains(&follow_entry_detail)); let follow_entry_id = follow_list.remove(&follow_entry_detail); assert_eq!(follow_entry_id, Some(0)); assert_eq!(follow_list.len(), 0); - assert_eq!(follow_list.contains(&follow_entry_detail), false); + assert!(!follow_list.contains(&follow_entry_detail)); let follow_entry_id = follow_list.add(follow_entry_detail.clone()); assert_eq!(follow_entry_id, 0); assert_eq!(follow_list.len(), 1); - assert_eq!(follow_list.contains(&follow_entry_detail), true); + assert!(follow_list.contains(&follow_entry_detail)); } #[test] @@ -135,22 +139,22 @@ mod test { let mut follow_list = FollowList::default(); let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), - canister_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), + principal_id: Principal::self_authenticating((0u64).to_ne_bytes()), + canister_id: Principal::self_authenticating((0u64).to_ne_bytes()), }; let follow_entry_id = follow_list.add(follow_entry_detail.clone()); assert_eq!(follow_entry_id, 0); assert_eq!(follow_list.len(), 1); - assert_eq!(follow_list.contains(&follow_entry_detail), true); + assert!(follow_list.contains(&follow_entry_detail)); let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&(1u64).to_ne_bytes()), - canister_id: Principal::self_authenticating(&(1u64).to_ne_bytes()), + principal_id: Principal::self_authenticating((1u64).to_ne_bytes()), + canister_id: Principal::self_authenticating((1u64).to_ne_bytes()), }; - assert_eq!(follow_list.contains(&follow_entry_detail), false); + assert!(!follow_list.contains(&follow_entry_detail)); } #[test] @@ -158,26 +162,26 @@ mod test { let mut follow_list = FollowList::default(); let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), - canister_id: Principal::self_authenticating(&(0u64).to_ne_bytes()), + principal_id: Principal::self_authenticating((0u64).to_ne_bytes()), + canister_id: Principal::self_authenticating((0u64).to_ne_bytes()), }; let follow_entry_id = follow_list.add(follow_entry_detail.clone()); assert_eq!(follow_entry_id, 0); assert_eq!(follow_list.len(), 1); - assert_eq!(follow_list.contains(&follow_entry_detail), true); + assert!(follow_list.contains(&follow_entry_detail)); let follow_entry_detail = FollowEntryDetail { - principal_id: Principal::self_authenticating(&(1u64).to_ne_bytes()), - canister_id: Principal::self_authenticating(&(1u64).to_ne_bytes()), + principal_id: Principal::self_authenticating((1u64).to_ne_bytes()), + canister_id: Principal::self_authenticating((1u64).to_ne_bytes()), }; let follow_entry_id = follow_list.add(follow_entry_detail.clone()); assert_eq!(follow_entry_id, 1); assert_eq!(follow_list.len(), 2); - assert_eq!(follow_list.contains(&follow_entry_detail), true); + assert!(follow_list.contains(&follow_entry_detail)); } } } diff --git a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/hot_or_not/mod.rs b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/hot_or_not/mod.rs index f352fbea..02e2e334 100644 --- a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/hot_or_not/mod.rs +++ b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/hot_or_not/mod.rs @@ -190,7 +190,7 @@ impl Post { started_at, number_of_participants, ongoing_slot: currently_ongoing_slot, - ongoing_room: *currently_active_room.0 as u64, + ongoing_room: *currently_active_room.0, has_this_user_participated_in_this_post: if *bet_maker_principal_id == Principal::anonymous() { @@ -217,11 +217,9 @@ impl Post { .as_ref() .unwrap() .slot_history - .iter() - .map(|(_, slot_details)| slot_details.room_details.iter()) - .flatten() - .map(|(_, room_details)| room_details.bets_made.iter()) - .flatten() + .values() + .flat_map(|slot_details| slot_details.room_details.iter()) + .flat_map(|(_, room_details)| room_details.bets_made.iter()) .any(|(principal, _)| principal == principal_making_bet) } @@ -268,7 +266,7 @@ impl Post { // * Update bets_made currently if bets_made_currently.len() < 100 { bets_made_currently.insert( - bet_maker_principal_id.clone(), + *bet_maker_principal_id, BetDetails { amount: bet_amount, bet_direction: bet_direction.clone(), @@ -281,7 +279,7 @@ impl Post { let new_room_number = ongoing_room + 1; let mut bets_made = BTreeMap::default(); bets_made.insert( - bet_maker_principal_id.clone(), + *bet_maker_principal_id, BetDetails { amount: bet_amount, bet_direction: bet_direction.clone(), @@ -370,9 +368,8 @@ impl Post { .unwrap() .room_details .iter_mut() - .for_each(|(room_id, room_detail)| match room_detail.bet_outcome { - // * Only tabulate scores for room if already not tabulated - RoomBetPossibleOutcomes::BetOngoing => { + .for_each(|(room_id, room_detail)| { + if room_detail.bet_outcome == RoomBetPossibleOutcomes::BetOngoing { // * Figure out which side won match room_detail.total_hot_bets.cmp(&room_detail.total_not_bets) { Ordering::Greater => { @@ -442,7 +439,6 @@ impl Post { }; }); } - _ => {} }) } } @@ -688,7 +684,7 @@ mod test { let result = post.has_this_principal_already_bet_on_this_post(&get_mock_user_alice_principal_id()); - assert_eq!(result, false); + assert!(!result); post.place_hot_or_not_bet( &get_mock_user_alice_principal_id(), @@ -702,7 +698,7 @@ mod test { let result = post.has_this_principal_already_bet_on_this_post(&get_mock_user_alice_principal_id()); - assert_eq!(result, true); + assert!(result); } #[test] @@ -900,8 +896,8 @@ mod test { .iter() .for_each(|(user_id, bet_direction, bet_amount, _)| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&user_id.to_ne_bytes()), - &Principal::self_authenticating(&user_id.to_ne_bytes()), + &Principal::self_authenticating(user_id.to_ne_bytes()), + &Principal::self_authenticating(user_id.to_ne_bytes()), *bet_amount, bet_direction, &post_creation_time, @@ -944,7 +940,7 @@ mod test { .for_each(|(user_id, bet_direction, bet_amount, amount_won)| { let bet_detail = room_detail .bets_made - .get(&Principal::self_authenticating(&user_id.to_ne_bytes())) + .get(&Principal::self_authenticating(user_id.to_ne_bytes())) .unwrap(); assert_eq!(bet_detail.bet_direction, *bet_direction); @@ -1049,8 +1045,8 @@ mod test { .iter() .for_each(|(user_id, bet_direction, bet_amount, _)| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(user_id + 75).to_ne_bytes()), - &Principal::self_authenticating(&(user_id + 75).to_ne_bytes()), + &Principal::self_authenticating((user_id + 75).to_ne_bytes()), + &Principal::self_authenticating((user_id + 75).to_ne_bytes()), *bet_amount, bet_direction, &post_creation_time, @@ -1094,7 +1090,7 @@ mod test { let bet_detail = room_detail .bets_made .get(&Principal::self_authenticating( - &(user_id + 75).to_ne_bytes(), + (user_id + 75).to_ne_bytes(), )) .unwrap(); @@ -1288,8 +1284,8 @@ mod test { .iter() .for_each(|(user_id, bet_direction, bet_amount, _)| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&user_id.to_ne_bytes()), - &Principal::self_authenticating(&user_id.to_ne_bytes()), + &Principal::self_authenticating(user_id.to_ne_bytes()), + &Principal::self_authenticating(user_id.to_ne_bytes()), *bet_amount, bet_direction, &post_creation_time, @@ -1333,7 +1329,7 @@ mod test { .for_each(|(user_id, bet_direction, bet_amount, amount_won)| { let bet_detail = room_detail .bets_made - .get(&Principal::self_authenticating(&user_id.to_ne_bytes())) + .get(&Principal::self_authenticating(user_id.to_ne_bytes())) .unwrap(); assert_eq!(bet_detail.bet_direction, *bet_direction); @@ -1373,7 +1369,7 @@ mod test { .for_each(|(user_id, bet_direction, bet_amount, amount_won)| { let bet_detail = room_detail .bets_made - .get(&Principal::self_authenticating(&user_id.to_ne_bytes())) + .get(&Principal::self_authenticating(user_id.to_ne_bytes())) .unwrap(); assert_eq!(bet_detail.bet_direction, *bet_direction); @@ -1496,8 +1492,8 @@ mod test { .iter() .for_each(|(user_id, bet_direction, bet_amount, _)| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&user_id.to_ne_bytes()), - &Principal::self_authenticating(&user_id.to_ne_bytes()), + &Principal::self_authenticating(user_id.to_ne_bytes()), + &Principal::self_authenticating(user_id.to_ne_bytes()), *bet_amount, bet_direction, &post_creation_time, @@ -1540,7 +1536,7 @@ mod test { .for_each(|(user_id, bet_direction, bet_amount, amount_won)| { let bet_detail = room_detail .bets_made - .get(&Principal::self_authenticating(&user_id.to_ne_bytes())) + .get(&Principal::self_authenticating(user_id.to_ne_bytes())) .unwrap(); assert_eq!(bet_detail.bet_direction, *bet_direction); diff --git a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/mod.rs b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/mod.rs index a0301d58..8de7f8f8 100644 --- a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/mod.rs +++ b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/mod.rs @@ -1,4 +1,5 @@ pub mod arg; +pub mod configuration; pub mod error; pub mod follow; pub mod hot_or_not; diff --git a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/post/mod.rs b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/post/mod.rs index bc9869ce..457bc9f8 100644 --- a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/post/mod.rs +++ b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/post/mod.rs @@ -185,7 +185,7 @@ impl Post { hashtags: (*post_details_from_frontend.hashtags).to_vec(), video_uid: (*post_details_from_frontend.video_uid).to_string(), status: PostStatus::Uploaded, - created_at: current_time.clone(), + created_at: *current_time, likes: HashSet::new(), share_count: 0, view_stats: PostViewStatistics { @@ -213,12 +213,8 @@ impl Post { let current_total_dividend = earlier_sum_component + current_full_view_component + percentage_watched as u64; let current_total_divisor = self.view_stats.total_view_count + full_view_count as u64 + 1; - let recalculated_average = (current_total_dividend / current_total_divisor) as u8; - // ic_cdk::print(std::format!( - // "🥫 recalculated_average: {}", - // recalculated_average - // )); - recalculated_average + + (current_total_dividend / current_total_divisor) as u8 } pub fn recalculate_home_feed_score(&mut self, current_time: &SystemTime) { @@ -382,10 +378,10 @@ impl Post { // if liked, return true & if unliked, return false if self.likes.contains(user_principal_id) { self.likes.remove(user_principal_id); - return false; + false } else { - self.likes.insert(user_principal_id.clone()); - return true; + self.likes.insert(*user_principal_id); + true } } @@ -461,8 +457,8 @@ mod test { (0..80).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -480,8 +476,8 @@ mod test { (80..145).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -536,8 +532,8 @@ mod test { (0..216).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -555,8 +551,8 @@ mod test { (216..360).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -611,8 +607,8 @@ mod test { (0..1_078).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -633,8 +629,8 @@ mod test { (1_078..2_695).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -681,7 +677,7 @@ mod test { post.view_stats.total_view_count = 15_000; (0..1_200).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 1_200); @@ -691,8 +687,8 @@ mod test { (0..4_725).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -713,8 +709,8 @@ mod test { (4_725..10_500).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -761,7 +757,7 @@ mod test { post.view_stats.total_view_count = 75_000; (0..3_000).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 3_000); @@ -771,8 +767,8 @@ mod test { (0..26_827).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -793,8 +789,8 @@ mod test { (26_827..54_750).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -841,7 +837,7 @@ mod test { post.view_stats.total_view_count = 150; (0..3).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 3); @@ -851,8 +847,8 @@ mod test { (0..18).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -873,8 +869,8 @@ mod test { (18..45).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -921,7 +917,7 @@ mod test { post.view_stats.total_view_count = 400; (0..4).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 4); @@ -931,8 +927,8 @@ mod test { (0..40).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -953,8 +949,8 @@ mod test { (40..68).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1001,7 +997,7 @@ mod test { post.view_stats.total_view_count = 3_500; (0..35).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 35); @@ -1011,8 +1007,8 @@ mod test { (0..466).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1033,8 +1029,8 @@ mod test { (466..805).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1081,7 +1077,7 @@ mod test { post.view_stats.total_view_count = 15_000; (0..600).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 600); @@ -1091,8 +1087,8 @@ mod test { (0..1_320).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1113,8 +1109,8 @@ mod test { (1_320..2_400).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1161,7 +1157,7 @@ mod test { post.view_stats.total_view_count = 75_000; (0..750).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 750); @@ -1171,8 +1167,8 @@ mod test { (0..6_270).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1193,8 +1189,8 @@ mod test { (6_270..14_250).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1249,8 +1245,8 @@ mod test { (0..80).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1268,8 +1264,8 @@ mod test { (80..145).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1338,8 +1334,8 @@ mod test { (0..216).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1357,8 +1353,8 @@ mod test { (216..360).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1427,8 +1423,8 @@ mod test { (0..1_078).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1449,8 +1445,8 @@ mod test { (1_078..2_695).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1511,7 +1507,7 @@ mod test { post.view_stats.total_view_count = 15_000; (0..1_200).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 1_200); @@ -1521,8 +1517,8 @@ mod test { (0..4_725).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1543,8 +1539,8 @@ mod test { (4_725..10_500).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1605,7 +1601,7 @@ mod test { post.view_stats.total_view_count = 75_000; (0..3_000).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 3_000); @@ -1615,8 +1611,8 @@ mod test { (0..26_827).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1637,8 +1633,8 @@ mod test { (26_827..54_750).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1699,7 +1695,7 @@ mod test { post.view_stats.total_view_count = 150; (0..3).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 3); @@ -1709,8 +1705,8 @@ mod test { (0..18).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1731,8 +1727,8 @@ mod test { (18..45).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1793,7 +1789,7 @@ mod test { post.view_stats.total_view_count = 400; (0..4).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 4); @@ -1803,8 +1799,8 @@ mod test { (0..40).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1825,8 +1821,8 @@ mod test { (40..68).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1887,7 +1883,7 @@ mod test { post.view_stats.total_view_count = 3_500; (0..35).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 35); @@ -1897,8 +1893,8 @@ mod test { (0..466).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -1919,8 +1915,8 @@ mod test { (466..805).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -1981,7 +1977,7 @@ mod test { post.view_stats.total_view_count = 15_000; (0..600).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 600); @@ -1991,8 +1987,8 @@ mod test { (0..1_320).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -2013,8 +2009,8 @@ mod test { (1_320..2_400).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, @@ -2075,7 +2071,7 @@ mod test { post.view_stats.total_view_count = 75_000; (0..750).for_each(|number| { post.likes.insert(Principal::self_authenticating( - &(number as usize).to_ne_bytes(), + (number as usize).to_ne_bytes(), )); }); assert_eq!(post.likes.len(), 750); @@ -2085,8 +2081,8 @@ mod test { (0..6_270).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Hot, &betting_time, @@ -2107,8 +2103,8 @@ mod test { (6_270..14_250).for_each(|number| { let result = post.place_hot_or_not_bet( - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), - &Principal::self_authenticating(&(number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), + &Principal::self_authenticating((number as usize).to_ne_bytes()), 100, &BetDirection::Not, &betting_time, diff --git a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/token.rs b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/token.rs index 158fa6fc..47cbef01 100644 --- a/src/lib/shared_utils/src/canister_specific/individual_user_template/types/token.rs +++ b/src/lib/shared_utils/src/canister_specific/individual_user_template/types/token.rs @@ -58,7 +58,7 @@ impl TokenBalance { } => { self.utility_token_balance += winnings_amount; self.lifetime_earnings += - get_earnings_amount_from_winnings_amount(&winnings_amount); + get_earnings_amount_from_winnings_amount(winnings_amount); } }, } @@ -83,8 +83,7 @@ fn get_earnings_amount_from_winnings_amount(winnings_amount: &u64) -> u64 { let comission_subtracted_bet_amount = winnings_amount / HOT_OR_NOT_BET_WINNINGS_MULTIPLIER; let bet_amount = comission_subtracted_bet_amount * 100 / (100 - HOT_OR_NOT_BET_CREATOR_COMMISSION_PERCENTAGE); - let earnings = winnings_amount - bet_amount; - return earnings; + winnings_amount - bet_amount } #[cfg(test)] diff --git a/src/lib/shared_utils/src/common/mod.rs b/src/lib/shared_utils/src/common/mod.rs index e4bd745f..5b907739 100644 --- a/src/lib/shared_utils/src/common/mod.rs +++ b/src/lib/shared_utils/src/common/mod.rs @@ -1,3 +1,4 @@ pub mod environment; +pub mod timer; pub mod types; pub mod utils; diff --git a/src/lib/shared_utils/src/common/timer/mod.rs b/src/lib/shared_utils/src/common/timer/mod.rs new file mode 100644 index 00000000..1cd723ff --- /dev/null +++ b/src/lib/shared_utils/src/common/timer/mod.rs @@ -0,0 +1 @@ +pub mod send_metrics; diff --git a/src/lib/shared_utils/src/common/timer/send_metrics.rs b/src/lib/shared_utils/src/common/timer/send_metrics.rs new file mode 100644 index 00000000..35ab77a0 --- /dev/null +++ b/src/lib/shared_utils/src/common/timer/send_metrics.rs @@ -0,0 +1,73 @@ +use std::time::Duration; + +use candid::Principal; +use ic_cdk::api::management_canister::{ + http_request::{self, CanisterHttpRequestArgument, HttpMethod}, + main, + provisional::CanisterIdRecord, +}; +use rmp_serde::encode; +use serde::Serialize; + +// Send metrics every 6 hours +const PING_INTERVAL_FOR_CALLING_METRICS_REST_API: Duration = Duration::from_secs(60 * 60 * 6); + +pub fn enqueue_timer_for_calling_metrics_rest_api(url_to_ping: String) { + ic_cdk_timers::set_timer_interval(PING_INTERVAL_FOR_CALLING_METRICS_REST_API, move || { + ic_cdk::spawn(ping_metrics_rest_api(url_to_ping.clone())) + }); +} + +async fn ping_metrics_rest_api(url_to_ping: String) { + let status = get_my_canister_cycle_balance_and_memory_usage().await; + + let request_arg = CanisterHttpRequestArgument { + url: url_to_ping, + max_response_bytes: Some(0), + method: HttpMethod::POST, + body: Some(encode::to_vec(&status).expect("Failed to serialize status")), + ..Default::default() + }; + + http_request::http_request(request_arg) + .await + .expect("Failed to ping"); +} + +#[derive(Serialize)] +pub struct CanisterStatus { + pub canister_id: Principal, + cycle_balance: i64, + idle_cycles_burned_per_day: i64, + memory_size: i64, +} + +#[derive(Serialize)] +pub struct CanisterStatusError { + pub canister_id: Principal, + pub error_message: String, +} + +pub async fn get_my_canister_cycle_balance_and_memory_usage( +) -> Result { + let canister_id = ic_cdk::id(); + + let canister_status_result = main::canister_status(CanisterIdRecord { canister_id }) + .await + .map_err(|err| CanisterStatusError { + canister_id: ic_cdk::id(), + error_message: err.1, + })? + .0; + + Ok(CanisterStatus { + canister_id, + cycle_balance: canister_status_result.cycles.0.try_into().unwrap(), + memory_size: canister_status_result.memory_size.0.try_into().unwrap(), + idle_cycles_burned_per_day: canister_status_result + .idle_cycles_burned_per_day + .0 + .try_into() + .unwrap(), + }) +} diff --git a/src/lib/shared_utils/src/common/types/utility_token/token_event.rs b/src/lib/shared_utils/src/common/types/utility_token/token_event.rs index b7cf7fe9..1b2cc241 100644 --- a/src/lib/shared_utils/src/common/types/utility_token/token_event.rs +++ b/src/lib/shared_utils/src/common/types/utility_token/token_event.rs @@ -29,7 +29,7 @@ pub enum TokenEvent { } impl TokenEvent { - pub fn get_token_amount_for_token_event(self: &Self) -> u64 { + pub fn get_token_amount_for_token_event(&self) -> u64 { match self { TokenEvent::Mint { details, .. } => match details { MintEvent::NewUserSignup { .. } => 1000, diff --git a/src/lib/shared_utils/src/common/utils/stable_memory_serializer_deserializer.rs b/src/lib/shared_utils/src/common/utils/stable_memory_serializer_deserializer.rs index 95ee6b3c..11a9f14e 100644 --- a/src/lib/shared_utils/src/common/utils/stable_memory_serializer_deserializer.rs +++ b/src/lib/shared_utils/src/common/utils/stable_memory_serializer_deserializer.rs @@ -1,10 +1,10 @@ -use ic_cdk::api::stable::{BufferedStableReader, BufferedStableWriter, WASM_PAGE_SIZE_IN_BYTES}; +use ic_cdk::api::stable::{BufferedStableReader, BufferedStableWriter}; use serde::{de::DeserializeOwned, Serialize}; use std::cmp::min; use std::error::Error; use std::io::{Read, Write}; -// * const WASM_PAGE_SIZE_BYTES: usize = 64 * 1024; // 64KB +const WASM_PAGE_SIZE_IN_BYTES: usize = 64 * 1024; // 64KB pub fn serialize_to_stable_memory( state: S, diff --git a/src/lib/shared_utils/src/constant.rs b/src/lib/shared_utils/src/constant.rs index 59f0fd0f..97000390 100644 --- a/src/lib/shared_utils/src/constant.rs +++ b/src/lib/shared_utils/src/constant.rs @@ -19,9 +19,8 @@ pub fn get_global_super_admin_principal_id_v1( Principal::from_text("7gaq2-4kttl-vtbt4-oo47w-igteo-cpk2k-57h3p-yioqe-wkawi-wz45g-jae") .unwrap() } - _ => well_known_canisters + _ => *well_known_canisters .get(&KnownPrincipalType::UserIdGlobalSuperAdmin) - .expect("USER ID for global super admin not found") - .clone(), + .expect("USER ID for global super admin not found"), } } diff --git a/src/lib/test_utils/src/setup/env/v1.rs b/src/lib/test_utils/src/setup/env/v1.rs index 287ee8c9..d9565457 100644 --- a/src/lib/test_utils/src/setup/env/v1.rs +++ b/src/lib/test_utils/src/setup/env/v1.rs @@ -100,10 +100,9 @@ pub fn get_initialized_env_with_provisioned_known_canisters( }; canister_installer( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdConfiguration) - .unwrap() - .clone(), + .unwrap(), get_canister_wasm(KnownPrincipalType::CanisterIdConfiguration), candid::encode_one(ConfigurationInitArgs { known_principal_ids: Some(known_principal_map_with_all_canisters.clone()), @@ -112,10 +111,9 @@ pub fn get_initialized_env_with_provisioned_known_canisters( .unwrap(), ); canister_installer( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdDataBackup) - .unwrap() - .clone(), + .unwrap(), get_canister_wasm(KnownPrincipalType::CanisterIdDataBackup), candid::encode_one(DataBackupInitArgs { known_principal_ids: Some(known_principal_map_with_all_canisters.clone()), @@ -124,10 +122,9 @@ pub fn get_initialized_env_with_provisioned_known_canisters( .unwrap(), ); canister_installer( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdPostCache) - .unwrap() - .clone(), + .unwrap(), get_canister_wasm(KnownPrincipalType::CanisterIdPostCache), candid::encode_one(PostCacheInitArgs { known_principal_ids: Some(known_principal_map_with_all_canisters.clone()), @@ -145,15 +142,13 @@ pub fn get_initialized_env_with_provisioned_known_canisters( ); canister_installer( - known_principal_map_with_all_canisters + *known_principal_map_with_all_canisters .get(&KnownPrincipalType::CanisterIdUserIndex) - .unwrap() - .clone(), + .unwrap(), get_canister_wasm(KnownPrincipalType::CanisterIdUserIndex), candid::encode_one(UserIndexInitArgs { known_principal_ids: Some(known_principal_map_with_all_canisters.clone()), access_control_map: Some(user_index_access_control_map), - ..Default::default() }) .unwrap(), ); @@ -165,8 +160,7 @@ pub fn get_canister_id_of_specific_type_from_principal_id_map( principal_id_map: &KnownPrincipalMap, canister_type: KnownPrincipalType, ) -> Principal { - principal_id_map + *principal_id_map .get(&canister_type) .expect("Canister type not found in principal id map") - .clone() } diff --git a/src/lib/test_utils/src/setup/test_constants/mod.rs b/src/lib/test_utils/src/setup/test_constants/mod.rs index e4b067b2..5db1016e 100644 --- a/src/lib/test_utils/src/setup/test_constants/mod.rs +++ b/src/lib/test_utils/src/setup/test_constants/mod.rs @@ -6,67 +6,67 @@ use std::{fs::File, io::Read, path::PathBuf}; pub mod v1; pub fn get_global_super_admin_principal_id_v1() -> Principal { - Principal::self_authenticating(&[0]) + Principal::self_authenticating([0]) } pub fn get_mock_user_alice_principal_id() -> Principal { - Principal::self_authenticating(&[1]) + Principal::self_authenticating([1]) } pub fn get_mock_user_bob_principal_id() -> Principal { - Principal::self_authenticating(&[2]) + Principal::self_authenticating([2]) } pub fn get_mock_user_charlie_principal_id() -> Principal { - Principal::self_authenticating(&[3]) + Principal::self_authenticating([3]) } pub fn get_mock_user_dan_principal_id() -> Principal { - Principal::self_authenticating(&[4]) + Principal::self_authenticating([4]) } pub fn get_mock_canister_id_post_cache() -> Principal { - CanisterId::from_slice(&(0 as usize).to_ne_bytes()) + CanisterId::from_slice(&0_usize.to_ne_bytes()) } pub fn get_mock_canister_id_root() -> Principal { - CanisterId::from_slice(&(2 as usize).to_ne_bytes()) + CanisterId::from_slice(&2_usize.to_ne_bytes()) } pub fn get_mock_canister_id_sns() -> Principal { - CanisterId::from_slice(&(3 as usize).to_ne_bytes()) + CanisterId::from_slice(&3_usize.to_ne_bytes()) } pub fn get_mock_canister_id_topic_cache() -> Principal { - CanisterId::from_slice(&(4 as usize).to_ne_bytes()) + CanisterId::from_slice(&4_usize.to_ne_bytes()) } pub fn get_mock_canister_id_user_index() -> Principal { - CanisterId::from_slice(&(5 as usize).to_ne_bytes()) + CanisterId::from_slice(&5_usize.to_ne_bytes()) } pub fn get_mock_canister_id_configuration() -> Principal { - CanisterId::from_slice(&(6 as usize).to_ne_bytes()) + CanisterId::from_slice(&6_usize.to_ne_bytes()) } pub fn get_mock_canister_id_data_backup() -> Principal { - CanisterId::from_slice(&(7 as usize).to_ne_bytes()) + CanisterId::from_slice(&7_usize.to_ne_bytes()) } pub fn get_mock_user_alice_canister_id() -> Principal { - CanisterId::from_slice(&(8 as usize).to_ne_bytes()) + CanisterId::from_slice(&8_usize.to_ne_bytes()) } pub fn get_mock_user_bob_canister_id() -> Principal { - CanisterId::from_slice(&(9 as usize).to_ne_bytes()) + CanisterId::from_slice(&9_usize.to_ne_bytes()) } pub fn get_mock_user_charlie_canister_id() -> Principal { - CanisterId::from_slice(&(10 as usize).to_ne_bytes()) + CanisterId::from_slice(&10_usize.to_ne_bytes()) } pub fn get_mock_user_dan_canister_id() -> Principal { - CanisterId::from_slice(&(11 as usize).to_ne_bytes()) + CanisterId::from_slice(&11_usize.to_ne_bytes()) } pub fn get_user_index_canister_wasm() -> Vec { diff --git a/talking_points.md b/talking_points.md deleted file mode 100644 index 606e536e..00000000 --- a/talking_points.md +++ /dev/null @@ -1,15 +0,0 @@ -# IC side - -- Only 10% of hardware capacity is currently being used -- Hardware capability increase over time, cost for executing same number of instructions decrease over time which is equivalent to cycles -- Optimizations and savings from improvements in the base protocol - -# Canister side - -- Migration to stable memory - accounts for 50% of our current costs - - Delay this for as long as possible - - Already burned once, wasted 2-3 months on moving from stable to heap - - ic-stable-structures - still has breaking bugs moving between minor versions (e.g. v0.3 - v0.4) - - Schema changes are very easy for heap, but complicated for stable - - Have to declare size of entries up front which won't work in our case. Dynamic allocator absent -- Recycle dead/inactive canisters