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

Added update current turn and update phase logic in proc call #15

Merged
merged 20 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e19bc91
add update current turn in proc call
Created-for-a-purpose May 19, 2024
975a234
add update phase logic in proc call
Created-for-a-purpose May 19, 2024
e8f8416
fix: update current turn in actions
Created-for-a-purpose May 19, 2024
42e933c
feat: add update current turn and phase logic in proc fold
Created-for-a-purpose May 19, 2024
658d7ae
fix: update current turn in actions
Created-for-a-purpose May 19, 2024
63358e1
fix: update fold offset in proc fold test
Created-for-a-purpose May 19, 2024
44ea50f
feat: add update current turn and phase logic in proc check
Created-for-a-purpose May 19, 2024
910b0d1
fix: update proc check unit test
Created-for-a-purpose May 19, 2024
54cf153
feat: add proc bet contract
Created-for-a-purpose May 19, 2024
ee97a0b
feat: add proc bet
Created-for-a-purpose May 19, 2024
81ebb9b
feat: add e2e test
Created-for-a-purpose May 19, 2024
c6a10c2
fix: remove redundant code
Created-for-a-purpose May 19, 2024
302d845
feat: add test for proc bet
Created-for-a-purpose May 20, 2024
f3b8a7b
e2e test reorganization
Created-for-a-purpose May 20, 2024
640ae11
add e2e test path in cargo.toml
Created-for-a-purpose May 20, 2024
71b39d4
Merge branch 'feat/add-bet-contract' into feat/add-e2e-test
Created-for-a-purpose May 21, 2024
d93a962
Merge pull request #19 from RizeLabs/feat/add-e2e-test
nlok5923 May 21, 2024
5b41cae
Merge pull request #18 from RizeLabs/feat/add-bet-contract
nlok5923 May 21, 2024
7c77a9f
Merge pull request #17 from RizeLabs/rg/active-player
nlok5923 May 21, 2024
e70dd26
Merge pull request #16 from RizeLabs/rg/add-play-check
nlok5923 May 21, 2024
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
Prev Previous commit
Next Next commit
feat: add proc bet
  • Loading branch information
Created-for-a-purpose committed May 19, 2024
commit ee97a0b55cff04dacec303b25fb61d9094d287b8
103 changes: 103 additions & 0 deletions lib/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

