-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
132 additions
and
85 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
examples/minimal/packages/contracts/src/codegen/world/IDoubleSystem.sol
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
examples/minimal/packages/contracts/src/codegen/world/IWorld.sol
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
examples/minimal/packages/contracts/src/systems/DoubleSystem.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.21; | ||
import { console } from "forge-std/console.sol"; | ||
import { System } from "@latticexyz/world/src/System.sol"; | ||
import { CounterTable } from "../codegen/index.sol"; | ||
|
||
contract DoubleSystem is System { | ||
function double() public returns (uint32) { | ||
uint32 counter = CounterTable.get(); | ||
uint32 newValue = counter * 2; | ||
CounterTable.set(newValue); | ||
return newValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Client, Transport, Chain, Account, Hex, getFunctionSelector } from "viem"; | ||
import { hexToResource, writeContract } from "@latticexyz/common"; | ||
import { System, WorldDeploy, WorldFunction, worldAbi } from "./common"; | ||
import { debug } from "./debug"; | ||
import { getFunctions } from "./getFunctions"; | ||
|
||
export async function ensureFunctions({ | ||
client, | ||
worldDeploy, | ||
functions, | ||
}: { | ||
client: Client<Transport, Chain | undefined, Account>; | ||
worldDeploy: WorldDeploy; | ||
functions: WorldFunction[]; | ||
}): Promise<Hex[]> { | ||
const worldFunctions = await getFunctions({ client, worldDeploy }); | ||
const worldSelectorToFunction = Object.fromEntries(worldFunctions.map((func) => [func.selector, func])); | ||
|
||
const toSkip = functions.filter((func) => worldSelectorToFunction[func.selector]); | ||
const toAdd = functions.filter((func) => !toSkip.includes(func)); | ||
|
||
if (toSkip.length) { | ||
debug("functions already registered:", toSkip.map((func) => func.signature).join(", ")); | ||
const wrongSystem = toSkip.filter((func) => func.systemId !== worldSelectorToFunction[func.selector]?.systemId); | ||
if (wrongSystem.length) { | ||
console.warn( | ||
"found", | ||
wrongSystem.length, | ||
"functions already registered but pointing at a different system ID:", | ||
wrongSystem.map((func) => func.signature).join(", ") | ||
); | ||
} | ||
} | ||
|
||
if (!toAdd.length) return []; | ||
|
||
debug("registering functions:", toAdd.map((func) => func.signature).join(", ")); | ||
|
||
return Promise.all( | ||
toAdd.map((func) => { | ||
const { namespace } = hexToResource(func.systemId); | ||
if (namespace === "") { | ||
return writeContract(client, { | ||
chain: client.chain ?? null, | ||
address: worldDeploy.address, | ||
abi: worldAbi, | ||
// TODO: replace with batchCall | ||
functionName: "registerRootFunctionSelector", | ||
// TODO: why do we have to specify the selector here? | ||
args: [func.systemId, func.systemFunctionSignature, func.systemFunctionSelector], | ||
}); | ||
} | ||
return writeContract(client, { | ||
chain: client.chain ?? null, | ||
address: worldDeploy.address, | ||
abi: worldAbi, | ||
// TODO: replace with batchCall | ||
functionName: "registerFunctionSelector", | ||
args: [func.systemId, func.systemFunctionSignature], | ||
}); | ||
}) | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters