# A Game Deadline
Make sure you have all you need before proceeding:
- You understand the concepts of Protobuf.
- Have Go installed.
- The checkers blockchain codebase with the game FIFO. You can get there by following the previous steps or checking out the relevant version (opens new window).
In the previous section you introduced a FIFO that keeps the oldest games at its head and the most recently updated games at its tail.
Just because a game has not been updated in a while does not mean that it has expired. To ascertain this you need to add a new field, deadline
, to a game and test against it. Time to prepare the field.
# New information
To prepare the field, add in the StoredGame
's Protobuf definition:
To have Starport and Protobuf recompile this file. You can use:
On each update the deadline will always be now plus a fixed duration. In this context, now refers to the block's time. Declare this duration as a new constant, along with how the date is to be represented, i.e. encoded in the saved game as a string:
# Date manipulation
You can make your life easier by using helper functions that encode and decode the deadline in the storage.
First define a new error:
Now you can add your date helpers. A reasonable location to pick is
full_game.go
:Of note in the above is that
sdkerrors.Wrapf(err, ...)
returnsnil
iferr
isnil
. This is very convenient.Add a function that encapsulates the knowledge of how the next deadline is calculated in the same file:
# Updated deadline
Next you need to update this new field with its appropriate value:
At creation in the message handler for game creation:
And after a move in the message handler:
Now confirm that your project still compiles:
You have created and updated the deadline. The section two steps ahead describes how to use the deadline and the FIFO to expire games that reached their deadline.
Before you can do that there is one other field you need to add. Discover which in the next section.