The final project for this class will be a carnival; in particular:
This project depends on you having a working implementation of MP10. You will need to create that: we will not be releasing an MP10 solution.
Your project code and your MP10 code must both be on your VM prior to the December 16th checkoff.
Initial files are available in project.zip. We provide simple game.py you’ll want to edit.
You’re also welcome to add additional files if you wish; most students will add at least one .html file, and possibly other .py, .html, .css, .js, and .json files.
Each game will be different, but all should conform to the following sequence of events:
Your booth is welcome to add booth-specific displays and user interaction between these steps. That could include having some of the gameplay occur before step 3.
We recommend creating only single-player games for simplicity, but if you want to try for some type of multi-player game that is permitted. Note that if it is multi-player, each player should get a different memo and each player’s experience should follow the above sequence.
The following are optional ideas on how you might approach this project. They are not the only way to do things, and you’re welcome to try a different approach if it suits your booth idea and/or coding style better.
Because this is a browser-based system, some of your code will me in languages we have not taught you (HTML, CSS, and JavaScript), and will not be testing your learning of course concepts. As such, we recommend having AI create these files for you.
Other tips here may mention HTML and JavaScript concepts, primarily to give you vocabulary to use when talking to the AI.
A booth server will need to connect multiple HTTP requests into a single session. At a minimum, these are (a) the initial GET / that loads the game UI and (b) the player’s action in the booth after they pay their tickets.
One way to do this is to have identifying information (such as the memo) included in each subsequent HTTP request the player makes. That would look something like
GET / would return an HTML page that has the memo included.<input type="hidden" value="the memo"> inside an HTML form or adding the memo to the JSON object sent in a fetch.POST endpoint that checks the memo.You can also use other identifying information instead of the memo, such as the hash of a block providing a ticket transfer from which the memo can be extracted.
Another way to implement sessions is to have only one normal HTTP request, then open a WebSocket and have all subsequent information use that. We have a desciption of WebSockets available if you are interested.
The user will need to send tickets to your booth using their wc_agent.py from MP10. That means they’ll need 3 pieces of information:
_b)One way to send this kind of information to the user is to have a static HTML file with placeholder strings like BOOTH inside of it, and then in your @routes.get("/") callback use str’s replace method to replace those parts of that static HTML file for the current user.
Another way to send this kind of information is to have the HTML file use fetch or WebSockets to ask for this information from a separate booth endpoint and then add it to the webpage.
There’s no easy way to query the blockchain to discover if there’s some block with a given dst and memo: you could get the entire /chain and search every block, but that will become time-prohibitive as the blockchain grows.
We recommend that the booth have the user tell the booth the hash of the block that provides the payment. The server can then use /getlive to verify that that block is a precursor to the head and has the correct fields.
This idea would suggest a user experience that includes having two browsers open, with some back-and-forth action between them:
| Order | Booth UI | BlockChain UI |
|---|---|---|
| 1 | booth shows player where to send tickets | |
| 2 | player requests transfer | |
| 3 | blockchain replies both new block’s hash | |
| 4 | player shares the new block’s hash | |
| 5 | booth verifies transfer and shows next part of game |
Your booth will need to create blocks on the blockchain. This should be done as follows:
Run bc_agent.py from MP10 on the same server as your game.
In game.py,
Load the booth name, passcode, and port from the private config file used by bc_agent.py.
Create an HTTP client that uses the bc_agent.py’s host and authentication information, as follows:
auth = aiohttp.BasicAuth(login=USER, password=PASS)
client = aiohttp.ClientSession(f'http://localhost:{PORT}', auth=auth)where
PORT is the port on which bc_agent.py is runningUSER is the booth namePASS is passcode associated with that booth nameWe recommend doing this just once, during asyncstartup, and storing the resulting client inside app, as e.g. app["client"] = client. You can then get to the client from other methods using request.app["client"].
To send tickets, use that authenticating client to send a POST request to the /transfer endpoint, as follows:
async with client.post('/transfer',
json={'dst':PLAYER, 'n':AMOUNT, 'memo':MEMO}
) as resp:
data = await resp.json()
if 'error' in data:
... # the transfer failed; is bc_agent.py running and the USER/PASS correct?
else:
... # the transfer succeededSome of this code is provided in the starter code, though you are free to modify it if you wish.
To test your game, you’ll need at least three concurrently-running aiohttp apps: two blockchain agents (one to be a player, one to be the booth) and your game:
python3 bc_agent.py -v configs/priv_user1.json (the player’s agent)python3 bc_agent.py -v configs/priv_user2.json (the booth’s agent)python3 game.py -v ../mp10/configs/priv_user2.json (the booth’s UI)You’ll also need at least two browsers open: one to the player’s bc_agent.py page https://localhost:34010 and one to your game https://localhost:20258. It might be nice to also having open a blockchain viewer https://localhost:34010/view and refresh it periodically to ensure the correct blocks are being added to the blockchain.
You’ll then need to follow the back-and-forth activity outlined above. If the result is a game with blocks being added
There are no automated tests for the project. It is graded entirely based on how it performs in the in-class checkoff.
The grade will consider the following factors:
We will also provide a means for students to vote on booths you liked (which does not impact grade, only fame) and report booths that are inappropriate or not working properly.