-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
continue refactoring namespace+name to resource selector
- Loading branch information
Showing
12 changed files
with
153 additions
and
141 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
packages/world/src/interfaces/IWorldRegistrationSystem.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,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
/* Autogenerated file. Do not edit manually. */ | ||
|
||
import { ISystemHook } from "./ISystemHook.sol"; | ||
import { System } from "./../System.sol"; | ||
|
||
interface IWorldRegistrationSystem { | ||
function registerNamespace(bytes16 namespace) external; | ||
|
||
function registerSystemHook(bytes32 resourceSelector, ISystemHook hook) external; | ||
|
||
function registerSystem(bytes32 resourceSelector, System system, bool publicAccess) external; | ||
|
||
function registerFunctionSelector( | ||
bytes32 resourceSelector, | ||
string memory systemFunctionName, | ||
string memory systemFunctionArguments | ||
) external returns (bytes4 worldFunctionSelector); | ||
|
||
function registerRootFunctionSelector( | ||
bytes32 resourceSelector, | ||
bytes4 worldFunctionSelector, | ||
bytes4 systemFunctionSelector | ||
) external returns (bytes4); | ||
} |
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
89 changes: 89 additions & 0 deletions
89
packages/world/src/modules/core/implementations/StoreRegistrationSystem.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,89 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
import { IStoreHook } from "@latticexyz/store/src/IStore.sol"; | ||
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; | ||
import { Schema } from "@latticexyz/store/src/Schema.sol"; | ||
|
||
import { System } from "../../../System.sol"; | ||
import { ResourceSelector } from "../../../ResourceSelector.sol"; | ||
import { Resource } from "../../../Types.sol"; | ||
import { ROOT_NAMESPACE, ROOT_NAME } from "../../../constants.sol"; | ||
import { AccessControl } from "../../../AccessControl.sol"; | ||
import { Call } from "../../../Call.sol"; | ||
import { NamespaceOwner } from "../../../tables/NamespaceOwner.sol"; | ||
import { ResourceAccess } from "../../../tables/ResourceAccess.sol"; | ||
import { ISystemHook } from "../../../interfaces/ISystemHook.sol"; | ||
import { IWorldErrors } from "../../../interfaces/IWorldErrors.sol"; | ||
|
||
import { ResourceType } from "../tables/ResourceType.sol"; | ||
import { SystemHooks } from "../tables/SystemHooks.sol"; | ||
import { SystemRegistry } from "../tables/SystemRegistry.sol"; | ||
import { Systems } from "../tables/Systems.sol"; | ||
import { FunctionSelectors } from "../tables/FunctionSelectors.sol"; | ||
|
||
import { CORE_SYSTEM_NAME } from "../constants.sol"; | ||
|
||
import { WorldRegistrationSystem } from "./WorldRegistrationSystem.sol"; | ||
|
||
/** | ||
* Functions related to registering table resources in the World. | ||
*/ | ||
contract StoreRegistrationSystem is System, IWorldErrors { | ||
using ResourceSelector for bytes32; | ||
|
||
/** | ||
* Register a table with given schema in the given namespace | ||
*/ | ||
function registerTable( | ||
bytes32 resourceSelector, | ||
Schema keySchema, | ||
Schema valueSchema, | ||
string[] calldata keyNames, | ||
string[] calldata fieldNames | ||
) public virtual { | ||
// Require the name to not be the namespace's root name | ||
if (resourceSelector.getName() == ROOT_NAME) revert InvalidSelector(resourceSelector.toString()); | ||
|
||
// If the namespace doesn't exist yet, register it | ||
bytes16 namespace = resourceSelector.getNamespace(); | ||
if (ResourceType.get(namespace) == Resource.NONE) { | ||
// We can't call IBaseWorld(this).registerSchema directly because it would be handled like | ||
// an external call, so msg.sender would be the address of the World contract | ||
(address systemAddress, ) = Systems.get(ResourceSelector.from(ROOT_NAMESPACE, CORE_SYSTEM_NAME)); | ||
Call.withSender({ | ||
msgSender: _msgSender(), | ||
target: systemAddress, | ||
funcSelectorAndArgs: abi.encodeWithSelector(WorldRegistrationSystem.registerNamespace.selector, namespace), | ||
delegate: true, | ||
value: 0 | ||
}); | ||
} else { | ||
// otherwise require caller to own the namespace | ||
AccessControl.requireOwnerOrSelf(namespace, _msgSender()); | ||
} | ||
|
||
// Require no resource to exist at this selector yet | ||
if (ResourceType.get(resourceSelector) != Resource.NONE) { | ||
revert ResourceExists(resourceSelector.toString()); | ||
} | ||
|
||
// Store the table resource type | ||
ResourceType.set(resourceSelector, Resource.TABLE); | ||
|
||
// Register the table's schema | ||
StoreCore.registerTable(resourceSelector, keySchema, valueSchema, keyNames, fieldNames); | ||
} | ||
|
||
/** | ||
* Register a hook for the table at the given namepace and name. | ||
* Requires the caller to own the namespace. | ||
*/ | ||
function registerStoreHook(bytes32 tableId, IStoreHook hook) public virtual { | ||
// Require caller to own the namespace | ||
AccessControl.requireOwnerOrSelf(tableId, _msgSender()); | ||
|
||
// Register the hook | ||
StoreCore.registerStoreHook(tableId, hook); | ||
} | ||
} |
Oops, something went wrong.