Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"node",
"runtime",
"wallet",
"game",
"toolkit/partner-chains-cli",
"toolkit/cli/commands",
"toolkit/cli/node-commands",
Expand Down Expand Up @@ -76,6 +77,8 @@ zero-prefixed-literal = { level = "allow", priority = 2 } # 00_1000_0
griffin-core = { default-features = false, path = "griffin-core" }
griffin-partner-chains-runtime = { path = "./runtime", default-features = false }
griffin-rpc = { default-features = false, path = "griffin-rpc" }
griffin-wallet = { default-features = false, path = "wallet" }
game = { default-features = false, path = "game" }
clap = { version = "4.5.13" }
derive-new = { version = "0.7.0" }
docify = { version = "0.2.9" }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This repository will contain a reference implementation of a Substrate partnerch

- [Start a chain with docker](#build-and-run-with-docker)

- [Use-case: Asteria game]()
- [Use-case: Asteria game](#use-case-asteria-game)

- [Setting up a partner chain](#setting-up-a-partner-chain)

Expand Down Expand Up @@ -92,7 +92,7 @@ Make sure that the endpoint you are connecting to matches the node's being run i
## Use-case: Asteria game

As the result of the discovery process, after surveying many developers, it was decided that the use case for the partnerchain reference implementation would be a game. We chose the game Asteria which consists of ships moving across a board to find the Asteria prize and collect a portion of it.
In this repository we include the [on-chain code](./game/onchain/), which comes with a [design document](./game/onchain/docs/design/design.md) that thoroughly explains the transactions involved in the game.
In this repository we include the [on-chain code](./game/onchain/), which comes with a [design document](./game/onchain/docs/design/design.md) that thoroughly explains the transactions involved in the game. In the game [src](./game/src/) you can find the implementation of the commands necessary to play the game and [detailed instructions](./game/README.md) on how to run them.

## Setting up a Partner Chain

Expand Down
24 changes: 24 additions & 0 deletions game/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "game"
description = "Game implementation"
version = "0.1.0"
repository.workspace = true
edition.workspace = true

[dependencies]
anyhow = { workspace = true }
clap = { features = ["derive"], workspace = true }
griffin-core = { workspace = true }
griffin-wallet = { workspace = true }
hex = { workspace = true }
jsonrpsee = { workspace = true }
log = { workspace = true }
parity-scale-codec = { workspace = true }
sc-cli = { workspace = true }
sc-keystore = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sp-core ={ workspace = true }
sp-runtime ={ workspace = true }

sled = "0.34.7"
107 changes: 107 additions & 0 deletions game/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Game: Asteria

As part of the discovery process, it was decided that the use case for the partnerchain reference implementation would be a game. We decided on implementing Asteria which is a simple game about that showcases the capabilities of the eUTxO model.
The game consists of ships moving across a two-dimension grid to find the Asteria, which holds a prize pool that the players can redeem a portion of. In the grid there are also pellets that hold fuel for the ships to collect. The operations of the game are: create a ship, move a ship, gather fuel and mine asteria.

The game is implemented through commands that build the transactions for each operation. A more in depth explanation of the game can be found in the [design document](./onchain/docs/design/design.md).

## Game usage

Each of the following actions must be run with a running instance of the node.

### Deploy Scripts

This command reads all the script parameters from `game/src/deploy_params.json` and applies them to the generic (parameterized)
scripts, writing the resulting ones in their respective files, inside the `scripts` directory.

```console
./target/release/griffin-partner-chains-node game deploy-scripts
--params <SCRIPTS_PARAMS_PATH>
```

#### Arguments details:

*params*: path to the json file containing all the script parameters.

### Create Ship

This command creates the player’s Ship. The transaction also mints the initial ship’s fuel, the ship and pilot tokens, and pays an inscription fee that is added to the total prize in the Asteria UTxO. The pilot token goes back to the wallet input owner, and serves as a proof of the ownership of the Ship.

```console
./target/release/griffin-partner-chains-node game create-ship
--input <WALLET_OUTPUT_REF>
--witness <PUBLIC_KEY>
--pos-x <POS_X>
--pos-y <POS_Y>
--ttl <TIME_TO_LIVE>
```
#### Arguments details:

- *input*: a wallet input that must be consumed to pay for the minimal amount of coin in the Ship output and the fee added to the Asteria accumulated rewards.
- *witness*: public key of the input owner. If omitted, Shawn’s pub key is the default value, since this makes it easier to test transactions in a `dev` environment.
- *pos-x*: initial “x” coordinate of the Ship output.
- *pos-y*: initial “y” coordinate of the Ship output.
- *ttl*: the transaction’s time-to-live. The resulting POSIX time of the validity interval is used to set the initial `last-move-latest-time` field in the Ship output datum.

### Gather Fuel

This command moves fuel tokens from a pellet UTxO to a ship UTxO, only if they have the same position in the grid, as specified in the datums. The amount of fuel to gather is specified in the redeemer, and the total ship fuel must not exceed its maximum capacity.

```console
./target/release/griffin-partner-chains-node game gather-fuel
--ship <SHIP_OUTPUT_REF>
--pellet <PELLET_OUTPUT_REF>
--witness <PUBLIC_KEY>
--fuel <FUEL_AMOUNT>
--validity-interval-start <VALIDITY_INTERVAL_START>
```

#### Arguments details:

- *ship*: reference to the ship UTxO.
- *pellet*: reference to the pellet UTxO.
- *witness*: public key of the pilot token owner. This is necessary since the pilot UTxO must be provided as input to prove the ship ownership. If omitted, Shawn’s pub key is the default value.
- *fuel*: the amount of fuel to transfer from the pellet to the ship.
- *validity-interval-start*: start of the transaction’s validity interval. The corresponding POSIX must be greater than the `last-move-latest-time` field in the ship datum, in order to respect the speed limit of the last move.

### Move Ship

This command moves the ship to a different point in the grid (updates de `pos_x` and `pos_y` fields in the ship datum). The transaction also burns the fuel tokens consumed.

```console
./target/release/griffin-partner-chains-node game move-ship
--ship <SHIP_OUTPUT_REF>
--witness <PUBLIC_KEY>
--pos-x <POS_X>
--pos-y <POS_Y>
--validity-interval-start <VALIDITY_INTERVAL_START>
--ttl <TIME_TO_LIVE>
```

#### Arguments details:

- *ship*: reference to the ship UTxO.
witness: public key of the pilot token owner. This is necessary since the pilot UTxO must be provided as input to prove the ship ownership. If omitted, Shawn’s pub key is the default value.
- *pos-x*: new “x” coordinate of the ship.
- *pos-y*: new “y” coordinate of the ship.
- *validity-interval-start*: start of the transaction’s validity interval. The corresponding POSIX must be greater than the `last-move-latest-time` field in the ship datum, in order to respect the speed limit of the last move.
- *ttl*: the transaction’s time-to-live. The resulting POSIX time of the validity interval is used to set the initial `last-move-latest-time` field in the Ship output datum. The manhattan distance travelled divided by the POSIX validity range must be less or equal to the max speed.

### Mine Asteria

This command can be triggered when the ship reaches Asteria, i.e., its coordinates are both zero. Then the ship owner can receive a percentage of the total prize given by (MAX_ASTERIA_MINING/100). This transaction also burns the ship and all remaining fuel tokens.

```console
./target/release/griffin-partner-chains-node game mine-asteria
--ship <SHIP_OUTPUT_REF>
--witness <PUBLIC_KEY>
--validity-interval-start <VALIDITY_INTERVAL_START>
```

#### Arguments details:

- *ship*: reference to the ship UTxO.
- *witness*: public key of the pilot token owner. This is necessary since the pilot UTxO must be provided as input to prove the ship ownership. If omitted, Shawn’s pub key is the default value.
- *validity-interval-start*: start of the transaction’s validity interval. The corresponding POSIX must be greater than the `last-move-latest-time` field in the ship datum, in order to respect the speed limit of the last move.


14 changes: 14 additions & 0 deletions game/src/deploy_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"admin_policy": "516238dd0a79bac4bebe041c44bad8bf880d74720733d2fc0d255d28",
"admin_name": "asteriaAdmin",
"fuel_per_step": 1,
"initial_fuel": 30,
"max_speed": {
"distance": 1,
"time": 30000
},
"max_ship_fuel": 100,
"max_asteria_mining": 50,
"min_asteria_distance": 10,
"ship_mint_lovelace_fee": 3000000
}
1,237 changes: 1,237 additions & 0 deletions game/src/game.rs

Large diffs are not rendered by default.

Loading