forked from Aze-Cards/aze-server
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,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, | ||
|
@@ -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; | ||
|
||
|
@@ -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){ | ||
let small_blind_amt = 5u8; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make these values as default constants and store it in |
||
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) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?