Skip to content

Commit

Permalink
feat: rename table to tableId
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Sep 14, 2023
1 parent f29829c commit 6edf524
Show file tree
Hide file tree
Showing 92 changed files with 1,076 additions and 1,059 deletions.
20 changes: 10 additions & 10 deletions docs/pages/store/advanced-features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,25 @@ This is an example of a Mirror hook which mirrors a table into another one:
uint256 constant indexerTableId = uint256(keccak256("indexer.table"));
contract MirrorSubscriber is IStoreHook {
uint256 _table;
bytes32 _tableId;
constructor(uint256 table, Schema schema, Schema keySchema) {
constructor(bytes32 tableId, Schema schema, Schema keySchema) {
IStore(msg.sender).registerSchema(indexerTableId, schema, keySchema);
_table = table;
_tableId = tableId;
}
function onSetRecord(uint256 table, bytes32[] memory key, bytes memory data) public {
if (_table != table) revert("invalid table");
function onSetRecord(bytes32 tableId, bytes32[] memory key, bytes memory data) public {
if (_tableId != tableId) revert("invalid tableId");
StoreSwitch.setRecord(indexerTableId, key, data);
}
function onSetField(uint256 table, bytes32[] memory key, uint8 schemaIndex, bytes memory data) public {
if (_table != table) revert("invalid table");
function onSetField(bytes32 tableId, bytes32[] memory key, uint8 schemaIndex, bytes memory data) public {
if (_tableId != tableId) revert("invalid tableId");
StoreSwitch.setField(indexerTableId, key, schemaIndex, data);
}
function onDeleteRecord(uint256 table, bytes32[] memory key) public {
if (_table != table) revert("invalid table");
function onDeleteRecord(bytes32 tableId, bytes32[] memory key) public {
if (_tableId != tableId) revert("invalid tableId");
StoreSwitch.deleteRecord(indexerTableId, key);
}
}
Expand All @@ -109,7 +109,7 @@ contract MirrorSubscriber is IStoreHook {
Registering the hook can be done using the low-level Store API:

```solidity
uint256 table = keccak256("table");
bytes32 tableId = keccak256("table");
Schema schema = SchemaLib.encode(SchemaType.UINT256, SchemaType.UINT256);
Schema keySchema = SchemaLib.encode(SchemaType.UINT256);
MirrorSubscriber subscriber = new MirrorSubscriber(table, schema, keySchema);
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/store/using-without-world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract Contract is Store {
constructor() {
Schema keySchema = SchemaLib.encode(SchemaType.UINT256);
Schema schema = SchemaLib.encode(SchemaType.UINT256, SchemaType.UINT256);
uint256 table = uint256(keccak256("MyTable"));
bytes32 tableId = uint256(keccak256("MyTable"));
StoreCore.registerSchema(table, schema, keySchema);
// Setting metadata is optional. It helps off-chain actors name columns
string[] memory fieldNames = new string[](2);
Expand Down
8 changes: 4 additions & 4 deletions packages/block-logs-stream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ latestBlockNumber$
publicClient,
address,
events: parseAbi([
"event StoreDeleteRecord(bytes32 table, bytes32[] key)",
"event StoreSetField(bytes32 table, bytes32[] key, uint8 schemaIndex, bytes data)",
"event StoreSetRecord(bytes32 table, bytes32[] key, bytes data)",
"event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)",
"event StoreDeleteRecord(bytes32 tableId, bytes32[] key)",
"event StoreSetField(bytes32 tableId, bytes32[] key, uint8 schemaIndex, bytes data)",
"event StoreSetRecord(bytes32 tableId, bytes32[] key, bytes data)",
"event StoreEphemeralRecord(bytes32 tableId, bytes32[] key, bytes data)",
]),
}),
mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs)))
Expand Down
10 changes: 5 additions & 5 deletions packages/store-sync/src/blockLogsToStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function blockLogsToStorage<TConfig extends StoreConfig = StoreConfig>({
const newTables = block.logs
.map((log) => {
if (log.eventName !== "StoreSetRecord") return;
if (log.args.table !== schemasTableId) return;
if (log.args.tableId !== schemasTableId) return;

// TODO: refactor encode/decode to use Record<string, SchemaAbiType> schemas
// TODO: refactor to decode key with protocol-parser utils
Expand Down Expand Up @@ -83,8 +83,8 @@ export function blockLogsToStorage<TConfig extends StoreConfig = StoreConfig>({
block.logs.map((log) =>
JSON.stringify({
address: getAddress(log.address),
tableId: log.args.table,
...hexToTableId(log.args.table),
tableId: log.args.tableId,
...hexToTableId(log.args.tableId),
})
)
)
Expand All @@ -101,9 +101,9 @@ export function blockLogsToStorage<TConfig extends StoreConfig = StoreConfig>({

const operations = block.logs
.map((log): StorageOperation<TConfig> | undefined => {
const table = tables[`${getAddress(log.address)}:${log.args.table}`];
const table = tables[`${getAddress(log.address)}:${log.args.tableId}`];
if (!table) {
debug("no table found for event, skipping", hexToTableId(log.args.table), log);
debug("no table found for event, skipping", hexToTableId(log.args.tableId), log);
return;
}

Expand Down
12 changes: 6 additions & 6 deletions packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions packages/store/abi/IStore.sol/IStore.abi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6edf524

Please sign in to comment.