Skip to content

Commit

Permalink
refactor(store): use _keyTupleDefinition in encodeKeyTuple (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1a authored Aug 16, 2023
1 parent d5b73b1 commit 83bc404
Show file tree
Hide file tree
Showing 37 changed files with 147 additions and 82 deletions.
6 changes: 4 additions & 2 deletions e2e/packages/contracts/src/codegen/tables/Multi.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,14 @@ library Multi {
}

/** Encode keys as a bytes32 array using this table's schema */
function encodeKeyTuple(uint32 a, bool b, uint256 c, int120 d) internal pure returns (bytes32[] memory _keyTuple) {
_keyTuple = new bytes32[](4);
function encodeKeyTuple(uint32 a, bool b, uint256 c, int120 d) internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](4);
_keyTuple[0] = bytes32(uint256(a));
_keyTuple[1] = _boolToBytes32(b);
_keyTuple[2] = bytes32(uint256(c));
_keyTuple[3] = bytes32(uint256(int256(d)));

return _keyTuple;
}

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

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

return _keyTuple;
}

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

/** 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 e2e/packages/contracts/src/codegen/tables/Vector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ library Vector {
}

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

return _keyTuple;
}

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

/** 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
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,13 @@ library Inventory {
}

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

return _keyTuple;
}

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

/** 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;
}
}
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 @@ -947,9 +947,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 @@ -593,9 +593,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 @@ -580,8 +580,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 @@ -224,9 +224,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 @@ -224,9 +224,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 @@ -519,9 +519,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 @@ -448,9 +448,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 @@ -224,9 +224,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 @@ -961,9 +961,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 @@ -225,9 +225,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
Loading

0 comments on commit 83bc404

Please sign in to comment.