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
Feat: Adding proc fold, its endpoint and its unit test #13
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b4d82d4
add rough check method
rishotics c014864
comments over contract procedures
nlok5923 168545a
change logic
rishotics 6024f1e
add new logic
rishotics 308d70a
fixes in play check procedure
nlok5923 fd4fee3
Merge branch 'main' into rg/add-play-check
rishotics 3365537
add brainstorm
rishotics 72a235c
merge
rishotics 4ae955b
add play fold
rishotics 8347ec3
Merge branch 'main' into rg/add-play-check
Created-for-a-purpose d551424
feat: add proc fold
Created-for-a-purpose 93f7e3d
fix: remove redundant code
Created-for-a-purpose 824c535
fix: adding some changes
Created-for-a-purpose 4d75c70
fix: add constants in notescript
Created-for-a-purpose 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
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
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use.miden::account | ||
use.miden::note | ||
use.miden::contracts::wallets::basic->wallet | ||
|
||
const.CURRENT_TURN_INDEX=60 | ||
|
||
proc.play_fold | ||
push.CURRENT_TURN_INDEX exec.account::get_item | ||
# => [0, 0, 0, current_turn_index] | ||
|
||
drop drop drop | ||
# => [current_turn_index] | ||
|
||
push.9 | ||
# 9, current_turn_index | ||
add | ||
# => [current_turn_index + 9] | ||
dup #for getting the get item | ||
dup #for updating the turn | ||
# => [current_turn_index + 9, current_turn_index + 9, current_turn_index + 9] | ||
|
||
# getting the is_fold of player | ||
exec.account::get_item | ||
drop drop drop | ||
# => [is_fold, current_turn_index + 9, current_turn_index + 9] | ||
|
||
# making sure that is_fold is zero currently | ||
assertz | ||
# => [current_turn_index + 9, current_turn_index + 9] | ||
push.1 | ||
# => [1, current_turn_index + 9, current_turn_index + 9] | ||
|
||
swap padw drop movup.3 | ||
# => [current_turn_index + 9, 0, 0, 0, 1, current_turn_index + 9] | ||
exec.account::set_item | ||
dropw drop drop drop | ||
# => [current_turn_index + 9] | ||
|
||
# adding 4 will give the slot of next player | ||
push.4 add | ||
push.1 | ||
# => [1, next_turn_index] | ||
|
||
while.true | ||
|
||
dup push.9 add | ||
# => [next_turn_index + 9, next_turn_index] | ||
exec.account::get_item | ||
drop drop drop | ||
# => [is_fold, next_turn_index] | ||
|
||
if.true | ||
# if player has folded | ||
dup push.103 lte | ||
# => [0/1, next_turn_index] | ||
|
||
if.true | ||
push.13 add | ||
push.1 | ||
# => [1, next_turn_index + 13] | ||
else | ||
push.0 | ||
end | ||
else | ||
# checking is fold | ||
# => [next_turn_index] | ||
|
||
padw drop | ||
# => [0, 0, 0, next_turn_index] | ||
|
||
push.CURRENT_TURN_INDEX # slot of current turn | ||
# => [CURRENT_TURN_INDEX, 0, 0, 0, next_turn_index] | ||
|
||
exec.account::set_item | ||
dropw dropw | ||
# => [...] | ||
push.0 | ||
end | ||
end | ||
drop | ||
# => [...] | ||
end | ||
|
||
begin | ||
dropw | ||
|
||
call.play_fold | ||
# => [...] | ||
|
||
dropw | ||
exec.note::get_assets drop mem_loadw | ||
# => [ASSET, ...] | ||
|
||
# load the asset and add it to the account | ||
call.wallet::receive_asset | ||
# => [...] | ||
|
||
dropw | ||
end |
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 |
---|---|---|
@@ -0,0 +1,196 @@ | ||
use.miden::account | ||
|
||
# const.CURRNET_TURN_PLAYER_PUB_KEY_INDEX=63 | ||
|
||
# index corresponding to the information saved | ||
const.PLAYER_1_INDEX=62 # use this index to find other player pub key slot index which would always be second to the player account id | ||
const.SMALL_BLIND_INDEX=56 | ||
const.BIG_BLIND_INDEX=57 | ||
const.BUY_IN_INDEX=58 | ||
const.NO_OF_PLAYERS_INDEX=59 | ||
const.CURRENT_TURN_INDEX=60 | ||
const.RAISER_INDEX=61 | ||
const.HIGHEST_BET_SLOT_INDEX=63 | ||
const.CURRENT_TURN_PLAYER_PUB_KEY_INDEX=64 # need to check it's storage initially small blind public key on slot 62 | ||
|
||
# this procedure just stores the cards as items in the account storage | ||
export.receive_cards | ||
exec.account::set_item | ||
|
||
# prepare stack for return | ||
movup.4 drop movup.4 drop movup.4 drop | ||
end | ||
|
||
# it helps to check that the intended player is calling the function | ||
export.poker_auth_tx_rpo_falcon512 | ||
# Get commitments to created notes | ||
exec.tx::get_output_notes_hash | ||
# => [OUTPUT_NOTES_HASH, ...] | ||
|
||
# Get commitments to consumed notes | ||
exec.tx::get_input_notes_hash | ||
# => [INPUT_NOTES_HASH, OUTPUT_NOTES_HASH, ...] | ||
|
||
# Get current nonce of the account and pad | ||
exec.account::get_nonce push.0.0.0 | ||
# => [0, 0, 0, nonce, INPUT_NOTES_HASH, OUTPUT_NOTES_HASH, ...] | ||
|
||
# Get current AccountID and pad | ||
exec.account::get_id push.0.0.0 | ||
# => [0, 0, 0, account_id, 0, 0, 0, nonce, INPUT_NOTES_HASH, OUTPUT_NOTES_HASH, ...] | ||
|
||
# Compute the message to be signed | ||
# M = h(OUTPUT_NOTES_HASH, h(INPUT_NOTES_HASH, h(0, 0, 0, account_id, 0, 0, 0, nonce))) | ||
hmerge hmerge hmerge | ||
|
||
# Get public key from account storage at pos 0 and verify signature | ||
push.CURRENT_TURN_PLAYER_PUB_KEY_INDEX exec.account::get_item | ||
# => [PUB_KEY, M] | ||
|
||
# Verify the signature against the public key and the message. The procedure gets as | ||
# inputs the hash of the public key and the hash of the message via the operand | ||
# stack. The signature is provided via the advice stack. The signature is valid if and | ||
# only if the procedure returns. | ||
exec.rpo_falcon512::verify | ||
# => [] | ||
|
||
# Update the nonce | ||
push.1 exec.account::incr_nonce | ||
# => [] | ||
end | ||
|
||
# should be executed using transcripts | ||
export.play_call | ||
# when user wants to just call and match the bet | ||
# fetch the current bet we need to 2 to the player_1_index | ||
|
||
push.PLAYER_1_INDEX.2 add exec.account::get_item | ||
# => [0, 0, 0, current bet] since we are currently storing everything in word | ||
drop drop drop | ||
# => [current bet] | ||
push.HIGHEST_BET_SLOT_INDEX exec.account::get_item | ||
# => [0, 0, 0, highest bet, current bet] | ||
drop drop drop | ||
sub | ||
# => [highest bet - current bet] subtract this amount from player balance | ||
# => [difference] | ||
# using current turn index found player index | ||
const.CURRENT_PLAYER_INDEX=100 | ||
push.CURRENT_PLAYER_INDEX.4 # At 4th we are saving using balance | ||
exec.account::get_item | ||
# => [balance, difference] | ||
sub | ||
# => [balance - difference] | ||
push.CURRENT_PLAYER_INDEX.4 | ||
exec.account::set_item | ||
end | ||
|
||
export.play_check | ||
# update the turn | ||
# balance, points will remain same | ||
push.CURRENT_TURN_INDEX exec.account::get_item | ||
# [0, 0, 0, current turn index] | ||
drop | ||
drop | ||
drop | ||
# [current turn index] | ||
|
||
push.8 | ||
add | ||
push.44 | ||
mod | ||
# currnt_turn_index + 8 | ||
|
||
dup | ||
# currnt_turn_index + 8, currnt_turn_index + 8 | ||
|
||
mem_store.0 | ||
#currnt_turn_index + 8 | ||
|
||
while | ||
# now we know that this is the index we need to use as the next player index | ||
# currnt_turn_index + 8 | ||
push.4 | ||
# 4, currnt_turn_index + 8 | ||
add | ||
exec::account::get_item | ||
drop drop drop | ||
# [is fold] | ||
if | ||
# checking is fold | ||
mem_load.0 # player ka index | ||
push.CURRENT_TURN_INDEX # slot (player ka index ) | ||
exec::account::set_item | ||
push.0 | ||
else | ||
push.8 | ||
add | ||
end | ||
end | ||
|
||
export.play_raise | ||
# update the turn | ||
# raise the amount of current bet | ||
|
||
end | ||
|
||
export.play_fold | ||
# make is_fold of player 1 | ||
# inc turn | ||
push.CURRENT_TURN_INDEX | ||
# [0, 0, 0, current_turn_index] | ||
|
||
drop drop drop | ||
# [current_turn_index] | ||
|
||
push.4 | ||
# 4, current_turn_index | ||
add | ||
# [4+current_turn_index] | ||
dup #for getting the get item | ||
dup #for updating the turn | ||
# [4+current_turn_index, 4+current_turn_index, 4+current_turn_index] | ||
|
||
# getting the is_fold of player | ||
exec::account::get_item | ||
drop drop drop | ||
#[is_fold, 4+current_turn_index, 4+current_turn_index] | ||
|
||
# making sure that is_fold is zero currently | ||
dup | ||
push.0 | ||
equal | ||
|
||
#[is_fold, 4+current_turn_index, 4+current_turn_index] | ||
swap | ||
exec::account::set_item | ||
#[4+current_turn_index] | ||
|
||
# adding 1 will give the slot of next player | ||
push.1 | ||
add | ||
push.44 | ||
mod | ||
|
||
#[next_turn_index] | ||
|
||
while | ||
|
||
push.4 | ||
# 4, next_turn_index | ||
add | ||
exec::account::get_item | ||
drop drop drop | ||
# [is fold] | ||
if | ||
# checking is fold | ||
mem_load.0 # player ka index | ||
push.CURRENT_TURN_INDEX # slot (player ka index ) | ||
exec::account::set_item | ||
push.0 | ||
else | ||
push.8 | ||
add | ||
end | ||
|
||
end |
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 |
---|---|---|
|
@@ -173,10 +173,10 @@ fn construct_game_constructor_storage( | |
]; | ||
player_pub_keys.extend(player_slots); | ||
|
||
slot_index += 8; // since the mid 9 elements would cover the player stats and initially all those values are zero | ||
slot_index += 13; // since the mid 9 elements would cover the player stats and initially all those values are zero | ||
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. Can you hardcode this different in constant, And name it something suitable. |
||
} | ||
|
||
// merghe player_id with card_suit | ||
// merge player_id with card_suit | ||
game_info.push(auth_slot); | ||
game_info.extend(cards); | ||
game_info.extend(game_stats); | ||
|
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.
We can delete this file since we are not using it anywhere.