use crate::accounts::{ create_basic_aze_game_account, create_basic_aze_player_account };
use crate::utils::{ create_aze_store_path, load_config };
use crate::notes::{
create_send_card_note,
create_play_bet_note,
create_play_raise_note,
create_play_call_note,
create_play_fold_note,
Expand Down Expand Up @@ -55,6 +57,14 @@ pub struct SendCardTransactionData {
cards: [[Felt; 4]; 2],
}

#[derive(Clone)]
pub struct PlayBetTransactionData {
asset: Asset,
sender_account_id: AccountId,
target_account_id: AccountId,
player_bet: u8,
}

#[derive(Clone)]
pub struct PlayRaiseTransactionData {
asset: Asset,
Expand Down Expand Up @@ -103,6 +113,25 @@ impl SendCardTransactionData {
}
}

impl PlayBetTransactionData {
pub fn account_id(&self) -> AccountId {
self.sender_account_id
}
pub fn new(
asset: Asset,
sender_account_id: AccountId,
target_account_id: AccountId,
player_bet: u8
) -> Self {
Self {
asset,
sender_account_id,
target_account_id,
player_bet,
}
}
}

impl PlayRaiseTransactionData {
pub fn account_id(&self) -> AccountId {
self.sender_account_id
Expand Down Expand Up @@ -177,6 +206,11 @@ pub trait AzeGameMethods {
// auth_info: AuthInfo,
transaction_template: AzeTransactionTemplate
) -> Result<TransactionRequest, ClientError>;
fn build_aze_play_bet_tx_request(
&mut self,
// auth_info: AuthInfo,
transaction_template: AzeTransactionTemplate
) -> Result<TransactionRequest, ClientError>;
fn build_aze_play_raise_tx_request(
&mut self,
// auth_info: AuthInfo,
Expand Down Expand Up @@ -401,6 +435,73 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store> AzeGameMethods for Client<N, R, S>
)
}

fn build_aze_play_bet_tx_request(
&mut self,
// auth_info: AuthInfo,
transaction_template: AzeTransactionTemplate
) -> Result<TransactionRequest, ClientError> {
let account_id = transaction_template.account_id();
let account_auth = self.store().get_account_auth(account_id)?;

let (sender_account_id, target_account_id, asset, player_bet) = match transaction_template {
AzeTransactionTemplate::PlayBet(
PlayBetTransactionData {
asset,
sender_account_id,
target_account_id,
player_bet,
},
) => (sender_account_id, target_account_id, asset, player_bet),
_ => panic!("Invalid transaction template"),
};

let random_coin = self.get_random_coin();

let created_note = create_play_bet_note(
self,
sender_account_id,
target_account_id,
[asset].to_vec(),
NoteType::Public,
random_coin,
player_bet
)?;

let recipient = created_note
.recipient_digest()
.iter()
.map(|x| x.as_int().to_string())
.collect::<Vec<_>>()
.join(".");

let note_tag = created_note.metadata().tag().inner();
let note_type = NoteType::Public;

let tx_script = ProgramAst::parse(
&transaction_request::AUTH_SEND_ASSET_SCRIPT
.replace("{recipient}", &recipient)
.replace("{note_type}", &Felt::new(note_type as u64).to_string())
.replace("{tag}", &Felt::new(note_tag.into()).to_string())
.replace("{asset}", &prepare_word(&asset.into()).to_string())
).expect("shipped MASM is well-formed");

let tx_script = {
let script_inputs = vec![account_auth.into_advice_inputs()];
self.compile_tx_script(tx_script, script_inputs, vec![])?
};

println!("Created txn script");

Ok(
TransactionRequest::new(
sender_account_id,
BTreeMap::new(),
vec![created_note],
Some(tx_script)
)
)
}

fn build_aze_play_raise_tx_request(
&mut self,
// auth_info: AuthInfo,
Expand Down Expand Up @@ -674,6 +775,7 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store> AzeGameMethods for Client<N, R, S>
//implement a new transaction template
pub enum AzeTransactionTemplate {
SendCard(SendCardTransactionData),
PlayBet(PlayBetTransactionData),
PlayRaise(PlayRaiseTransactionData),
PlayCall(PlayCallTransactionData),
PlayFold(PlayFoldTransactionData),
Expand All @@ -685,6 +787,7 @@ impl AzeTransactionTemplate {
pub fn account_id(&self) -> AccountId {
match self {
AzeTransactionTemplate::SendCard(p) => p.account_id(),
AzeTransactionTemplate::PlayBet(p) => p.account_id(),
AzeTransactionTemplate::PlayRaise(p) => p.account_id(),
AzeTransactionTemplate::PlayCall(p) => p.account_id(),
AzeTransactionTemplate::PlayFold(p) => p.account_id(),
Expand Down
26 changes: 26 additions & 0 deletions lib/src/notes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ pub fn create_send_card_note<R: FeltRng, N: NodeRpcClient, S: Store>(
Ok(Note::new(vault, metadata, recipient))
}

pub fn create_play_bet_note<R: FeltRng, N: NodeRpcClient, S: Store>(
client: &mut Client<N, R, S>,
sender_account_id: AccountId,
target_account_id: AccountId,
assets: Vec<Asset>,
note_type: NoteType,
mut rng: RpoRandomCoin,
player_bet: u8
) -> Result<Note, NoteError> {
let note_script = include_str!("../../contracts/notes/game/bet.masm");
let script_ast = ProgramAst::parse(note_script).unwrap();
let note_script = client.compile_note_script(script_ast, vec![]).unwrap();

let inputs = vec![Felt::from(player_bet)];
let note_inputs = NoteInputs::new(inputs).unwrap();
let tag = NoteTag::from_account_id(target_account_id, NoteExecutionMode::Local)?;
let serial_num = rng.draw_word();
let aux = ZERO;

let metadata = NoteMetadata::new(sender_account_id, NoteType::Public, tag, aux)?;
let vault = NoteAssets::new(assets)?;
let recipient = NoteRecipient::new(serial_num, note_script, note_inputs);

Ok(Note::new(vault, metadata, recipient))
}

pub fn create_play_raise_note<R: FeltRng, N: NodeRpcClient, S: Store>(
client: &mut Client<N, R, S>,
sender_account_id: AccountId,
Expand Down