Skip to content

Latest commit

 

History

History
309 lines (257 loc) · 12.8 KB

README.md

File metadata and controls

309 lines (257 loc) · 12.8 KB

wheres_alex_v011.aleo

High level overview of Where's Alex with the Puzzle Wallet and Puzzle SDK


image

More information on the Puzzle Wallet and Puzzle SDK can be found here


Walking through the Where's Alex Leo programs


Note: There is additional technical functionality in the wheres_alex program for better FE UX and notification enablement that is not explained in detail below.


Step 1: challenger calls propose_game


image

propose_game to create a game with a friend.

This will involve creating a 2/2 multisig and staking funds to the private 2/2 multisig between the challenger and their opponent for the game (solving problem #3 mentioned above).

Function:

propose_game(
  wager_record: puzzle_token.leo/Puzz.record,
  amount: u64,
  sender: address, // Challenger address proposing game
  challenger: address,
  opponent: address,
  game_multisig: address,
  message_1: field, //from output of useSignature
  message_2: field,
  message_3: field,
  message_4: field,
  message_5: field,
  sig: signature, //from output of useSignature
  //multiparty_pvp_utils data
  nonce: field,
  answer: field,
  seed: field,
)

Example Command:

leo run propose_game "{
        owner: aleo16hf8hfpwasnn9cf7k2c0dllc56nn7qt547qxgvgwu6pznw4trvqsx68kls.private,
        amount: 500u64.private,
        ix: 0u32.private,
        _nonce: 5117772722354704202838157764917930913180509833961648133377098024993045952079group.public
    }" 100u64 aleo16hf8hfpwasnn9cf7k2c0dllc56nn7qt547qxgvgwu6pznw4trvqsx68kls aleo16hf8hfpwasnn9cf7k2c0dllc56nn7qt547qxgvgwu6pznw4trvqsx68kls aleo1r4pc6ufjvw050jhzrew3vqm2lvacdxfd4a5ckulau0vjc72qvc8sr0jg2a aleo1asu88azw3uqud282sll23wh3tvmvwjdz5vhvu2jwyrdwtgqn5qgqetuvr6 8062328565641143710315198539395259864274213782537700083868207132716559019626field 646976134778083579747150617209623060175268802563807996500102649727939562470field 7738966642647861988443742254957166327730088714215632067055062293849087980027field 501202936879316583063216806269060512965140130553350448375465909870676136661field 478560413032field sign1h04lnsl0t4aau8lzp06rzcm5eqrzr9ew63ljnw43v2nr7nkmsqqcx8cksna2ajwgk80rv0s7prrndw5k56sey3nrl487552lvaukuq8xe0cgu6x809qetnn35ufm3gl6ecyvtpgaavu9y5754j27utrwq8amruqyq2x6dvqs790yqsrctwmjnh3k7thslm0r9c3hpdvjrywpzts24xr 12345field 0field 98765field

Step 2: Opponent starts to accept game by calling submit_wager() with their key

image

submit_wager to submit your wager to the game you received from the challenger.

Function:

