-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add FunctionSignatures table, require function signature in registerR…
…ootFunctionSelector
- Loading branch information
Showing
10 changed files
with
298 additions
and
56 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 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
198 changes: 198 additions & 0 deletions
198
packages/world/src/modules/core/tables/FunctionSignatures.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,198 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.21; | ||
|
||
/* Autogenerated file. Do not edit manually. */ | ||
|
||
// Import schema type | ||
import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; | ||
|
||
// Import store internals | ||
import { IStore } from "@latticexyz/store/src/IStore.sol"; | ||
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; | ||
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; | ||
import { Bytes } from "@latticexyz/store/src/Bytes.sol"; | ||
import { Memory } from "@latticexyz/store/src/Memory.sol"; | ||
import { SliceLib } from "@latticexyz/store/src/Slice.sol"; | ||
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; | ||
import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol"; | ||
import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; | ||
import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; | ||
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||
import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol"; | ||
|
||
ResourceId constant _tableId = ResourceId.wrap( | ||
bytes32(abi.encodePacked(RESOURCE_OFFCHAIN_TABLE, bytes14(""), bytes16("FunctionSignatur"))) | ||
); | ||
ResourceId constant FunctionSignaturesTableId = _tableId; | ||
|
||
FieldLayout constant _fieldLayout = FieldLayout.wrap( | ||
0x0000000100000000000000000000000000000000000000000000000000000000 | ||
); | ||
|
||
library FunctionSignatures { | ||
/** Get the table values' field layout */ | ||
function getFieldLayout() internal pure returns (FieldLayout) { | ||
return _fieldLayout; | ||
} | ||
|
||
/** Get the table's key schema */ | ||
function getKeySchema() internal pure returns (Schema) { | ||
SchemaType[] memory _keySchema = new SchemaType[](1); | ||
_keySchema[0] = SchemaType.BYTES4; | ||
|
||
return SchemaLib.encode(_keySchema); | ||
} | ||
|
||
/** Get the table's value schema */ | ||
function getValueSchema() internal pure returns (Schema) { | ||
SchemaType[] memory _valueSchema = new SchemaType[](1); | ||
_valueSchema[0] = SchemaType.STRING; | ||
|
||
return SchemaLib.encode(_valueSchema); | ||
} | ||
|
||
/** Get the table's key names */ | ||
function getKeyNames() internal pure returns (string[] memory keyNames) { | ||
keyNames = new string[](1); | ||
keyNames[0] = "functionSelector"; | ||
} | ||
|
||
/** Get the table's field names */ | ||
function getFieldNames() internal pure returns (string[] memory fieldNames) { | ||
fieldNames = new string[](1); | ||
fieldNames[0] = "functionSignature"; | ||
} | ||
|
||
/** Register the table with its config */ | ||
function register() internal { | ||
StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); | ||
} | ||
|
||
/** Register the table with its config */ | ||
function _register() internal { | ||
StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); | ||
} | ||
|
||
/** Register the table with its config (using the specified store) */ | ||
function register(IStore _store) internal { | ||
_store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); | ||
} | ||
|
||
/** Set the full data using individual values */ | ||
function set(bytes4 functionSelector, string memory functionSignature) internal { | ||
bytes memory _staticData; | ||
PackedCounter _encodedLengths = encodeLengths(functionSignature); | ||
bytes memory _dynamicData = encodeDynamic(functionSignature); | ||
|
||
bytes32[] memory _keyTuple = new bytes32[](1); | ||
_keyTuple[0] = bytes32(functionSelector); | ||
|
||
StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); | ||
} | ||
|
||
/** Set the full data using individual values */ | ||
function _set(bytes4 functionSelector, string memory functionSignature) internal { | ||
bytes memory _staticData; | ||
PackedCounter _encodedLengths = encodeLengths(functionSignature); | ||
bytes memory _dynamicData = encodeDynamic(functionSignature); | ||
|
||
bytes32[] memory _keyTuple = new bytes32[](1); | ||
_keyTuple[0] = bytes32(functionSelector); | ||
|
||
StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); | ||
} | ||
|
||
/** Set the full data using individual values (using the specified store) */ | ||
function set(IStore _store, bytes4 functionSelector, string memory functionSignature) internal { | ||
bytes memory _staticData; | ||
PackedCounter _encodedLengths = encodeLengths(functionSignature); | ||
bytes memory _dynamicData = encodeDynamic(functionSignature); | ||
|
||
bytes32[] memory _keyTuple = new bytes32[](1); | ||
_keyTuple[0] = bytes32(functionSelector); | ||
|
||
_store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); | ||
} | ||
|
||
/** | ||
* Decode the tightly packed blob of static data using this table's field layout | ||
* Undefined behaviour for invalid blobs | ||
*/ | ||
function decodeDynamic( | ||
PackedCounter _encodedLengths, | ||
bytes memory _blob | ||
) internal pure returns (string memory functionSignature) { | ||
uint256 _start; | ||
uint256 _end; | ||
unchecked { | ||
_end = _encodedLengths.atIndex(0); | ||
} | ||
functionSignature = (string(SliceLib.getSubslice(_blob, _start, _end).toBytes())); | ||
} | ||
|
||
/** | ||
* Decode the tightly packed blob using this table's field layout. | ||
* Undefined behaviour for invalid blobs. | ||
*/ | ||
function decode( | ||
bytes memory, | ||
PackedCounter _encodedLengths, | ||
bytes memory _dynamicData | ||
) internal pure returns (string memory functionSignature) { | ||
(functionSignature) = decodeDynamic(_encodedLengths, _dynamicData); | ||
} | ||
|
||
/** Delete all data for given keys */ | ||
function deleteRecord(bytes4 functionSelector) internal { | ||
bytes32[] memory _keyTuple = new bytes32[](1); | ||
_keyTuple[0] = bytes32(functionSelector); | ||
|
||
StoreSwitch.deleteRecord(_tableId, _keyTuple, _fieldLayout); | ||
} | ||
|
||
/** Delete all data for given keys */ | ||
function _deleteRecord(bytes4 functionSelector) internal { | ||
bytes32[] memory _keyTuple = new bytes32[](1); | ||
_keyTuple[0] = bytes32(functionSelector); | ||
|
||
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); | ||
} | ||
|
||
/** Delete all data for given keys (using the specified store) */ | ||
function deleteRecord(IStore _store, bytes4 functionSelector) internal { | ||
bytes32[] memory _keyTuple = new bytes32[](1); | ||
_keyTuple[0] = bytes32(functionSelector); | ||
|
||
_store.deleteRecord(_tableId, _keyTuple, _fieldLayout); | ||
} | ||
|
||
/** Tightly pack dynamic data using this table's schema */ | ||
function encodeLengths(string memory functionSignature) internal pure returns (PackedCounter _encodedLengths) { | ||
// Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits | ||
unchecked { | ||
_encodedLengths = PackedCounterLib.pack(bytes(functionSignature).length); | ||
} | ||
} | ||
|
||
/** Tightly pack dynamic data using this table's schema */ | ||
function encodeDynamic(string memory functionSignature) internal pure returns (bytes memory) { | ||
return abi.encodePacked(bytes((functionSignature))); | ||
} | ||
|
||
/** Tightly pack full data using this table's field layout */ | ||
function encode(string memory functionSignature) internal pure returns (bytes memory, PackedCounter, bytes memory) { | ||
bytes memory _staticData; | ||
PackedCounter _encodedLengths = encodeLengths(functionSignature); | ||
bytes memory _dynamicData = encodeDynamic(functionSignature); | ||
|
||
return (_staticData, _encodedLengths, _dynamicData); | ||
} | ||
|
||
/** Encode keys as a bytes32 array using this table's field layout */ | ||
function encodeKeyTuple(bytes4 functionSelector) internal pure returns (bytes32[] memory) { | ||
bytes32[] memory _keyTuple = new bytes32[](1); | ||
_keyTuple[0] = bytes32(functionSelector); | ||
|
||
return _keyTuple; | ||
} | ||
} |
Oops, something went wrong.