-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(world): add World prototype #405
Changes from all commits
a0dbcc1
ee1ce70
f39c2ce
dad190b
ce31edd
9a267f9
43b7070
a3f5e68
d0f8e12
cdad26d
4e216e0
d1ecc42
b1bda3e
d2b54a9
177d98d
a466e62
29c1558
accef11
416288d
c38bfc4
2cc28af
7fc68d0
270f193
f25f3be
ba8ed10
f37a289
f010ea2
da48c0f
9901b65
bcfcf68
0c91fba
26642b3
0278f0a
8247a54
fdcc1da
b6258e5
9a68d83
1f2f19e
75849f2
253d8bb
7a9c9f7
6d349f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,20 @@ interface IStore { | |
// Set full record (including full dynamic data) | ||
function setRecord( | ||
uint256 table, | ||
bytes32[] memory key, | ||
bytes memory data | ||
bytes32[] calldata key, | ||
bytes calldata data | ||
) external; | ||
|
||
// Set partial data at schema index | ||
function setField( | ||
uint256 table, | ||
bytes32[] memory key, | ||
bytes32[] calldata key, | ||
uint8 schemaIndex, | ||
bytes memory data | ||
bytes calldata data | ||
) external; | ||
|
||
// Register hooks to be called when a record or field is set or deleted | ||
function registerHook(uint256 table, IStoreHook hooks) external; | ||
function registerStoreHook(uint256 table, IStoreHook hooks) external; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should probably be |
||
|
||
// Set full record (including full dynamic data) | ||
function deleteRecord(uint256 table, bytes32[] memory key) external; | ||
|
@@ -40,14 +40,14 @@ interface IStore { | |
// Get full record (including full array) | ||
function getRecord( | ||
uint256 table, | ||
bytes32[] memory key, | ||
bytes32[] calldata key, | ||
Schema schema | ||
) external view returns (bytes memory data); | ||
|
||
// Get partial data at schema index | ||
function getField( | ||
uint256 table, | ||
bytes32[] memory key, | ||
bytes32[] calldata key, | ||
uint8 schemaIndex | ||
) external view returns (bytes memory data); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ using DecodeSlice for Slice global; | |
* @title Static functions for Slice | ||
*/ | ||
library SliceLib { | ||
error Slice_OutOfBounds(); | ||
error Slice_OutOfBounds(bytes data, uint256 start, uint256 end); | ||
|
||
uint256 constant MASK_LEN = uint256(type(uint128).max); | ||
uint256 constant MASK_PTR = uint256(type(uint128).max) << 128; | ||
|
@@ -36,16 +36,24 @@ library SliceLib { | |
return Slice.wrap((_pointer << 128) | (data.length & MASK_LEN)); | ||
} | ||
|
||
/** | ||
* @dev Subslice a bytes array using the given start index until the end of the array (without copying data) | ||
*/ | ||
function getSubslice(bytes memory data, uint256 start) internal pure returns (Slice) { | ||
return getSubslice(data, start, data.length); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. naming nit: what about just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I named it that way pretty much just to avoid confusion with the |
||
|
||
/** | ||
* @dev Subslice a bytes array using the given indexes (without copying data) | ||
* The start index is inclusive, the end index is exclusive | ||
*/ | ||
function getSubslice( | ||
bytes memory data, | ||
uint256 start, | ||
uint256 end | ||
) internal pure returns (Slice) { | ||
// TODO this check helps catch bugs and can eventually be removed | ||
if (!(start <= end && end <= data.length)) revert Slice_OutOfBounds(); | ||
if (!(start <= end && end <= data.length)) revert Slice_OutOfBounds(data, start, end); | ||
|
||
uint256 _pointer; | ||
assembly { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
import { SchemaType } from "./Types.sol"; | ||
import { IStore, IStoreHook } from "./IStore.sol"; | ||
import { StoreCore } from "./StoreCore.sol"; | ||
import { Schema } from "./Schema.sol"; | ||
|
||
abstract contract Store is IStore { | ||
constructor() { | ||
StoreCore.initialize(); | ||
} | ||
|
||
function getSchema(uint256 table) public view virtual returns (Schema schema) { | ||
schema = StoreCore.getSchema(table); | ||
} | ||
|
||
// Get full record (static and dynamic data, load schema from storage) | ||
function getRecord(uint256 table, bytes32[] calldata key) public view virtual returns (bytes memory data) { | ||
data = StoreCore.getRecord(table, key); | ||
} | ||
|
||
// Get full record (static and dynamic data) | ||
function getRecord( | ||
uint256 table, | ||
bytes32[] calldata key, | ||
Schema schema | ||
) public view virtual returns (bytes memory data) { | ||
data = StoreCore.getRecord(table, key, schema); | ||
} | ||
|
||
// Get partial data at schema index | ||
function getField( | ||
uint256 table, | ||
bytes32[] calldata key, | ||
uint8 schemaIndex | ||
) public view virtual returns (bytes memory data) { | ||
data = StoreCore.getField(table, key, schemaIndex); | ||
} | ||
|
||
function isStore() public view {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not blocking for this PR but we should update these usages to use the
@latticexyz/std-contracts
import formatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
considering it's a breaking change and not relevant for v2, is it worth it for v1 packages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do breaking changes all the time 🙈