submit_wager(
  game_address: address,
  opponent: address,
  wager: puzzle_token.leo/Puzz.record,
  wager_amount: u64,
  nonce: field,
  msg: field,
  sig: signature,
)
leo run submit_wager "{
  owner: aleo1r4pc6ufjvw050jhzrew3vqm2lvacdxfd4a5ckulau0vjc72qvc8sr0jg2a.private,
  amount: 500u64.private,
  ix: 0u32.private,
  _nonce: 3004940205258698961047675300612628178407977124226246568871909567528102781306group.public
}" "{
  owner: aleo1r4pc6ufjvw050jhzrew3vqm2lvacdxfd4a5ckulau0vjc72qvc8sr0jg2a.private,
  seed: 98765field.private,
  amount: 100u64.private,
  challenger: aleo16hf8hfpwasnn9cf7k2c0dllc56nn7qt547qxgvgwu6pznw4trvqsx68kls.private,
  opponent: aleo1r4pc6ufjvw050jhzrew3vqm2lvacdxfd4a5ckulau0vjc72qvc8sr0jg2a.private,
  game_multisig: aleo1asu88azw3uqud282sll23wh3tvmvwjdz5vhvu2jwyrdwtgqn5qgqetuvr6.private,
  _nonce: 614304942627494924156540954346562345174322008762458420667361217491279792987group.public
}" "{
  owner: aleo1r4pc6ufjvw050jhzrew3vqm2lvacdxfd4a5ckulau0vjc72qvc8sr0jg2a.private,
  game_multisig: aleo1asu88azw3uqud282sll23wh3tvmvwjdz5vhvu2jwyrdwtgqn5qgqetuvr6.private,
  game_state: 1field.private,
  your_turn: true.private,
  total_pot: 200u64.private,
  challenger_address: aleo16hf8hfpwasnn9cf7k2c0dllc56nn7qt547qxgvgwu6pznw4trvqsx68kls.private,
  opponent_address: aleo1r4pc6ufjvw050jhzrew3vqm2lvacdxfd4a5ckulau0vjc72qvc8sr0jg2a.private,
  _nonce: 5007203806498158254911228558413488930295100188486359169745660062379448997833group.public
}" 4299148155668445410404796665478412871867472362428312345599969289162437917169field 251561861986387641133995513088278466362266230978294643355666629668300490271field 1152742118437172617676919179607096353215168002720611159713055309066048881777field 6965356107999508170054292104522311809055538516545196583411503498743541220125field 478560413032field sign1j0hhruukxrlddx4tzzpe8gccgy3l430el69e0jpclrzk2x3kecpq7zteu9z5qqqttk4xltyplgwzt4famkfxar5wjncz5ttssdur2qslse2uz49ljzhxz82y28gy0un45z8w2jgwk7jhdgxqh58qgcvwqpcuf9estpjsv9n9jln3x08mzl2rc8z25j6s6r4uf8rq9r7ddkxqyaahcxh

Step 3: Opponent uses multisig key to lock wagers in with accept_game()

image

accept_game to commit the wagers to the game and turn the game to the next step.

accept_game (
  game_record: Game,
  opponent_answer: field,
  piece_stake_challenger: puzzle_pieces_v007.leo/PieceStake.record,
  piece_claim_challenger: puzzle_pieces_v007.leo/PieceClaim.record,
  piece_stake_opponent: puzzle_pieces_v007.leo/PieceStake.record,
  piece_claim_opponent: puzzle_pieces_v007.leo/PieceClaim.record,
  block_ht: u32,
)

Step 4: Challenger updates game & joint stake to finish state with reveal_answer()

image

reveal_answer to reveal answer record and whether player 1 won or lost.

Function:

reveal_answer(
  reveal_answer_notification_record: RevealAnswerNotification,
  answer_record: multiparty_pvp_utils_v001.leo/Answer.record,
  joint_piece_state: puzzle_pieces_v007.leo/JointPieceState.record,
  claim_signature: puzzle_pieces_v007.leo/ClaimSignature.record,
  sig: signature
)

Step 5: Challenger uses multisig key to send payouts to winner with finish_game()

image

finish_game to finish game

Function:

finish_game (
  game_record: Game,
  joint_piece_winner: puzzle_pieces_v007.leo/JointPieceWinner.record,
  piece_joint_stake: puzzle_pieces_v007.leo/PieceJointStake.record,
  joint_piece_time_claim: puzzle_pieces_v007.leo/JointPieceTimeClaim.record,
)

NOTE: Different function executions require different keys (player 1, player 2, multisig keys). For testing purposes, you can run the below to switch execution keys.

We also have a test.sh script here that runs through all the flows.

echo "
NETWORK=testnet3
PRIVATE_KEY={MS_PK || P1_PK | P2_PK}
" > .env