From dc01c073991fda5a5f5de768ccba3c39128060c5 Mon Sep 17 00:00:00 2001 From: chumeston Date: Wed, 11 Dec 2024 16:48:32 -0600 Subject: [PATCH] nba(jump ball): cadence * Fix win logic. --- contracts/JumpBall.cdc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/contracts/JumpBall.cdc b/contracts/JumpBall.cdc index 2783500..b7b1d42 100644 --- a/contracts/JumpBall.cdc +++ b/contracts/JumpBall.cdc @@ -129,12 +129,16 @@ access(all) contract JumpBall { let winner: Address if creatorTotal > opponentTotal { - winner = game.creator + // Creator wins + emit WinnerDetermined(gameID: gameID, winner: game.creator) + game.transferAllToWinner(winner: game.creator, winnerCap: winnerCap) } else if opponentTotal > creatorTotal { - winner = game.opponent + // Opponent wins + emit WinnerDetermined(gameID: gameID, winner: game.opponent) + game.transferAllToWinner(winner: game.opponent, winnerCap: winnerCap) } else { // Tie: Return NFTs to their original owners. - emit WinnerDetermined(gameID: gameID, winner: Address(0)) + emit WinnerDetermined(gameID: gameID, winner: Address.zero) let keys = game.nfts.keys for key in keys { let originalOwner = game.ownership[key] ?? panic("Original owner not found for NFT.") @@ -142,11 +146,6 @@ access(all) contract JumpBall { game.returnNFT(nftID: key, owner: depositCap) } } - - emit WinnerDetermined(gameID: gameID, winner: winner) - - // Award NFTs to the winner - game.transferAllToWinner(winner: winner, winnerCap: winnerCap) } }