ajuna-network / worker

SubstraTEE worker for SubstraTEE node
Apache License 2.0
8 stars 1 forks source link

Create a new connectfour game in the sgx runtime #9

Closed haerdib closed 2 years ago

haerdib commented 2 years ago

To create a new game, we call into the into sgx-runtime connectfour pallet new_game . Example: https://github.com/ajuna-network/worker/blob/60410d7bf19d80302c1cf1767fd9ca525e9b0c72/app-libs/stf/src/stf_sgx.rs#L187-L193

The function call go create this game is triggered in the detection implemented in #8

haerdib commented 2 years ago

Upon detecting the ack_game extrinsic, we can retrieve the shard and the hash of the games from the extrinsic.

I think it would make it easier, if we create first a TrustedCall and execute it then. The game creation can be done similarly to here: https://github.com/integritee-network/worker/blob/87e8a830716b8ba794c1b9327a9e02014e8694f3/app-libs/stf/src/stf_sgx.rs#L170-L178

To get the Players, needed to create a new game, the parentchain storage needs to be retrieved first: Query the GameRegistry for every game hash in the extrinsic and create a TrustedCall for each and call the Stf::execute.

Example of TrustedCall creation & execution: https://github.com/integritee-network/worker/blob/master/core-primitives/stf-executor/src/executor.rs#L179-L193

To create a new game extrinsic, two player inputs are necessary: https://github.com/ajuna-network/ajuna-node/blob/update-substrate-5/pallets/ajuna-connectfour/src/lib.rs#L264-L265

I hope that helps a little.