With the introduction of game expiry in the previous section and other features, you have now addressed the cases when two players start a game and finish it, or let it expire.
In this section, you will go one step closer to adding an extra layer to a game, with wagers or stakes. Your application already includes all the necessary modules.
Players choose to wager money or not, and the winner gets both wagers. The forfeiter loses their wager. To reduce complexity, start by letting players wager in the staking token of your application.
Now that no games can be left stranded, it is possible for players to safely wager on their games. How could this be implemented?
When thinking about implementing a wager on games, ask:
What form will a wager take?
Who decides on the amount of wagers?
Where is a wager recorded?
At what junctures do you need to handle payments, refunds, and wins?
This is a lot to go through. Therefore, the work is divided into three sections. In this first section, you only add new information, while the second section is where the tokens are actually handled, and in the third section you add integration tests.
Some answers:
Even if only as a start, it makes sense to let the game creator decide on the wager.
It seems reasonable to save this information in the game itself so that wagers can be handled at any point in the lifecycle of the game.
Modify the constructor among the interface definition of MsgCreateGame in x/checkers/types/message_create_game.go to avoid surprises:
Copy
-funcNewMsgCreateGame(creator string, black string, red string)*MsgCreateGame {+funcNewMsgCreateGame(creator string, black string, red string, wager uint64)*MsgCreateGame {return&MsgCreateGame{...+ Wager: wager,}} x checkers types message_create_game.go View source
This confirms what you expected with regards to the command-line interactions.
synopsis
To summarize, this section has explored:
How to add the new "wager" value, modify the "create a game" message to allow players to choose the wager they want to make, and add a helper function.
How to save the wager and adjust an event, modifying the create game handler.
How to minimally adjust unit tests.
How to interact via the CLI to check that wager values are being recorded.