Skip to content

Commit

Permalink
update comments, build
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1a committed Aug 15, 2023
1 parent 01bc59a commit 649b2d2
Show file tree
Hide file tree
Showing 14 changed files with 626 additions and 188 deletions.
40 changes: 30 additions & 10 deletions e2e/packages/contracts/src/codegen/tables/NumberList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,30 @@ library NumberList {
}
}

/** Get an item of value (unchecked, returns invalid data if index overflows) */
/**
* Get an item of value
* (unchecked, returns invalid data if index overflows)
*/
function getItem(uint256 _index) internal view returns (uint32) {
bytes32[] memory _keyTuple = new bytes32[](0);

bytes memory _blob = StoreSwitch.getFieldSlice(_tableId, _keyTuple, 0, getSchema(), _index * 4, (_index + 1) * 4);
return (uint32(Bytes.slice4(_blob, 0)));
unchecked {
bytes memory _blob = StoreSwitch.getFieldSlice(_tableId, _keyTuple, 0, getSchema(), _index * 4, (_index + 1) * 4);
return (uint32(Bytes.slice4(_blob, 0)));
}
}

/** Get an item of value (using the specified store) (unchecked, returns invalid data if index overflows) */
/**
* Get an item of value (using the specified store)
* (unchecked, returns invalid data if index overflows)
*/
function getItem(IStore _store, uint256 _index) internal view returns (uint32) {
bytes32[] memory _keyTuple = new bytes32[](0);

bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, getSchema(), _index * 4, (_index + 1) * 4);
return (uint32(Bytes.slice4(_blob, 0)));
unchecked {
bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, getSchema(), _index * 4, (_index + 1) * 4);
return (uint32(Bytes.slice4(_blob, 0)));
}
}

/** Push an element to value */
Expand Down Expand Up @@ -158,18 +168,28 @@ library NumberList {
_store.popFromField(_tableId, _keyTuple, 0, 4);
}

/** Update an element of value at `_index` */
/**
* Update an element of value at `_index`
* (checked only to prevent modifying other tables; can corrupt own data if index overflows)
*/
function update(uint256 _index, uint32 _element) internal {
bytes32[] memory _keyTuple = new bytes32[](0);

StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)));
unchecked {
StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)));
}
}

/** Update an element of value (using the specified store) at `_index` */
/**
* Update an element of value (using the specified store) at `_index`
* (checked only to prevent modifying other tables; can corrupt own data if index overflows)
*/
function update(IStore _store, uint256 _index, uint32 _element) internal {
bytes32[] memory _keyTuple = new bytes32[](0);

_store.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)));
unchecked {
_store.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)));
}
}

/** Tightly pack full data using this table's schema */
Expand Down
Loading

0 comments on commit 649b2d2

Please sign in to comment.