Skip to content

Commit

Permalink
docs: change namespaced function signatures (#2167)
Browse files Browse the repository at this point in the history
  • Loading branch information
qbzzt authored Jan 22, 2024
1 parent 0f27afd commit 0cc3d71
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions docs/pages/guides/extending-world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ The easiest way to create the Solidity code is to use the MUD template:

Register `MessageSystem.incrementMessage(string)`.
This step is necessary to make the function accessible through the `World`.
The function's name when accessed through the world is `<namespace>_<system>_<function>`, so this function will be available as `messaging_message_incrementMessage(string)`.
The function's name when accessed through the world is `<namespace>__<function>`, so this function will be available as `messaging__incrementMessage(string)`.

**Note:** This is the case for all namespaces except for the root namespace, where we just use the name of the function (such as `increment()`).

Expand All @@ -401,10 +401,10 @@ The easiest way to create the Solidity code is to use the MUD template:

```sh copy
source .env
cast send $WORLD_ADDRESS --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY "messaging_MessageSystem_incrementMessage(string)" "hello"
cast send $WORLD_ADDRESS --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY "messaging__incrementMessage(string)" "hello"
```

When a function is _not_ in the root namespace, it is accessible as `<namespace>_<system>_<function name>` (as long as it is [registered](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol#L164-L201)).
When a function is _not_ in the root namespace, it is accessible as `<namespace>__<function name>` (as long as it is [registered](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol#L164-L201)).

Here we call our `incrementMessage(string)` with the parameter `hello`.

Expand Down Expand Up @@ -561,7 +561,7 @@ We will fix these problems now.

### Increment and send a message

Edit `src/mud/createSystemCalls.ts` to use the new `messaging_MessageSystem_incrementMessage` function instead of `increment`.
Edit `src/mud/createSystemCalls.ts` to use the new `messaging__incrementMessage` function instead of `increment`.

<CollapseCode>

Expand Down Expand Up @@ -608,7 +608,7 @@ Edit `src/mud/createSystemCalls.ts` to use the new `messaging_MessageSystem_incr
* is in the root namespace, `.increment` can be called directly
* on the World contract.
*/
const tx = await worldContract.write.messaging_MessageSystem_incrementMessage(
const tx = await worldContract.write.messaging__incrementMessage(
[`message at ${Date()}`]);
await waitForTransaction(tx);
return getComponentValue(Counter, singletonEntity);
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/world/function-selectors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If [you have the necessary delegation](/world/account-delegation) you can also u

To improve the developer experience of calling `System` functions, the namespace owner can register a function selector for each `System` function in the `World` contract.
This removes the need for the caller to know the system's `ResourceId`, and the need to manually encode the calldata via `abi.encodeCall`.
Once the namespace owner registers a function selector for a `System` function, anybody can call the `System` via `<World>.<namespace>_<system>_<function>(<args>)`.
Once the namespace owner registers a function selector for a `System` function, anybody can call the `System` via `<World>.<namespace>__<function>(<args>)`.

To register a function selector, you use [`<world>.registerFunctionSelector`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol#L164-L201).
This function takes two parameters:
Expand All @@ -34,7 +34,7 @@ This is the code we use to register the `System` and the function selector:
After the function selector is registered, it can be accessed directly on the World:

```solidity
world.messaging_message_incrementMessage("hello");
world.messaging__incrementMessage("hello");
```

## Root function selectors
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/world/systems.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The `World` serves as a central entry point and forwards calls to systems, which

To call a `System`, you call the `World` in one of these ways:

- If a [function selector for the `System` is registered in the `World`](./function-selectors), you can call it via `world.<namespace>_<system>_<function>(<arguments>)`.
- If a [function selector for the `System` is registered in the `World`](./function-selectors), you can call it via `world.<namespace>__<function>(<arguments>)`.
- You can use [`call`](https://github.com/latticexyz/mud/blob/main/packages/world/src/World.sol#L346-L351).
- If you have [the proper delegation](/world/account-delegation) you can use [`callFrom`](https://github.com/latticexyz/mud/blob/main/packages/world/src/World.sol#L353-L394).

Expand Down
4 changes: 2 additions & 2 deletions docs/pages/world/world-table-illustration.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Interaction between the `World`, a `System`, and a table](./world-table.svg)

1. An account calls a function called `namespace_system_function` via the `World`.
[This function was registered](./function-selectors) by the owner of the `namespace` namespace and points to the `function` function in the `system` system in the `namespace` namespace.
1. An account calls a function called `namespace__function` via the `World`.
[This function was registered](./function-selectors) by the owner of the `namespace` namespace and points to the `function` function in one of the `System`s in the `namespace` namespace.

2. The `World` verifies that access is permitted (for example, because `namespace:system` is publicly accessible) and if so calls `function` on the `namespace:system` contract with the provided parameters.

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/world/world-table.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0cc3d71

Please sign in to comment.