Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Utility funtion to setup user, game accounts #24

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
80 changes: 72 additions & 8 deletions lib/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use miden_objects::{
accounts::{ Account, AccountCode, AccountId, AccountStorage, SlotItem },
assembly::{ ModuleAst, ProgramAst },
assets::{ Asset, AssetVault, FungibleAsset },
assets::{ Asset, AssetVault, FungibleAsset, TokenSymbol },
crypto::{
dsa::rpo_falcon512::SecretKey,
utils::Serializable,
rand::FeltRng,
rand::RpoRandomCoin,
dsa::rpo_falcon512::SecretKey, rand::{FeltRng, RpoRandomCoin}, utils::Serializable
},
notes::{ Note, NoteId, NoteScript },
notes::{ Note, NoteId, NoteScript, NoteType },
transaction::{
ChainMmr,
ExecutedTransaction,
Expand All @@ -21,17 +18,18 @@ use miden_objects::{
Felt,
Word,
};

use std::{ env::temp_dir, fs, time::Duration };
use miden_client::{
client::{ rpc::NodeRpcClient, Client },
client::{ accounts::{AccountStorageMode, AccountTemplate}, rpc::NodeRpcClient, Client },
config::ClientConfig,
errors::{ ClientError, NoteIdPrefixFetchError },
store::{ sqlite_store::SqliteStore, InputNoteRecord, NoteFilter as ClientNoteFilter, Store },
};
use std::path::Path;
use figment::{ providers::{ Format, Toml }, Figment };
use ::rand::Rng;
use crate::client::AzeClient;
use crate::{client::{AzeAccountTemplate, AzeClient, AzeGameMethods}, constants::BUY_IN_AMOUNT, notes::{consume_notes, mint_note}, storage::GameStorageSlotData};

// use uuid::Uuid;

Expand Down Expand Up @@ -83,3 +81,69 @@ pub async fn log_slots(client: &AzeClient, account_id: AccountId) {
println!("Account slot {:?} --> {:?}", i, regular_account.storage().get_item(i));
}
}

pub async fn initial_setup(mut client: &mut AzeClient) -> (FungibleAsset, AccountId, AccountId, GameStorageSlotData){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good can we rename initial_setup to something more reflective ?

let small_blind_amt = 5u8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make these values as default constants and store it in lib/src/constant modules

let buy_in_amt = 100u8;
let no_of_players = 4u8;
let current_turn_index = 64u8;
let player_balance = 10u8;

let slot_data = GameStorageSlotData::new(
small_blind_amt,
buy_in_amt,
no_of_players,
current_turn_index,
small_blind_amt,
player_balance,
);

let (game_account, _) = client
.new_game_account(
AzeAccountTemplate::GameAccount {
mutable_code: false,
storage_mode: AccountStorageMode::Local, // for now
},
Some(slot_data.clone()),
)
.unwrap();
let game_account_id = game_account.id();
log_slots(&client, game_account_id).await;

let (player_account, _) = client
.new_game_account(
AzeAccountTemplate::PlayerAccount {
mutable_code: false,
storage_mode: AccountStorageMode::Local, // for now
},
None,
)
.unwrap();
let player_account_id = player_account.id();

let (faucet_account, _) = client
.new_account(AccountTemplate::FungibleFaucet {
token_symbol: TokenSymbol::new("MATIC").unwrap(),
decimals: 8,
max_supply: 1_000_000_000,
storage_mode: AccountStorageMode::Local,
})
.unwrap();
let faucet_account_id = faucet_account.id();

let note = mint_note(
&mut client,
player_account_id,
faucet_account_id,
NoteType::Public,
)
.await;
println!("Minted note");
consume_notes(&mut client, player_account_id, &[note]).await;

let fungible_asset = FungibleAsset::new(faucet_account_id, BUY_IN_AMOUNT).unwrap();
let sender_account_id = player_account_id;
let target_account_id = game_account_id;

return (fungible_asset, sender_account_id, target_account_id, slot_data)
}
Loading
Loading