Skip to content

Commit

Permalink
rename remaining resource selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Sep 19, 2023
1 parent 4d97630 commit 95539e3
Show file tree
Hide file tree
Showing 25 changed files with 297 additions and 320 deletions.
14 changes: 7 additions & 7 deletions packages/world/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default mudConfig({
},
ResourceAccess: {
keySchema: {
resourceSelector: "bytes32",
resourceId: "bytes32",
caller: "address",
},
valueSchema: {
Expand Down Expand Up @@ -63,7 +63,7 @@ export default mudConfig({
Systems: {
directory: "modules/core/tables",
keySchema: {
resourceSelector: "bytes32",
systemId: "bytes32",
},
valueSchema: {
system: "address",
Expand All @@ -77,20 +77,20 @@ export default mudConfig({
system: "address",
},
valueSchema: {
resourceSelector: "bytes32",
systemId: "bytes32",
},
},
SystemHooks: {
directory: "modules/core/tables",
keySchema: {
resourceSelector: "bytes32",
systemId: "bytes32",
},
valueSchema: "bytes21[]",
},
ResourceType: {
directory: "modules/core/tables",
keySchema: {
resourceSelector: "bytes32",
systemId: "bytes32",
},
valueSchema: {
resourceType: "Resource",
Expand All @@ -102,7 +102,7 @@ export default mudConfig({
functionSelector: "bytes4",
},
valueSchema: {
resourceSelector: "bytes32",
systemId: "bytes32",
systemFunctionSelector: "bytes4",
},
dataStruct: false,
Expand Down Expand Up @@ -149,7 +149,7 @@ export default mudConfig({
keySchema: {
delegator: "address",
delegatee: "address",
resourceSelector: "bytes32",
systemId: "bytes32",
callDataHash: "bytes32",
},
valueSchema: {
Expand Down
2 changes: 1 addition & 1 deletion packages/world/src/AccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ library AccessControl {
}

/**
* Check for ownership of the namespace of the given resource selector.
* Check for ownership of the namespace of the given resource ID.
* Reverts with AccessDenied if the check fails.
*/
function requireOwner(bytes32 resourceId, address caller) internal view {
Expand Down
6 changes: 3 additions & 3 deletions packages/world/src/SystemCall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ library SystemCall {
using ResourceId for bytes32;

/**
* Calls a system via its resource selector and perform access control checks.
* Calls a system via its ID and perform access control checks.
* Does not revert if the call fails, but returns a `success` flag along with the returndata.
*/
function call(
Expand Down Expand Up @@ -66,7 +66,7 @@ library SystemCall {
}

/**
* Calls a system via its resource selector, perform access control checks and trigger hooks registered for the system.
* Calls a system via its ID, perform access control checks and trigger hooks registered for the system.
* Does not revert if the call fails, but returns a `success` flag along with the returndata.
*/
function callWithHooks(
Expand Down Expand Up @@ -99,7 +99,7 @@ library SystemCall {
}

/**
* Calls a system via its resource selector, perform access control checks and trigger hooks registered for the system.
* Calls a system via its ID, perform access control checks and trigger hooks registered for the system.
* Reverts if the call fails.
*/
function callWithHooksOrRevert(
Expand Down
4 changes: 2 additions & 2 deletions packages/world/src/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ library Utils {
if (StoreSwitch.getStoreAddress() == address(this)) {
return "";
} else {
bytes32 resourceSelector = SystemRegistry.get(address(this));
return ResourceId.getNamespace(resourceSelector);
bytes32 systemId = SystemRegistry.get(address(this));
return ResourceId.getNamespace(systemId);
}
}
}
14 changes: 7 additions & 7 deletions packages/world/src/World.sol
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,16 @@ contract World is StoreRead, IStoreData, IWorldKernel {
************************************************************************/

/**
* Call the system at the given resourceSelector.
* If the system is not public, the caller must have access to the namespace or name (encoded in the resourceSelector).
* Call the system at the given system ID.
* If the system is not public, the caller must have access to the namespace or name (encoded in the system ID).
*/
function call(bytes32 systemId, bytes memory callData) external payable virtual returns (bytes memory) {
return SystemCall.callWithHooksOrRevert(msg.sender, systemId, callData, msg.value);
}

/**
* Call the system at the given resourceSelector on behalf of the given delegator.
* If the system is not public, the delegator must have access to the namespace or name (encoded in the resourceSelector).
* Call the system at the given system ID on behalf of the given delegator.
* If the system is not public, the delegator must have access to the namespace or name (encoded in the system ID).
*/
function callFrom(
address delegator,
Expand Down Expand Up @@ -266,15 +266,15 @@ contract World is StoreRead, IStoreData, IWorldKernel {
* Fallback function to call registered function selectors
*/
fallback() external payable {
(bytes32 resourceSelector, bytes4 systemFunctionSelector) = FunctionSelectors._get(msg.sig);
(bytes32 systemId, bytes4 systemFunctionSelector) = FunctionSelectors._get(msg.sig);

if (resourceSelector == 0) revert FunctionSelectorNotFound(msg.sig);
if (systemId == 0) revert FunctionSelectorNotFound(msg.sig);

// Replace function selector in the calldata with the system function selector
bytes memory callData = Bytes.setBytes4(msg.data, 0, systemFunctionSelector);

// Call the function and forward the call data
bytes memory returnData = SystemCall.callWithHooksOrRevert(msg.sender, resourceSelector, callData, msg.value);
bytes memory returnData = SystemCall.callWithHooksOrRevert(msg.sender, systemId, callData, msg.value);

// If the call was successful, return the return data
assembly {
Expand Down
4 changes: 2 additions & 2 deletions packages/world/src/interfaces/IAccessManagementSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pragma solidity >=0.8.0;
/* Autogenerated file. Do not edit manually. */

interface IAccessManagementSystem {
function grantAccess(bytes32 resourceSelector, address grantee) external;
function grantAccess(bytes32 resourceId, address grantee) external;

function revokeAccess(bytes32 resourceSelector, address grantee) external;
function revokeAccess(bytes32 resourceId, address grantee) external;

function transferOwnership(bytes14 namespace, address newOwner) external;
}
2 changes: 1 addition & 1 deletion packages/world/src/interfaces/IModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bytes4 constant MODULE_INTERFACE_ID = IModule.getName.selector ^
ERC165_INTERFACE_ID;

interface IModule is IERC165 {
error RequiredModuleNotFound(string resourceSelector);
error RequiredModuleNotFound(string moduleId);
error RootInstallModeNotSupported();
error NonRootInstallNotSupported();

Expand Down
4 changes: 2 additions & 2 deletions packages/world/src/interfaces/ISystemHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bytes4 constant SYSTEM_HOOK_INTERFACE_ID = ISystemHook.onBeforeCallSystem.select
ERC165_INTERFACE_ID;

interface ISystemHook is IERC165 {
function onBeforeCallSystem(address msgSender, bytes32 resourceSelector, bytes memory callData) external;
function onBeforeCallSystem(address msgSender, bytes32 systemId, bytes memory callData) external;

function onAfterCallSystem(address msgSender, bytes32 resourceSelector, bytes memory callData) external;
function onAfterCallSystem(address msgSender, bytes32 systemId, bytes memory callData) external;
}
16 changes: 6 additions & 10 deletions packages/world/src/interfaces/IWorldKernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ interface IWorldModuleInstallation {

interface IWorldCall {
/**
* Call the system at the given resourceSelector.
* If the system is not public, the caller must have access to the namespace or name (encoded in the resourceSelector).
* Call the system at the given system ID.
* If the system is not public, the caller must have access to the namespace or name (encoded in the system ID).
*/
function call(bytes32 resourceSelector, bytes memory callData) external payable returns (bytes memory);
function call(bytes32 systemId, bytes memory callData) external payable returns (bytes memory);

/**
* Call the system at the given resourceSelector on behalf of the given delegator.
* If the system is not public, the delegator must have access to the namespace or name (encoded in the resourceSelector).
* Call the system at the given system ID on behalf of the given delegator.
* If the system is not public, the delegator must have access to the namespace or name (encoded in the system ID).
*/
function callFrom(
address delegator,
bytes32 resourceSelector,
bytes memory callData
) external payable returns (bytes memory);
function callFrom(address delegator, bytes32 systemId, bytes memory callData) external payable returns (bytes memory);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/world/src/interfaces/IWorldRegistrationSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import { WorldContextConsumer } from "./../WorldContext.sol";
interface IWorldRegistrationSystem {
function registerNamespace(bytes14 namespace) external;

function registerSystemHook(bytes32 resourceSelector, ISystemHook hookAddress, uint8 enabledHooksBitmap) external;
function registerSystemHook(bytes32 systemId, ISystemHook hookAddress, uint8 enabledHooksBitmap) external;

function unregisterSystemHook(bytes32 resourceSelector, ISystemHook hookAddress) external;
function unregisterSystemHook(bytes32 systemId, ISystemHook hookAddress) external;

function registerSystem(bytes32 resourceSelector, WorldContextConsumer system, bool publicAccess) external;
function registerSystem(bytes32 systemId, WorldContextConsumer system, bool publicAccess) external;

function registerFunctionSelector(
bytes32 resourceSelector,
bytes32 systemId,
string memory systemFunctionName,
string memory systemFunctionArguments
) external returns (bytes4 worldFunctionSelector);

function registerRootFunctionSelector(
bytes32 resourceSelector,
bytes32 systemId,
bytes4 worldFunctionSelector,
bytes4 systemFunctionSelector
) external returns (bytes4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ contract EphemeralRecordSystem is IStoreEphemeral, System {

/**
* Emit the ephemeral event without modifying storage at the given namespace and name.
* Requires the caller to have access to the namespace or name (encoded in the resource selector)
* Requires the caller to have access to the namespace or name (encoded in the table ID)
*/
function emitEphemeralRecord(
bytes32 resourceSelector,
bytes32 tableId,
bytes32[] calldata keyTuple,
bytes calldata staticData,
PackedCounter encodedLengths,
bytes calldata dynamicData,
FieldLayout fieldLayout
) public virtual {
// Require access to the namespace or name
AccessControl.requireAccess(resourceSelector, msg.sender);
AccessControl.requireAccess(tableId, msg.sender);

// Set the record
StoreCore.emitEphemeralRecord(resourceSelector, keyTuple, staticData, encodedLengths, dynamicData, fieldLayout);
StoreCore.emitEphemeralRecord(tableId, keyTuple, staticData, encodedLengths, dynamicData, fieldLayout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ contract WorldRegistrationSystem is System, IWorldErrors {
);

// Require the function selector to be globally unique
bytes32 existingResourceSelector = FunctionSelectors._getResourceSelector(worldFunctionSelector);
bytes32 existingSystemId = FunctionSelectors._getSystemId(worldFunctionSelector);

if (existingResourceSelector != 0) revert FunctionSelectorExists(worldFunctionSelector);
if (existingSystemId != 0) revert FunctionSelectorExists(worldFunctionSelector);

// Register the function selector
bytes memory systemFunctionSignature = abi.encodePacked(systemFunctionName, systemFunctionArguments);
Expand All @@ -186,9 +186,9 @@ contract WorldRegistrationSystem is System, IWorldErrors {
AccessControl.requireOwner(ROOT_NAMESPACE_ID, _msgSender());

// Require the function selector to be globally unique
bytes32 existingResourceSelector = FunctionSelectors._getResourceSelector(worldFunctionSelector);
bytes32 existingSystemId = FunctionSelectors._getSystemId(worldFunctionSelector);

if (existingResourceSelector != 0) revert FunctionSelectorExists(worldFunctionSelector);
if (existingSystemId != 0) revert FunctionSelectorExists(worldFunctionSelector);

// Register the function selector
FunctionSelectors._set(worldFunctionSelector, systemId, systemFunctionSelector);
Expand Down
20 changes: 10 additions & 10 deletions packages/world/src/modules/core/tables/Balances.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ library Balances {
}

/** Get balance */
function get(bytes14 namespace) internal view returns (uint256 balance) {
function get(bytes16 namespace) internal view returns (uint256 balance) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

Expand All @@ -84,7 +84,7 @@ library Balances {
}

/** Get balance */
function _get(bytes14 namespace) internal view returns (uint256 balance) {
function _get(bytes16 namespace) internal view returns (uint256 balance) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

Expand All @@ -93,7 +93,7 @@ library Balances {
}

/** Get balance (using the specified store) */
function get(IStore _store, bytes14 namespace) internal view returns (uint256 balance) {
function get(IStore _store, bytes16 namespace) internal view returns (uint256 balance) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

Expand All @@ -102,23 +102,23 @@ library Balances {
}

/** Set balance */
function set(bytes14 namespace, uint256 balance) internal {
function set(bytes16 namespace, uint256 balance) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), _fieldLayout);
}

/** Set balance */
function _set(bytes14 namespace, uint256 balance) internal {
function _set(bytes16 namespace, uint256 balance) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), _fieldLayout);
}

/** Set balance (using the specified store) */
function set(IStore _store, bytes14 namespace, uint256 balance) internal {
function set(IStore _store, bytes16 namespace, uint256 balance) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

Expand All @@ -141,31 +141,31 @@ library Balances {
}

/** Encode keys as a bytes32 array using this table's field layout */
function encodeKeyTuple(bytes14 namespace) internal pure returns (bytes32[] memory) {
function encodeKeyTuple(bytes16 namespace) internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

return _keyTuple;
}

/* Delete all data for given keys */
function deleteRecord(bytes14 namespace) internal {
function deleteRecord(bytes16 namespace) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

StoreSwitch.deleteRecord(_tableId, _keyTuple, _fieldLayout);
}

/* Delete all data for given keys */
function _deleteRecord(bytes14 namespace) internal {
function _deleteRecord(bytes16 namespace) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
}

/* Delete all data for given keys (using the specified store) */
function deleteRecord(IStore _store, bytes14 namespace) internal {
function deleteRecord(IStore _store, bytes16 namespace) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(namespace);

Expand Down
Loading

0 comments on commit 95539e3

Please sign in to comment.