diff --git a/.changeset/warm-mails-cheat.md b/.changeset/warm-mails-cheat.md new file mode 100644 index 0000000000..79d91ee726 --- /dev/null +++ b/.changeset/warm-mails-cheat.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/world": patch +--- + +Renamed the `functionSelector` key in the `FunctionSelectors` table to `worldFunctionSelector`. This clarifies that `FunctionSelectors` is for world function selectors and can be used to generate the world ABI. diff --git a/packages/cli/src/deploy/getFunctions.ts b/packages/cli/src/deploy/getFunctions.ts index 834dd2cecb..f191f41ec8 100644 --- a/packages/cli/src/deploy/getFunctions.ts +++ b/packages/cli/src/deploy/getFunctions.ts @@ -39,7 +39,7 @@ export async function getFunctions({ client, worldDeploy, table: worldTables.world_FunctionSelectors, - key: { functionSelector: selector }, + key: { worldFunctionSelector: selector }, }); const { namespace, name } = hexToResource(systemId); // TODO: find away around undoing contract logic (https://github.com/latticexyz/mud/issues/1708) diff --git a/packages/world/mud.config.ts b/packages/world/mud.config.ts index 08a52c769a..dce3430995 100644 --- a/packages/world/mud.config.ts +++ b/packages/world/mud.config.ts @@ -86,7 +86,7 @@ export default mudConfig({ }, FunctionSelectors: { keySchema: { - functionSelector: "bytes4", + worldFunctionSelector: "bytes4", }, valueSchema: { systemId: "ResourceId", diff --git a/packages/world/src/codegen/tables/FunctionSelectors.sol b/packages/world/src/codegen/tables/FunctionSelectors.sol index d8e9424bd7..0b7c19e7ba 100644 --- a/packages/world/src/codegen/tables/FunctionSelectors.sol +++ b/packages/world/src/codegen/tables/FunctionSelectors.sol @@ -37,7 +37,7 @@ library FunctionSelectors { */ function getKeyNames() internal pure returns (string[] memory keyNames) { keyNames = new string[](1); - keyNames[0] = "functionSelector"; + keyNames[0] = "worldFunctionSelector"; } /** @@ -67,9 +67,9 @@ library FunctionSelectors { /** * @notice Get systemId. */ - function getSystemId(bytes4 functionSelector) internal view returns (ResourceId systemId) { + function getSystemId(bytes4 worldFunctionSelector) internal view returns (ResourceId systemId) { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return ResourceId.wrap(bytes32(_blob)); @@ -78,9 +78,9 @@ library FunctionSelectors { /** * @notice Get systemId. */ - function _getSystemId(bytes4 functionSelector) internal view returns (ResourceId systemId) { + function _getSystemId(bytes4 worldFunctionSelector) internal view returns (ResourceId systemId) { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return ResourceId.wrap(bytes32(_blob)); @@ -89,9 +89,9 @@ library FunctionSelectors { /** * @notice Set systemId. */ - function setSystemId(bytes4 functionSelector, ResourceId systemId) internal { + function setSystemId(bytes4 worldFunctionSelector, ResourceId systemId) internal { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); } @@ -99,9 +99,9 @@ library FunctionSelectors { /** * @notice Set systemId. */ - function _setSystemId(bytes4 functionSelector, ResourceId systemId) internal { + function _setSystemId(bytes4 worldFunctionSelector, ResourceId systemId) internal { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); } @@ -109,9 +109,11 @@ library FunctionSelectors { /** * @notice Get systemFunctionSelector. */ - function getSystemFunctionSelector(bytes4 functionSelector) internal view returns (bytes4 systemFunctionSelector) { + function getSystemFunctionSelector( + bytes4 worldFunctionSelector + ) internal view returns (bytes4 systemFunctionSelector) { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); return (bytes4(_blob)); @@ -120,9 +122,11 @@ library FunctionSelectors { /** * @notice Get systemFunctionSelector. */ - function _getSystemFunctionSelector(bytes4 functionSelector) internal view returns (bytes4 systemFunctionSelector) { + function _getSystemFunctionSelector( + bytes4 worldFunctionSelector + ) internal view returns (bytes4 systemFunctionSelector) { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); return (bytes4(_blob)); @@ -131,9 +135,9 @@ library FunctionSelectors { /** * @notice Set systemFunctionSelector. */ - function setSystemFunctionSelector(bytes4 functionSelector, bytes4 systemFunctionSelector) internal { + function setSystemFunctionSelector(bytes4 worldFunctionSelector, bytes4 systemFunctionSelector) internal { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((systemFunctionSelector)), _fieldLayout); } @@ -141,9 +145,9 @@ library FunctionSelectors { /** * @notice Set systemFunctionSelector. */ - function _setSystemFunctionSelector(bytes4 functionSelector, bytes4 systemFunctionSelector) internal { + function _setSystemFunctionSelector(bytes4 worldFunctionSelector, bytes4 systemFunctionSelector) internal { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((systemFunctionSelector)), _fieldLayout); } @@ -151,9 +155,11 @@ library FunctionSelectors { /** * @notice Get the full data. */ - function get(bytes4 functionSelector) internal view returns (ResourceId systemId, bytes4 systemFunctionSelector) { + function get( + bytes4 worldFunctionSelector + ) internal view returns (ResourceId systemId, bytes4 systemFunctionSelector) { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, @@ -166,9 +172,11 @@ library FunctionSelectors { /** * @notice Get the full data. */ - function _get(bytes4 functionSelector) internal view returns (ResourceId systemId, bytes4 systemFunctionSelector) { + function _get( + bytes4 worldFunctionSelector + ) internal view returns (ResourceId systemId, bytes4 systemFunctionSelector) { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); (bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, @@ -181,14 +189,14 @@ library FunctionSelectors { /** * @notice Set the full data using individual values. */ - function set(bytes4 functionSelector, ResourceId systemId, bytes4 systemFunctionSelector) internal { + function set(bytes4 worldFunctionSelector, ResourceId systemId, bytes4 systemFunctionSelector) internal { bytes memory _staticData = encodeStatic(systemId, systemFunctionSelector); PackedCounter _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); } @@ -196,14 +204,14 @@ library FunctionSelectors { /** * @notice Set the full data using individual values. */ - function _set(bytes4 functionSelector, ResourceId systemId, bytes4 systemFunctionSelector) internal { + function _set(bytes4 worldFunctionSelector, ResourceId systemId, bytes4 systemFunctionSelector) internal { bytes memory _staticData = encodeStatic(systemId, systemFunctionSelector); PackedCounter _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } @@ -234,9 +242,9 @@ library FunctionSelectors { /** * @notice Delete all data for given keys. */ - function deleteRecord(bytes4 functionSelector) internal { + function deleteRecord(bytes4 worldFunctionSelector) internal { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); StoreSwitch.deleteRecord(_tableId, _keyTuple); } @@ -244,9 +252,9 @@ library FunctionSelectors { /** * @notice Delete all data for given keys. */ - function _deleteRecord(bytes4 functionSelector) internal { + function _deleteRecord(bytes4 worldFunctionSelector) internal { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } @@ -280,9 +288,9 @@ library FunctionSelectors { /** * @notice Encode keys as a bytes32 array using this table's field layout. */ - function encodeKeyTuple(bytes4 functionSelector) internal pure returns (bytes32[] memory) { + function encodeKeyTuple(bytes4 worldFunctionSelector) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(functionSelector); + _keyTuple[0] = bytes32(worldFunctionSelector); return _keyTuple; }