┌───────────Frontend ──────────┐
│ │
│ │
┌──────────────────► execute fetch ◄────────────────────┐
│ │
│ │ │ │
│ └──────────────────────────────┘ │
│ │
│ ┌───────────Contract────────┐ ┌────Checkpoint─────────────┐ |
│ │ │ │ │ ▲
▼ │ │ │
O────act(state, action) │ │ database ────►graphql────O
│ │ │ ▲
│ │ │ │ │ │ │
│ . internal_state │ │ │ │ │
│ N ▲ │ │ │ │ │
│ . │ │ │ │ │ │ │
│ │ ▼ │ │ ▼ │
│ └─► methodN ────► eventN - - - ─► handleEventN │
│ │ │ │
└───────────────────────────┘ └───────────────────────────┘
Pedersen are pretty cheap. Bitwise are pretty expensive. Storing the moves end figuring out the state dynamically is a bad idea, because many bitwise operations would be needed. A FEN can be packed into a single felt, but decoding it would take many bitwise operations. It's cheaper to pass the state with unpacked felts as an argument.
Format is the following:
- game id
- white address
- black address
- governor address
- white draw request
- black draw request
- felt stating the number of FENs following it
- An array of FENs. Each FEN takes 72 felts. The first one corresponds to the initial state, and all the others are the resultant state after a move.
First felt is action type, everything else is dependant on the action type.
- create_game
- move
- surrender
- offer_draw
- force_threefold_draw
- force_fifty_moves_draw
- write_result
- force_result
Per action type, listed below their inputs and outputs.
Pass the state as with the other functions, but ommitting the first felt for game_id
.
[]
[game_id]
[as_player, only_check, start_y, start_x, end_y, end_x, extra]
[is_valid]
[as_player]
[result]
[as_player]
[result]
[as_player, a, b]
[result]
[as_player]
[result]
[]
[result]
[result]
[result]
You use events to handle off-chain state availability. They always include game_id
as their first argument, and then include other data.
Can you pass arrays to events?
create_game_called(game_id, state_len, state)
move
is the Move
struct.
move_called(game_id, move)
surrender_called(game_id, as_player)
offer_draw_called(game_id, as_player)
force_threefold_draw_called(game_id)
force_fifty_moves_draw_called(game_id)
write_result_called(game_id, result)
force_result(game_id, result)