Skip to content

Commit

Permalink
feat(examples): use namespace override for ChatNamespacedSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1a committed May 23, 2023
1 parent 7c4c3f4 commit ac6cf61
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 20 deletions.
8 changes: 4 additions & 4 deletions examples/minimal/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export default mudConfig({
name: "increment",
openAccess: true,
},
ChatNamespacedSystem: {
namespace: "namespace",
openAccess: true,
},
},
excludeSystems: [
// Until namespace overrides, this system must be manually deployed in PostDeploy
"ChatNamespacedSystem",
],
tables: {
CounterTable: {
schema: {
Expand Down
9 changes: 3 additions & 6 deletions examples/minimal/packages/contracts/script/PostDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity >=0.8.0;
import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { ResourceSelector } from "@latticexyz/world/src/ResourceSelector.sol";
import { Systems } from "@latticexyz/world/src/modules/core/tables/Systems.sol";
import { IWorld } from "../src/codegen/world/IWorld.sol";

import { MessageTable, MessageTableTableId } from "../src/codegen/Tables.sol";
Expand All @@ -17,15 +18,11 @@ contract PostDeploy is Script {
// Start broadcasting transactions from the deployer account
vm.startBroadcast(deployerPrivateKey);

// Manually deploy a system with another namespace
ChatNamespacedSystem chatNamespacedSystem = new ChatNamespacedSystem();
IWorld(worldAddress).registerSystem("namespace", "ChatNamespaced", chatNamespacedSystem, true);
IWorld(worldAddress).registerFunctionSelector("namespace", "ChatNamespaced", "sendMessage", "(string)");
// Grant this system access to MessageTable
// Grant a system with an overridden namespace access to MessageTable
IWorld(worldAddress).grantAccess(
ResourceSelector.getNamespace(MessageTableTableId),
ResourceSelector.getName(MessageTableTableId),
address(chatNamespacedSystem)
Systems.getSystem(IWorld(worldAddress), ResourceSelector.from("namespace", "ChatNamespacedSy"))
);

// ------------------ EXAMPLES ------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

/* Autogenerated file. Do not edit manually. */

interface IChatNamespacedSystem {
function namespace_ChatNamespacedSy_sendMessage(string memory message) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity >=0.8.0;

import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol";

import { IChatNamespacedSystem } from "./IChatNamespacedSystem.sol";
import { IChatSystem } from "./IChatSystem.sol";
import { IIncrementSystem } from "./IIncrementSystem.sol";
import { IInventorySystem } from "./IInventorySystem.sol";
Expand All @@ -14,6 +15,6 @@ import { IStructSystem } from "./IStructSystem.sol";
* The IWorld interface includes all systems dynamically added to the World
* during the deploy process.
*/
interface IWorld is IBaseWorld, IChatSystem, IIncrementSystem, IInventorySystem, IStructSystem {
interface IWorld is IBaseWorld, IChatNamespacedSystem, IChatSystem, IIncrementSystem, IInventorySystem, IStructSystem {

}

This file was deleted.

4 changes: 2 additions & 2 deletions examples/minimal/packages/contracts/test/ChatNamespaced.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";
import { MessageTable, MessageTableTableId } from "../src/codegen/Tables.sol";
import { IChatNamespacedSystem } from "../src/interfaces/IChatNamespacedSystem.sol";
import { IChatNamespacedSystem } from "../src/codegen/world/IChatNamespacedSystem.sol";

contract ChatNamespacedTest is MudV2Test {
function testEmitEphemeral() public {
bytes32[] memory keyTuple;
vm.expectEmit(true, true, true, true);
emit StoreCore.StoreEphemeralRecord(MessageTableTableId, keyTuple, MessageTable.encode("test"));
IChatNamespacedSystem(worldAddress).namespace_ChatNamespaced_sendMessage("test");
IChatNamespacedSystem(worldAddress).namespace_ChatNamespacedSy_sendMessage("test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface IWorldInterface extends utils.Interface {
"installModule(address,bytes)": FunctionFragment;
"installRootModule(address,bytes)": FunctionFragment;
"isStore()": FunctionFragment;
"namespace_ChatNamespacedSy_sendMessage(string)": FunctionFragment;
"pickUp(uint32,uint32)": FunctionFragment;
"popFromField(bytes16,bytes16,bytes32[],uint8,uint256)": FunctionFragment;
"popFromField(bytes32,bytes32[],uint8,uint256)": FunctionFragment;
Expand Down Expand Up @@ -108,6 +109,7 @@ export interface IWorldInterface extends utils.Interface {
| "installModule"
| "installRootModule"
| "isStore"
| "namespace_ChatNamespacedSy_sendMessage"
| "pickUp"
| "popFromField(bytes16,bytes16,bytes32[],uint8,uint256)"
| "popFromField(bytes32,bytes32[],uint8,uint256)"
Expand Down Expand Up @@ -249,6 +251,10 @@ export interface IWorldInterface extends utils.Interface {
values: [PromiseOrValue<string>, PromiseOrValue<BytesLike>]
): string;
encodeFunctionData(functionFragment: "isStore", values?: undefined): string;
encodeFunctionData(
functionFragment: "namespace_ChatNamespacedSy_sendMessage",
values: [PromiseOrValue<string>]
): string;
encodeFunctionData(
functionFragment: "pickUp",
values: [PromiseOrValue<BigNumberish>, PromiseOrValue<BigNumberish>]
Expand Down Expand Up @@ -527,6 +533,10 @@ export interface IWorldInterface extends utils.Interface {
data: BytesLike
): Result;
decodeFunctionResult(functionFragment: "isStore", data: BytesLike): Result;
decodeFunctionResult(
functionFragment: "namespace_ChatNamespacedSy_sendMessage",
data: BytesLike
): Result;
decodeFunctionResult(functionFragment: "pickUp", data: BytesLike): Result;
decodeFunctionResult(
functionFragment: "popFromField(bytes16,bytes16,bytes32[],uint8,uint256)",
Expand Down Expand Up @@ -849,6 +859,11 @@ export interface IWorld extends BaseContract {

isStore(overrides?: CallOverrides): Promise<[void]>;

namespace_ChatNamespacedSy_sendMessage(
message: PromiseOrValue<string>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;

pickUp(
item: PromiseOrValue<BigNumberish>,
itemVariant: PromiseOrValue<BigNumberish>,
Expand Down Expand Up @@ -1171,6 +1186,11 @@ export interface IWorld extends BaseContract {

isStore(overrides?: CallOverrides): Promise<void>;

namespace_ChatNamespacedSy_sendMessage(
message: PromiseOrValue<string>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;

pickUp(
item: PromiseOrValue<BigNumberish>,
itemVariant: PromiseOrValue<BigNumberish>,
Expand Down Expand Up @@ -1491,6 +1511,11 @@ export interface IWorld extends BaseContract {

isStore(overrides?: CallOverrides): Promise<void>;

namespace_ChatNamespacedSy_sendMessage(
message: PromiseOrValue<string>,
overrides?: CallOverrides
): Promise<void>;

pickUp(
item: PromiseOrValue<BigNumberish>,
itemVariant: PromiseOrValue<BigNumberish>,
Expand Down Expand Up @@ -1858,6 +1883,11 @@ export interface IWorld extends BaseContract {

isStore(overrides?: CallOverrides): Promise<BigNumber>;

namespace_ChatNamespacedSy_sendMessage(
message: PromiseOrValue<string>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<BigNumber>;

pickUp(
item: PromiseOrValue<BigNumberish>,
itemVariant: PromiseOrValue<BigNumberish>,
Expand Down Expand Up @@ -2181,6 +2211,11 @@ export interface IWorld extends BaseContract {

isStore(overrides?: CallOverrides): Promise<PopulatedTransaction>;

namespace_ChatNamespacedSy_sendMessage(
message: PromiseOrValue<string>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<PopulatedTransaction>;

pickUp(
item: PromiseOrValue<BigNumberish>,
itemVariant: PromiseOrValue<BigNumberish>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,19 @@ const _abi = [
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "string",
name: "message",
type: "string",
},
],
name: "namespace_ChatNamespacedSy_sendMessage",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
Expand Down

0 comments on commit ac6cf61

Please sign in to comment.