Skip to content

Commit

Permalink
Document new AsyncAPI and JSON-RPC endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Aug 7, 2024
1 parent a5d5faf commit 9f6fa93
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/home/1-setup/4-environment-config-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ These these variables are used if you only need to synchronize a single network

- [Primitive Catalogue](../100-state-machine/300-react-to-events/10-primitive-catalogue/1-introduction.md):
- `DEFAULT_PRESYNC_STEP_SIZE`: number of blocks to process in each step during initial presync phase. If not provided, a value of 1000 is used. Generally no need to change this value.
- `CDE_CONFIG_PATH`: allows you to specify a custom location for your `extensions.yml` that is used to initialize primitive catalogue entries
- `CDE_CONFIG_PATH`: allows you to specify a custom location for your `extensions.$NETWORK.yml` that is used to initialize primitive catalogue entries
- Cardano extensions
- `CARP_URL`: The URL of a Carp instance, required when using Cardano primitives.
- `CARDANO_NETWORK`: One of `preview`, `preprod`, `mainnet`. It needs to match the network indexed by the Carp instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Paima Engine currently supports many different kinds of primitives that you can

## Configuration

To specify which Primitives you are using for your game, you need to provide a configuration file. By default, a file named `extensions.yml` in your root directory (same place as the `.env` file) is expected, but you may adjust this path using the `CDE_CONFIG_PATH` environment variable.
To specify which Primitives you are using for your game, you need to provide a configuration file. By default, a file named `extensions.yml` in your root directory (same place as the `.env` file) is expected, but you may adjust this path using the `CDE_CONFIG_PATH` environment variable. We recommend using `extensions.$NETWORK.yml` to have different files depending on which network you're deploying your rollup to (ex: `localhost` or `mainnet`)

Here is an example `extensions.yml` that you can copy paste into the root folder of your project:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variables (learn more [here](../../../1-setup/4-environment-config-values.md))

The format of the config file is a yaml object mapping of a network name to the
config object. The name is used then in the `extensions.yml` configuration in
order to associate Paima Primitives with a particular network.
order to associate Paima Primitives with a particular network. You can use `extensions.$NETWORK.yml` to have different extension files for different deployments (ex: `localhost` or `mainnet`)

Each entry should have a `type` variable, which can be one of
- `evm-main`
Expand Down
30 changes: 26 additions & 4 deletions docs/home/350-game-node-api/1-introduction.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
# Basic Concepts

Games need to communicate not just with their UI, but also the rest of the web2 world that may want to interact with the game state.
Games need to communicate not just with their UI, but also the rest of the web2 world that may want to interact with the game state. Paima exposes multiple different endpoints to help both with humans and tools to access the game state.

## OpenAPI
## (REST) OpenAPI

To achieve this, Paima Engine comes with support for [OpenAPI](https://www.openapis.org/) so humans can easily interact with the node and can easily generate client libraries for games in a variety of languages. After starting your node, visit `http://localhost:3333/docs/` to see all the endpoints.
Paima Engine comes with support for [OpenAPI](https://www.openapis.org/) in two ways:
- (for humans) `http://localhost:3333/docs/rest/ui` to visually see the REST API generated for the node
- (for robots) `http://localhost:3333/docs/rest/spec.json` to access the OpenAPI specification for the node

To have your game's OpenAPI definition also show up in the docs, simply place an `openapi.json` file inside the `packaged` folder generated by your game, and Paima will automatically detect it.
Notably, the specification can be combined with tools like [openapi-typescript](https://www.npmjs.com/package/openapi-typescript) to generate a typescript library for your application.

To have your game's OpenAPI definition also show up in the docs, simply place an `openapi.json` file inside the `packaged` folder generated by your game, and Paima will automatically detect it (this is done automatically for you in the Paima game templates)

## (MQTT) AsyncAPI

Paima Engine comes with support for [AsyncAPI](https://www.asyncapi.com/) in two ways:
- (for humans) `http://localhost:3333/docs/asyncapi/ui` to visually see the AsyncAPI generated for the node
- (for robots) `http://localhost:3333/docs/asyncapi/spec.yml` to access the AsyncAPI specification for the node

You don't typically have to interact with the specification directly, as you typically interact with these through the [event log system](../100-state-machine/325-creating-events/100-events/100-general-interface.md)

## (JSON-RPC) EVM RPC API

Some tools only support the [EVM JSON-RPC specification](https://eips.ethereum.org/EIPS/eip-1474). Since Paima applications are non-EVM in nature (they aggregate multiple stacks, some of which might not even be EVM at all), it doesn't support this specification fully.

However, Paima nodes expose a EVM RPC wrapper API that tries its best to emulate the same behavior as EVM.

You can access the wrapper API at `http://localhost:3333/rpc/evm`

*NOTE*: this feature is still experimental, and we will update which endpoints work and which ones don't as well as subtle differences at a later time


8 changes: 8 additions & 0 deletions docs/home/600-releasing-a-game/3-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,12 @@ local $> rsync -r build/* [email protected]:/var/www/html/my-game-frontend

The server will generate backups, we recommend you keep them in a safe place, outside this same server to recover your state at any time.

#### Reset the database

If you need to wipe the database to reset from scratch, you can use the following

```bash
docker compose --env-file=.env.testnet down
docker volume rm my-game-db
docker compose --env-file=.env.testnet up -d
```

0 comments on commit 9f6fa93

Please sign in to comment.