Skip to content

Commit

Permalink
refactor(store): use _keyTupleDefinition in encodeKeyTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1a committed Aug 16, 2023
1 parent 331f0d6 commit 018b583
Show file tree
Hide file tree
Showing 26 changed files with 103 additions and 56 deletions.
6 changes: 4 additions & 2 deletions packages/cli/contracts/src/codegen/tables/Dynamics1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,11 @@ library Dynamics1 {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/contracts/src/codegen/tables/Dynamics2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,11 @@ library Dynamics2 {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/contracts/src/codegen/tables/Ephemeral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ library Ephemeral {
}

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

return _keyTuple;
}
}
6 changes: 4 additions & 2 deletions packages/cli/contracts/src/codegen/tables/Singleton.sol
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,10 @@ library Singleton {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/contracts/src/codegen/tables/Statics.sol
Original file line number Diff line number Diff line change
Expand Up @@ -885,15 +885,17 @@ library Statics {
bool k5,
Enum1 k6,
Enum2 k7
) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](7);
) internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](7);
_keyTuple[0] = bytes32(uint256(k1));
_keyTuple[1] = bytes32(uint256(int256(k2)));
_keyTuple[2] = bytes32(k3);
_keyTuple[3] = bytes32(uint256(uint160(k4)));
_keyTuple[4] = _boolToBytes32(k5);
_keyTuple[5] = bytes32(uint256(uint8(k6)));
_keyTuple[6] = bytes32(uint256(uint8(k7)));

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/store/src/codegen/tables/Callbacks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ library Callbacks {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/store/src/codegen/tables/Hooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ library Hooks {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/store/src/codegen/tables/KeyEncoding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,16 @@ library KeyEncoding {
address k4,
bool k5,
ExampleEnum k6
) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](6);
) internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](6);
_keyTuple[0] = bytes32(uint256(k1));
_keyTuple[1] = bytes32(uint256(int256(k2)));
_keyTuple[2] = bytes32(k3);
_keyTuple[3] = bytes32(uint256(uint160(k4)));
_keyTuple[4] = _boolToBytes32(k5);
_keyTuple[5] = bytes32(uint256(uint8(k6)));

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/store/src/codegen/tables/Mixed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,11 @@ library Mixed {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/store/src/codegen/tables/StoreMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,11 @@ library StoreMetadata {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/store/src/codegen/tables/Vector2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ library Vector2 {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 3 additions & 3 deletions packages/store/ts/codegen/renderTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ library ${libraryName} {
}
/** Encode keys as a bytes32 array using this table's schema */
function encodeKeyTuple(${renderArguments([_typedKeyArgs])}) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](${keyTuple.length});
${renderList(keyTuple, (key, index) => `_keyTuple[${index}] = ${renderValueTypeToBytes32(key.name, key)};`)}
function encodeKeyTuple(${renderArguments([_typedKeyArgs])}) internal pure returns (bytes32[] memory) {
${_keyTupleDefinition}
return _keyTuple;
}
${
Expand Down
6 changes: 4 additions & 2 deletions packages/world/src/modules/core/tables/FunctionSelectors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ library FunctionSelectors {
}

/** Encode keys as a bytes32 array using this table's schema */
function encodeKeyTuple(bytes4 functionSelector) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](1);
function encodeKeyTuple(bytes4 functionSelector) internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(functionSelector);

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/world/src/modules/core/tables/ResourceType.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ library ResourceType {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/world/src/modules/core/tables/SystemHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ library SystemHooks {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/world/src/modules/core/tables/SystemRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ library SystemRegistry {
}

/** Encode keys as a bytes32 array using this table's schema */
function encodeKeyTuple(address system) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](1);
function encodeKeyTuple(address system) internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = bytes32(uint256(uint160(system)));

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/world/src/modules/core/tables/Systems.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ library Systems {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/world/src/modules/keysintable/tables/KeysInTable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,11 @@ library KeysInTable {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ library UsedKeysIndex {
}

/** Encode keys as a bytes32 array using this table's schema */
function encodeKeyTuple(bytes32 sourceTable, bytes32 keysHash) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](2);
function encodeKeyTuple(bytes32 sourceTable, bytes32 keysHash) internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](2);
_keyTuple[0] = sourceTable;
_keyTuple[1] = keysHash;

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ library KeysWithValue {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ library UniqueEntity {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
9 changes: 4 additions & 5 deletions packages/world/src/tables/InstalledModules.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,12 @@ library InstalledModules {
}

/** Encode keys as a bytes32 array using this table's schema */
function encodeKeyTuple(
bytes16 moduleName,
bytes32 argumentsHash
) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](2);
function encodeKeyTuple(bytes16 moduleName, bytes32 argumentsHash) internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](2);
_keyTuple[0] = bytes32(moduleName);
_keyTuple[1] = argumentsHash;

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/world/src/tables/NamespaceOwner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ library NamespaceOwner {
}

/** Encode keys as a bytes32 array using this table's schema */
function encodeKeyTuple(bytes16 namespace) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](1);
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 */
Expand Down
6 changes: 4 additions & 2 deletions packages/world/src/tables/ResourceAccess.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ library ResourceAccess {
}

/** Encode keys as a bytes32 array using this table's schema */
function encodeKeyTuple(bytes32 resourceSelector, address caller) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](2);
function encodeKeyTuple(bytes32 resourceSelector, address caller) internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](2);
_keyTuple[0] = resourceSelector;
_keyTuple[1] = bytes32(uint256(uint160(caller)));

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/world/test/tables/AddressArray.sol
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ library AddressArray {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down
6 changes: 4 additions & 2 deletions packages/world/test/tables/Bool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ library Bool {
}

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

return _keyTuple;
}

/* Delete all data for given keys */
Expand Down

0 comments on commit 018b583

Please sign in to comment.