Explain solidity>credits system

Credits System

If Player O never accepts, Player X should be able to cancel and get their stake back.

Tracking Credits:

First, add a mapping that stores how much ETH each address can withdraw:

mapping(address => uint256) public credits;

A mapping is a key-value store. Here the key is a player address and the value is the amount owed.

The next lesson uses this same mapping to build the withdraw function.



Cancel Requirements:

Only Player X can cancel:

require(msg.sender == playerX, "Only starter can cancel");

The accept deadline must have passed:

require(block.timestamp > acceptDeadline, "Accept period not expired");

Game hasn't been accepted yet:

require(!gameAccepted, "Game already accepted");



Refunding the Stake:

We'll use a credits system for safety. Store the refund amount:

credits[playerX] += stake;

Then reset the game state:

stake = 0;
gameActive = false;

Then create the cancelUnaccepted() function.

Add cancel and credits system
0%
0 of 9 requirements passed.
Requirements:
Declares credits mapping
Declares cancelUnaccepted function
cancelUnaccepted is public
Checks msg.sender is playerX
Checks deadline expired
Checks game not accepted
Credits playerX the stake
Resets stake to 0
Resets gameActive to false