From ea8d244a6dde5a53263ecb49d6716c9d3828a7d2 Mon Sep 17 00:00:00 2001 From: marvincd Date: Tue, 25 Mar 2025 02:05:15 +0100 Subject: [PATCH 1/5] added a v1 for infinite slots functions need for proper increment in entry fees --- .../src/tournaments/helper_functions.rs | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/game_bloc_backend/src/tournaments/helper_functions.rs b/game_bloc_backend/src/tournaments/helper_functions.rs index 48224525..9bbdd7cb 100644 --- a/game_bloc_backend/src/tournaments/helper_functions.rs +++ b/game_bloc_backend/src/tournaments/helper_functions.rs @@ -103,3 +103,116 @@ pub fn append_player_to_participants( } } } + +pub fn append_squad_to_tournament_v1( + squad_id: &String, + ign: Vec<(String, String, String)>, + new_member_ign: &Option>, + mut tournament: TournamentAccount, +) -> TournamentAccount { + match tournament + .to_owned() + .no_of_participants + .cmp(&(tournament.to_owned().user.len() as u128)) + { + Ordering::Greater => { + SQUAD_STORE.with(|squad_store| { + let mut squad = squad_store + .borrow() + .get(&squad_id.to_owned()) + .cloned() + .unwrap(); + if new_member_ign.is_some() { + let count = new_member_ign.to_owned().unwrap().len(); + if count > 0 { + PROFILE_STORE.with(|profile_store| { + loop { + if count == 0 { + break; + } + let mut user = profile_store + .borrow() + .get(&new_member_ign.to_owned().unwrap()[count - 1].0) + .cloned() + .unwrap(); + let missing: Member = Member { + name: user.to_owned().username, + principal_id: new_member_ign.to_owned().unwrap()[count - 1] + .0 + .to_owned(), + }; + squad.members.push(missing); + user.squad_badge = squad.id_hash.to_owned(); + profile_store.borrow_mut().insert( + new_member_ign.to_owned().unwrap()[count - 1].0.to_owned(), + user, + ); + } + squad_store + .borrow_mut() + .insert(squad_id.to_owned(), squad.to_owned()); + }); + } + let mut mutable_new_member_ign = new_member_ign.to_owned().unwrap(); + ign.to_owned().append(&mut mutable_new_member_ign); + } + tournament.squad.push(squad); + }); + match tournament.to_owned().squad_in_game_names { + None => { + tournament.squad_in_game_names = Some(vec![ign]); + tournament + } + Some(mut previous_igns) => { + previous_igns.push(ign); + tournament.squad_in_game_names = Some(previous_igns); + tournament + } + } + } + _ => tournament, + } +} + +pub fn append_player_to_participants_v1( + name: String, + ign: (String, String, String), + mut tournament: TournamentAccount, +) -> TournamentAccount { + match GameType::from_str(tournament.game_type.to_owned().as_str()) { + GameType::Single => { + match tournament + .to_owned() + .no_of_participants + .cmp(&(tournament.to_owned().user.len() as u128)) + { + Ordering::Greater => { + tournament.user.push(name.to_owned()); + match tournament.to_owned().in_game_names { + None => { + tournament.in_game_names = Some(vec![ign.to_owned()]); + } + Some(mut previous_igns) => { + previous_igns.push(ign); + tournament.in_game_names = Some(previous_igns); + } + } + let user_details = get_profile(name); + match tournament.user_details.to_owned() { + None => { + tournament.user_details = Some(vec![user_details]); + tournament + } + Some(mut previous_user_details) => { + previous_user_details.push(user_details); + tournament.user_details = Some(previous_user_details); + tournament + } + } + } + _ => tournament, + } + } + _ => tournament, + } +} From fc2c3a6d33b7812916b50a74d584919f8181b61b Mon Sep 17 00:00:00 2001 From: marvincd Date: Mon, 7 Apr 2025 17:17:15 +0100 Subject: [PATCH 2/5] code cleanup/file restructure --- build.sh | 158 ------------------ game_bloc_backend/game_bloc_backend.did | 10 +- game_bloc_backend/src/model.rs | 1 + icp_ledger.did => interfaces/icp_ledger.did | 0 icrc_ledger.did => interfaces/icrc_ledger.did | 0 ledger.did => interfaces/ledger.did | 0 .../qhbym-qaaaa-aaaaa-aaafq-cai.did | 0 .../ryjl3-tyaaa-aaaaa-aaaba-cai.did | 0 .../download_latest_icp_ledger.sh | 0 install_didc.sh => scripts/install_didc.sh | 0 makefile => scripts/makefile | 0 point.sh => scripts/point.sh | 0 12 files changed, 9 insertions(+), 160 deletions(-) delete mode 100755 build.sh rename icp_ledger.did => interfaces/icp_ledger.did (100%) rename icrc_ledger.did => interfaces/icrc_ledger.did (100%) rename ledger.did => interfaces/ledger.did (100%) rename qhbym-qaaaa-aaaaa-aaafq-cai.did => interfaces/qhbym-qaaaa-aaaaa-aaafq-cai.did (100%) rename ryjl3-tyaaa-aaaaa-aaaba-cai.did => interfaces/ryjl3-tyaaa-aaaaa-aaaba-cai.did (100%) rename download_latest_icp_ledger.sh => scripts/download_latest_icp_ledger.sh (100%) rename install_didc.sh => scripts/install_didc.sh (100%) rename makefile => scripts/makefile (100%) rename point.sh => scripts/point.sh (100%) diff --git a/build.sh b/build.sh deleted file mode 100755 index 5df35c25..00000000 --- a/build.sh +++ /dev/null @@ -1,158 +0,0 @@ -#!/bin/bash - -echo ">> Building ledger" - -dfx identity remove minter -dfx identity new minter -dfx identity use minter -MINT_ACC=$(dfx ledger account-id) -export MINT_ACC - -dfx identity use default - -export OWNER=$(dfx identity get-principal) - -LEDGER_ACC=$(dfx ledger account-id) -export LEDGER_ACC - -ARCHIVE_CONTROLLER=$(dfx identity get-principal) -export ARCHIVE_CONTROLLER - -export TOKEN_NAME="ICP" - - candid-extractor target/wasm32-unknown-unknown/release/game_bloc_backend.wasm > game_bloc_backend/game_bloc_backend.did - - -cargo build --release --target wasm32-unknown-unknown --package game_bloc_backend - -dfx deploy icp_ledger --argument "(variant {Init =record {minting_account = \"${MINT_ACC}\"; -initial_values = vec { record { \"${LEDGER_ACC}\"; -record { e8s=100_000_000_000 } } } ; archive_options = opt record {num_blocks_to_archive = 1000000; trigger_threshold = 1000000; \ - controller_id = principal \"${ARCHIVE_CONTROLLER}\"; }; send_whitelist = vec {}}})" --specified-id ryjl3-tyaaa-aaaaa-aaaba-cai - -dfx deploy icp_index --specified-id qhbym-qaaaa-aaaaa-aaafq-cai --argument '(record {ledger_id = principal "ryjl3-tyaaa-aaaaa-aaaba-cai"})' - -# dfx canister --network local call icp_ledger icr1_transfer ' -# (record { -# to=(record { -# owner=(principal "b77ix-eeaaa-aaaaa-qaada-cai") -# }); -# amount=500_000 -# })' - -# dfx ledger transfer --amount 500_000 --memo 123 476653ac80a51b906bcc24f5ce59c1c6b4290d8dddc7ac6fae4a4b5070cf5abd - -# dfx identity use DevJourney -# dfx canister call icp_ledger icrc1_transfer "(record { to = record { owner = principal \"b77ix-eeaaa-aaaaa-qaada-cai\";};  amount = 1_000_000;})" - -# --specified-id ryjl3-tyaaa-aaaaa-aaaaa-cai -# dfx deploy --network local icrc1_ledger --argument ' -# (variant { -# Init = record { -# token_name = "Local ICP"; -# token_symbol = "LICP"; -# minting_account = record { -# owner = principal "'${OWNER}'"; -# }; -# initial_balances = vec { -# record { -# record { -# owner = principal "'${OWNER}'"; -# }; -# 100_000_000_000; -# }; -# }; -# metadata = vec {}; -# transfer_fee = 10; -# archive_options = record { -# trigger_threshold = 2000; -# num_blocks_to_archive = 1000; -# controller_id = principal "'${OWNER}'"; -# } -# } -# }) -# ' - -dfx deploy --network local --specified-id mxzaz-hqaaa-aaaar-qaada-cai ckbtc_ledger --argument ' - (variant { - Init = record { - token_name = "Local ckBTC"; - token_symbol = "LCKBTC"; - minting_account = record { - owner = principal "'${OWNER}'"; - }; - initial_balances = vec { - record { - record { - owner = principal "'${OWNER}'"; - }; - 100_000_000_000; - }; - }; - metadata = vec {}; - transfer_fee = 10; - archive_options = record { - trigger_threshold = 2000; - num_blocks_to_archive = 1000; - controller_id = principal "'${OWNER}'"; - } - } - }) -' - -# dfx deploy ckbtc_index --specified-id n5wcd-faaaa-aaaar-qaaea-cai --argument '(record {ledger_id = principal "mxzaz-hqaaa-aaaar-qaada-cai"})' - -dfx deploy --network local ckbtc_index --argument ' - record { - ledger_id = (principal "mxzaz-hqaaa-aaaar-qaada-cai"); - } -' - - -dfx deploy --network local --specified-id ss2fx-dyaaa-aaaar-qacoq-cai cketh_ledger --argument ' - (variant { - Init = record { - token_name = "Local ckETH"; - token_symbol = "LCKETH"; - minting_account = record { - owner = principal "'${OWNER}'"; - }; - initial_balances = vec { - record { - record { - owner = principal "'${OWNER}'"; - }; - 100_000_000_000; - }; - }; - metadata = vec {}; - transfer_fee = 10; - archive_options = record { - trigger_threshold = 2000; - num_blocks_to_archive = 1000; - controller_id = principal "'${OWNER}'"; - } - } - }) -' - -dfx deploy --network local cketh_index --argument ' - record { - ledger_id = (principal "ss2fx-dyaaa-aaaar-qacoq-cai"); - } -' - - -dfx deploy - -# "system_api": { -# "candid": "system_api/vetkd_system_api.did", -# "type": "rust", -# "package": "vetkd_system_api" -# }, - - -# dfx deploy --network=ic canister update-settings kitchen --add-controller ltmcx-2y32p-k3cxj-oe7mh-zplyh-mg7j2-w5756-qajf5-l6y47-be56z-nqe --network=ic2024-10-03 21:07:49.875732 UTC: [Canister bd3sg-teaaa-aaaaa-qaaba-cai] 20[ic-icrc1-index] Indexed: 0 waiting : 22 -# 4-10-03 21:07:49.875732 UTC: [Canister be2us-64aaa-aaaaa-qaabq-cai] - -# MOPS_VERSION=1.0.0 sh -ci "$(curl -fsSL cli.mops.one/install.sh | sh)" diff --git a/game_bloc_backend/game_bloc_backend.did b/game_bloc_backend/game_bloc_backend.did index c2e7477b..2ba7d572 100644 --- a/game_bloc_backend/game_bloc_backend.did +++ b/game_bloc_backend/game_bloc_backend.did @@ -5,7 +5,7 @@ type Contestant = record { losses : nat8; point : nat; }; -type GameType = variant { Duo; Squad; TeamvTeam; Single }; +type GameType = variant { Duo; Squad; OnevOne; TeamvTeam; Single }; type LobbyAccount = record { idx : nat8; status : TournamentStatus; @@ -70,6 +70,7 @@ type TournamentAccount = record { squad : vec Squad; accepts_wagers : opt bool; no_of_participants_at_bump : opt nat; + referal_ids : vec text; lobbies : opt vec LobbyAccount; game_type : text; user_details : opt vec UserProfile; @@ -99,7 +100,12 @@ type TournamentStatus = variant { Archived; GameCompleted; }; -type TournamentType = variant { Prepaid; Crowdfunded; Blitzkrieg }; +type TournamentType = variant { + Prepaid; + Crowdfunded; + Blitzkrieg; + SquadTraining; +}; type UserProfile = record { age : nat8; account_id : text; diff --git a/game_bloc_backend/src/model.rs b/game_bloc_backend/src/model.rs index 969e1ddf..6171ad3d 100644 --- a/game_bloc_backend/src/model.rs +++ b/game_bloc_backend/src/model.rs @@ -52,6 +52,7 @@ pub_struct!( squad_in_game_names:Option>>, messages: Option>, user: Vec, + referal_ids: Vec, user_details: Option>, winers: Vec, //deprecated diff --git a/icp_ledger.did b/interfaces/icp_ledger.did similarity index 100% rename from icp_ledger.did rename to interfaces/icp_ledger.did diff --git a/icrc_ledger.did b/interfaces/icrc_ledger.did similarity index 100% rename from icrc_ledger.did rename to interfaces/icrc_ledger.did diff --git a/ledger.did b/interfaces/ledger.did similarity index 100% rename from ledger.did rename to interfaces/ledger.did diff --git a/qhbym-qaaaa-aaaaa-aaafq-cai.did b/interfaces/qhbym-qaaaa-aaaaa-aaafq-cai.did similarity index 100% rename from qhbym-qaaaa-aaaaa-aaafq-cai.did rename to interfaces/qhbym-qaaaa-aaaaa-aaafq-cai.did diff --git a/ryjl3-tyaaa-aaaaa-aaaba-cai.did b/interfaces/ryjl3-tyaaa-aaaaa-aaaba-cai.did similarity index 100% rename from ryjl3-tyaaa-aaaaa-aaaba-cai.did rename to interfaces/ryjl3-tyaaa-aaaaa-aaaba-cai.did diff --git a/download_latest_icp_ledger.sh b/scripts/download_latest_icp_ledger.sh similarity index 100% rename from download_latest_icp_ledger.sh rename to scripts/download_latest_icp_ledger.sh diff --git a/install_didc.sh b/scripts/install_didc.sh similarity index 100% rename from install_didc.sh rename to scripts/install_didc.sh diff --git a/makefile b/scripts/makefile similarity index 100% rename from makefile rename to scripts/makefile diff --git a/point.sh b/scripts/point.sh similarity index 100% rename from point.sh rename to scripts/point.sh From 1326a6036f96340cff3d06d5a7fb63e57c69f68f Mon Sep 17 00:00:00 2001 From: ola-893 Date: Thu, 1 May 2025 16:39:03 +0100 Subject: [PATCH 3/5] made update to follow the new architecture update stated by the cto --- game_bloc_backend/game_bloc_backend.did | 9 +- game_bloc_backend/src/model.rs | 198 +++++++++++++++++++++++- 2 files changed, 199 insertions(+), 8 deletions(-) diff --git a/game_bloc_backend/game_bloc_backend.did b/game_bloc_backend/game_bloc_backend.did index 2ba7d572..f9e56b62 100644 --- a/game_bloc_backend/game_bloc_backend.did +++ b/game_bloc_backend/game_bloc_backend.did @@ -70,7 +70,6 @@ type TournamentAccount = record { squad : vec Squad; accepts_wagers : opt bool; no_of_participants_at_bump : opt nat; - referal_ids : vec text; lobbies : opt vec LobbyAccount; game_type : text; user_details : opt vec UserProfile; @@ -100,12 +99,7 @@ type TournamentStatus = variant { Archived; GameCompleted; }; -type TournamentType = variant { - Prepaid; - Crowdfunded; - Blitzkrieg; - SquadTraining; -}; +type TournamentType = variant { Prepaid; Crowdfunded; Blitzkrieg }; type UserProfile = record { age : nat8; account_id : text; @@ -164,6 +158,7 @@ service : () -> { end_tournament : (text, principal, nat8, vec Winner) -> (bool); expected_wager_reward : (text, text) -> (vec nat) query; getSelf : () -> (UserProfile) query; + get_all_principals : () -> (vec principal) query; get_all_squad : () -> (vec Squad) query; get_all_tournament : () -> (vec TournamentAccount) query; get_all_tournament_lobbies : (text) -> (vec LobbyAccount) query; diff --git a/game_bloc_backend/src/model.rs b/game_bloc_backend/src/model.rs index 523d55a7..41896e7b 100644 --- a/game_bloc_backend/src/model.rs +++ b/game_bloc_backend/src/model.rs @@ -27,8 +27,11 @@ pub_struct!(UserProfile { tournaments_created:u8, points: Option>, username: String, + tournaments: Option>, //deprecated is_mod: bool, + usermode: Option, + earnings: Option, role: Option, principal_id: String, account_id : String, @@ -37,6 +40,8 @@ pub_struct!(UserProfile { referral_id: Option, }); + + pub_struct!( TournamentAccount { id_hash: String, @@ -44,6 +49,20 @@ pub_struct!( creator_id: Option, status: TournamentStatus, idx: u8, + creator_principal: Option, + + is_private: Option, + moderators: Option>, + payout_distribution: Option, + external_link: Option, + metadata: Option, + is_team_based: Option, + team_size: Option, + teams: Option>, + max_teams: Option, + allow_solo_players: Option, + allow_auto_match: Option, + starting_date: String, tournament_rules: String, tournament_type: TournamentType, @@ -52,7 +71,7 @@ pub_struct!( squad_in_game_names:Option>>, messages: Option>, user: Vec, - referal_ids: Vec, + referal_ids: Option>, user_details: Option>, winers: Vec, //deprecated @@ -143,6 +162,7 @@ pub_struct!(Point { total_points: u128, }); + pub_struct!( Squad { id_hash: String, @@ -156,6 +176,8 @@ pub_struct!( members: Vec, requests: Vec, points: Option>, + created_at: Option, + created_by: Option, }); pub_struct!(Member { @@ -189,6 +211,7 @@ pub enum Status { #[default] Online, Offline, + Away, } #[derive(Clone, Debug, Default, CandidType, Deserialize, Serialize)] @@ -196,6 +219,7 @@ pub enum Role { #[default] Player, Mod, + // Admin, TribunalMod(ModTag), } @@ -303,3 +327,175 @@ impl Storable for UserProfile { is_fixed_size: false, }; } + + +/// A placeholder for Internet Computer Principal IDs +pub type Principal = String; + +/// Basic result type +// #[derive(Debug, Serialize, Deserialize)] +// pub enum Result { +// Ok(T), +// Err(E), +// } + +/// Points outcome +// #[derive(Debug, Serialize, Deserialize)] +// pub enum Point { +// Win, +// Loss, +// Draw, +// } + + +/// Error messages +#[derive(Debug, Serialize, Deserialize)] +pub enum ErrorMessage { + NotAuthorized, + DoesNotExist, + Expired, + WrongCredentials, + NotAllowed, + NotEnoughBalance, + NotEligible, +} + +/// Notification model +#[derive(Debug, Serialize, Deserialize)] +pub struct Notification { + pub id: u64, + pub title: String, + pub body: String, + pub user: Principal, + pub username: String, + pub date: String, + pub read: bool, +} + +/// Container for multiple notifications +#[derive(Debug, Serialize, Deserialize)] +pub struct Notifications { + pub notifications: Vec, + pub user: Principal, +} + +/// User modes +#[derive( + Clone, Debug, PartialEq, Default, Ord, Eq, PartialOrd, CandidType, Deserialize, Serialize, +)] +pub enum UserMode { + #[default] + Base, + Creator, + Moderator, +} + +/// Tournament identifier +pub type TournamentId = String; + +/// Payout distribution among parties +#[derive( + Clone, Debug, PartialEq, Default, Ord, Eq, PartialOrd, CandidType, Deserialize, Serialize, +)] +pub struct PayoutDistribution { + pub winner: u64, + pub creator: u64, + pub platform: u64, +} + +/// Various game types +// #[derive(Debug, Serialize, Deserialize)] +// pub enum GameType { +// Board, +// Card, +// Shooter, +// MOBA, +// Sports, +// Trivia, +// Arcade, +// Custom(String), +// } + +/// Different game modes +// #[derive(Debug, Serialize, Deserialize)] +// pub enum GameMode { +// OnevOne, +// FreeForAll, +// BracketElimination, +// League, +// TimedScore, +// LastManStanding, +// GroupToFinals, +// Custom(String), +// } + +/// Metadata for tournaments +#[derive( + Clone, Debug, PartialEq, Default, Ord, Eq, PartialOrd, CandidType, Deserialize, Serialize, +)] +pub struct TournamentMeta { + pub start_time: String, + pub end_time: String, + pub prize_pool: u64, + pub winning_prize: u64, + pub stream_url: Option, + pub description: String, + pub tournament_banner: Option, + pub tags: Vec, +} + +/// Status of a tournament +// #[derive(Debug, Serialize, Deserialize)] +// pub enum TournamentStatus { +// Upcoming, +// Ongoing, +// Completed, +// Cancelled, +// Archived, +// } + +/// Type of tournament funding +// #[derive(Debug, Serialize, Deserialize)] +// pub enum TournamentType { +// Prepaid, +// Crowdfunded, +// } + +/// Team size options +#[derive( + Clone, Debug, PartialEq, Default, Ord, Eq, PartialOrd, CandidType, Deserialize, Serialize, +)] +pub enum TeamType { + Duo, + Squad, + #[default] + Solo, +} + +/// Team model +#[derive( + Clone, Debug, PartialEq, Default, Ord, Eq, PartialOrd, CandidType, Deserialize, Serialize, +)] +pub struct Team { + pub id: String, + pub name: String, + pub members: Vec, + pub captain: Principal, + pub created_at: String, + pub metadata: Option, +} + + + + + + + +/// Generic result type for Motoko-style unions +#[derive( + Clone, Debug, PartialEq, Ord, Eq, PartialOrd, CandidType, Deserialize, Serialize, +)] +pub enum OperationResult { + Ok(String), + Err(String), +} From 6b94548ce9c70d81f3bdeaa2d956a38845e1c6fe Mon Sep 17 00:00:00 2001 From: ola-893 Date: Mon, 5 May 2025 11:19:16 +0100 Subject: [PATCH 4/5] added a feature that enables certain players to be selected from the squad for a tournament, also updated the build script in other to fix the empty candid issue --- game_bloc_backend/.idea/workspace.xml | 56 ++++++++++--------- game_bloc_backend/game_bloc_backend.did | 51 ++++++++++++++++- game_bloc_backend/src/model.rs | 7 +++ .../src/tournaments/helper_functions.rs | 13 ++++- 4 files changed, 99 insertions(+), 28 deletions(-) diff --git a/game_bloc_backend/.idea/workspace.xml b/game_bloc_backend/.idea/workspace.xml index 32a5b2b3..49573108 100644 --- a/game_bloc_backend/.idea/workspace.xml +++ b/game_bloc_backend/.idea/workspace.xml @@ -8,10 +8,9 @@ - - + - + - { - "selectedUrlAndAccountId": { - "url": "https://github.com/Game-Bloc/Gamebloc-ICP.git", - "accountId": "0db38581-3150-4288-8add-0ffb714607b6" - } -} + + + { "associatedIndex": 4 } @@ -46,23 +49,23 @@