Skip to content

Commit

Permalink
refactor(store): remove TableId library (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1a committed Aug 11, 2023
1 parent 48c51b5 commit a258811
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-coats-pull.md
@@ -0,0 +1,5 @@
---
"@latticexyz/store": major
---

Remove `TableId` library to simplify `store` package
1 change: 0 additions & 1 deletion packages/store/abi/TableId.sol/TableId.abi.json

This file was deleted.

9 changes: 3 additions & 6 deletions packages/store/src/StoreCore.sol
Expand Up @@ -11,12 +11,9 @@ import { Slice, SliceLib } from "./Slice.sol";
import { StoreMetadata, Hooks, HooksTableId } from "./codegen/Tables.sol";
import { IStoreErrors } from "./IStoreErrors.sol";
import { IStoreHook } from "./IStore.sol";
import { TableId } from "./TableId.sol";
import { StoreSwitch } from "./StoreSwitch.sol";

library StoreCore {
using TableId for bytes32;

// note: the preimage of the tuple of keys used to index is part of the event, so it can be used by indexers
event StoreSetRecord(bytes32 table, bytes32[] key, bytes data);
event StoreSetField(bytes32 table, bytes32[] key, uint8 schemaIndex, bytes data);
Expand Down Expand Up @@ -77,7 +74,7 @@ library StoreCore {
function getSchema(bytes32 tableId) internal view returns (Schema schema) {
schema = StoreCoreInternal._getSchema(tableId);
if (schema.isEmpty()) {
revert IStoreErrors.StoreCore_TableNotFound(tableId, tableId.toString());
revert IStoreErrors.StoreCore_TableNotFound(tableId, string(abi.encodePacked(tableId)));
}
}

Expand All @@ -88,7 +85,7 @@ library StoreCore {
keySchema = StoreCoreInternal._getKeySchema(tableId);
// key schemas can be empty for singleton tables, so we can't depend on key schema for table check
if (!hasTable(tableId)) {
revert IStoreErrors.StoreCore_TableNotFound(tableId, tableId.toString());
revert IStoreErrors.StoreCore_TableNotFound(tableId, string(abi.encodePacked(tableId)));
}
}

Expand All @@ -109,7 +106,7 @@ library StoreCore {

// Verify the schema doesn't exist yet
if (hasTable(tableId)) {
revert IStoreErrors.StoreCore_TableAlreadyExists(tableId, tableId.toString());
revert IStoreErrors.StoreCore_TableAlreadyExists(tableId, string(abi.encodePacked(tableId)));
}

// Register the schema
Expand Down
8 changes: 0 additions & 8 deletions packages/store/src/TableId.sol

This file was deleted.

5 changes: 2 additions & 3 deletions packages/store/test/StoreCore.t.sol
Expand Up @@ -5,7 +5,6 @@ import "forge-std/Test.sol";
import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol";
import { StoreCore, StoreCoreInternal } from "../src/StoreCore.sol";
import { Bytes } from "../src/Bytes.sol";
import { TableId } from "../src/TableId.sol";
import { SliceLib } from "../src/Slice.sol";
import { EncodeArray } from "../src/tightcoder/EncodeArray.sol";
import { Schema } from "../src/Schema.sol";
Expand Down Expand Up @@ -77,12 +76,12 @@ contract StoreCoreTest is Test, StoreMock {
IStore(this).getKeySchema(table);

vm.expectRevert(
abi.encodeWithSelector(IStoreErrors.StoreCore_TableNotFound.selector, table2, TableId.toString(table2))
abi.encodeWithSelector(IStoreErrors.StoreCore_TableNotFound.selector, table2, string(abi.encodePacked(table2)))
);
IStore(this).getSchema(table2);

vm.expectRevert(
abi.encodeWithSelector(IStoreErrors.StoreCore_TableNotFound.selector, table2, TableId.toString(table2))
abi.encodeWithSelector(IStoreErrors.StoreCore_TableNotFound.selector, table2, string(abi.encodePacked(table2)))
);
IStore(this).getKeySchema(table2);
}
Expand Down
1 change: 0 additions & 1 deletion packages/store/test/StoreCoreGas.t.sol
Expand Up @@ -13,7 +13,6 @@ import { PackedCounter, PackedCounterLib } from "../src/PackedCounter.sol";
import { StoreReadWithStubs } from "../src/StoreReadWithStubs.sol";
import { IStoreErrors } from "../src/IStoreErrors.sol";
import { IStore } from "../src/IStore.sol";
import { StoreSwitch } from "../src/StoreSwitch.sol";
import { StoreMetadataData, StoreMetadata } from "../src/codegen/Tables.sol";
import { SchemaEncodeHelper } from "./SchemaEncodeHelper.sol";
import { StoreMock } from "./StoreMock.sol";
Expand Down
1 change: 0 additions & 1 deletion packages/world/abi/TableId.sol/TableId.abi.json

This file was deleted.

22 changes: 11 additions & 11 deletions packages/world/gas-report.json
Expand Up @@ -3,13 +3,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1245509
"gasUsed": 1245428
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1245509
"gasUsed": 1245428
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -21,13 +21,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallSingleton",
"name": "install keys in table module",
"gasUsed": 1245509
"gasUsed": 1245428
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1245509
"gasUsed": 1245428
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -45,7 +45,7 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "install keys in table module",
"gasUsed": 1245509
"gasUsed": 1245428
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -63,7 +63,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testGetKeysWithValueGas",
"name": "install keys with value module",
"gasUsed": 600153
"gasUsed": 600072
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -81,7 +81,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "install keys with value module",
"gasUsed": 600153
"gasUsed": 600072
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -93,7 +93,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "install keys with value module",
"gasUsed": 600153
"gasUsed": 600072
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -111,7 +111,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "install keys with value module",
"gasUsed": 600153
"gasUsed": 600072
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand Down Expand Up @@ -207,7 +207,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 787858
"gasUsed": 787777
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand All @@ -219,7 +219,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 760163
"gasUsed": 760082
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand Down

0 comments on commit a258811

Please sign in to comment.