From 65c9546c4ee8a410b21d032f02b0050442152e7e Mon Sep 17 00:00:00 2001 From: dk1a Date: Wed, 20 Sep 2023 14:17:37 +0300 Subject: [PATCH] refactor(store): always render field methods with suffix and conditionally without (#1550) --- .changeset/curvy-tables-melt.md | 6 + .changeset/olive-pigs-fold.md | 6 + .../contracts/src/codegen/tables/Number.sol | 51 ++++ .../src/codegen/tables/NumberList.sol | 199 ++++++++++++ .../src/codegen/tables/CounterTable.sol | 45 +++ .../src/codegen/tables/Inventory.sol | 68 +++++ .../src/codegen/render-solidity/common.ts | 16 + .../src/codegen/render-solidity/types.ts | 1 - .../store/src/codegen/tables/Callbacks.sol | 227 ++++++++++++++ packages/store/src/codegen/tables/Hooks.sol | 227 ++++++++++++++ .../store/src/codegen/tables/KeyEncoding.sol | 112 +++++++ .../store/src/codegen/tables/StoreHooks.sol | 227 ++++++++++++++ packages/store/ts/codegen/field.ts | 283 +++++++++--------- packages/store/ts/codegen/tableOptions.ts | 6 +- packages/store/ts/codegen/types.ts | 2 + .../src/modules/core/tables/Balances.sol | 51 ++++ .../src/modules/core/tables/ResourceType.sol | 51 ++++ .../src/modules/core/tables/SystemHooks.sol | 227 ++++++++++++++ .../modules/core/tables/SystemRegistry.sol | 51 ++++ .../keyswithvalue/tables/KeysWithValue.sol | 253 ++++++++++++++++ .../tables/CallboundDelegations.sol | 104 +++++++ .../tables/TimeboundDelegations.sol | 61 ++++ .../uniqueentity/tables/UniqueEntity.sol | 45 +++ packages/world/src/tables/Delegations.sol | 72 +++++ .../world/src/tables/InstalledModules.sol | 61 ++++ packages/world/src/tables/NamespaceOwner.sol | 51 ++++ packages/world/src/tables/ResourceAccess.sol | 57 ++++ packages/world/test/tables/AddressArray.sol | 227 ++++++++++++++ packages/world/test/tables/Bool.sol | 45 +++ .../contracts/src/codegen/tables/Counter.sol | 45 +++ .../contracts/src/codegen/tables/Counter.sol | 45 +++ .../contracts/src/codegen/tables/Counter.sol | 45 +++ 32 files changed, 2829 insertions(+), 138 deletions(-) create mode 100644 .changeset/curvy-tables-melt.md create mode 100644 .changeset/olive-pigs-fold.md diff --git a/.changeset/curvy-tables-melt.md b/.changeset/curvy-tables-melt.md new file mode 100644 index 0000000000..d974279b9e --- /dev/null +++ b/.changeset/curvy-tables-melt.md @@ -0,0 +1,6 @@ +--- +"@latticexyz/common": major +--- + +- Add `renderWithFieldSuffix` helper method to always render a field function with a suffix, and optionally render the same function without a suffix. +- Remove `methodNameSuffix` from `RenderField` interface, because the suffix is now computed as part of `renderWithFieldSuffix`. diff --git a/.changeset/olive-pigs-fold.md b/.changeset/olive-pigs-fold.md new file mode 100644 index 0000000000..f7f06156af --- /dev/null +++ b/.changeset/olive-pigs-fold.md @@ -0,0 +1,6 @@ +--- +"@latticexyz/store": major +--- + +- Always render field methods with a suffix in tablegen (they used to not be rendered if field methods without a suffix were rendered). +- Add `withSuffixlessFieldMethods` to `RenderTableOptions`, which indicates that field methods without a suffix should be rendered. diff --git a/e2e/packages/contracts/src/codegen/tables/Number.sol b/e2e/packages/contracts/src/codegen/tables/Number.sol index b75e730224..246f60517d 100644 --- a/e2e/packages/contracts/src/codegen/tables/Number.sol +++ b/e2e/packages/contracts/src/codegen/tables/Number.sol @@ -74,6 +74,33 @@ library Number { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue(uint32 key) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(key)); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value */ + function _getValue(uint32 key) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(key)); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, uint32 key) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(key)); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + /** Get value */ function get(uint32 key) internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -101,6 +128,30 @@ library Number { return (uint32(bytes4(_blob))); } + /** Set value */ + function setValue(uint32 key, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(key)); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(uint32 key, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(key)); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint32 key, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(key)); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + /** Set value */ function set(uint32 key, uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](1); diff --git a/e2e/packages/contracts/src/codegen/tables/NumberList.sol b/e2e/packages/contracts/src/codegen/tables/NumberList.sol index 7b03f525db..4f0a11dccc 100644 --- a/e2e/packages/contracts/src/codegen/tables/NumberList.sol +++ b/e2e/packages/contracts/src/codegen/tables/NumberList.sol @@ -72,6 +72,30 @@ library NumberList { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue() internal view returns (uint32[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get value */ + function _getValue() internal view returns (uint32[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store) internal view returns (uint32[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + /** Get value */ function get() internal view returns (uint32[] memory value) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -96,6 +120,27 @@ library NumberList { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); } + /** Set value */ + function setValue(uint32[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(uint32[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreCore.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint32[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + /** Set value */ function set(uint32[] memory value) internal { bytes32[] memory _keyTuple = new bytes32[](0); @@ -117,6 +162,36 @@ library NumberList { _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); } + /** Get the length of value */ + function lengthValue() internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](0); + + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 4; + } + } + + /** Get the length of value */ + function _lengthValue() internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](0); + + uint256 _byteLength = StoreCore.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 4; + } + } + + /** Get the length of value (using the specified store) */ + function lengthValue(IStore _store) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](0); + + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 4; + } + } + /** Get the length of value */ function length() internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -147,6 +222,52 @@ library NumberList { } } + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(uint256 _index) internal view returns (uint32) { + bytes32[] memory _keyTuple = new bytes32[](0); + + unchecked { + bytes memory _blob = StoreSwitch.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 4, + (_index + 1) * 4 + ); + return (uint32(bytes4(_blob))); + } + } + + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function _getItemValue(uint256 _index) internal view returns (uint32) { + bytes32[] memory _keyTuple = new bytes32[](0); + + unchecked { + bytes memory _blob = StoreCore.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 4, (_index + 1) * 4); + return (uint32(bytes4(_blob))); + } + } + + /** + * Get an item of value (using the specified store) + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(IStore _store, uint256 _index) internal view returns (uint32) { + bytes32[] memory _keyTuple = new bytes32[](0); + + unchecked { + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 4, (_index + 1) * 4); + return (uint32(bytes4(_blob))); + } + } + /** * Get an item of value * (unchecked, returns invalid data if index overflows) @@ -193,6 +314,27 @@ library NumberList { } } + /** Push an element to value */ + function pushValue(uint32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value */ + function _pushValue(uint32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreCore.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value (using the specified store) */ + function pushValue(IStore _store, uint32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + /** Push an element to value */ function push(uint32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](0); @@ -214,6 +356,27 @@ library NumberList { _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); } + /** Pop an element from value */ + function popValue() internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 4, _fieldLayout); + } + + /** Pop an element from value */ + function _popValue() internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreCore.popFromField(_tableId, _keyTuple, 0, 4, _fieldLayout); + } + + /** Pop an element from value (using the specified store) */ + function popValue(IStore _store) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.popFromField(_tableId, _keyTuple, 0, 4, _fieldLayout); + } + /** Pop an element from value */ function pop() internal { bytes32[] memory _keyTuple = new bytes32[](0); @@ -235,6 +398,42 @@ library NumberList { _store.popFromField(_tableId, _keyTuple, 0, 4, _fieldLayout); } + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function updateValue(uint256 _index, uint32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + unchecked { + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function _updateValue(uint256 _index, uint32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + unchecked { + StoreCore.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * 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 updateValue(IStore _store, uint256 _index, uint32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + unchecked { + _store.updateInField(_tableId, _keyTuple, 0, _index * 4, abi.encodePacked((_element)), _fieldLayout); + } + } + /** * Update an element of value at `_index` * (checked only to prevent modifying other tables; can corrupt own data if index overflows) diff --git a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol index 21056806b4..0eee6c3ff4 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/CounterTable.sol @@ -72,6 +72,30 @@ library CounterTable { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue() internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value */ + function _getValue() internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + /** Get value */ function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -96,6 +120,27 @@ library CounterTable { return (uint32(bytes4(_blob))); } + /** Set value */ + function setValue(uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + /** Set value */ function set(uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); diff --git a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol index 38f67b2815..7156ea2c10 100644 --- a/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol +++ b/examples/minimal/packages/contracts/src/codegen/tables/Inventory.sol @@ -78,6 +78,44 @@ library Inventory { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get amount */ + function getAmount(address owner, uint32 item, uint32 itemVariant) internal view returns (uint32 amount) { + bytes32[] memory _keyTuple = new bytes32[](3); + _keyTuple[0] = bytes32(uint256(uint160(owner))); + _keyTuple[1] = bytes32(uint256(item)); + _keyTuple[2] = bytes32(uint256(itemVariant)); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get amount */ + function _getAmount(address owner, uint32 item, uint32 itemVariant) internal view returns (uint32 amount) { + bytes32[] memory _keyTuple = new bytes32[](3); + _keyTuple[0] = bytes32(uint256(uint160(owner))); + _keyTuple[1] = bytes32(uint256(item)); + _keyTuple[2] = bytes32(uint256(itemVariant)); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get amount (using the specified store) */ + function getAmount( + IStore _store, + address owner, + uint32 item, + uint32 itemVariant + ) internal view returns (uint32 amount) { + bytes32[] memory _keyTuple = new bytes32[](3); + _keyTuple[0] = bytes32(uint256(uint160(owner))); + _keyTuple[1] = bytes32(uint256(item)); + _keyTuple[2] = bytes32(uint256(itemVariant)); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + /** Get amount */ function get(address owner, uint32 item, uint32 itemVariant) internal view returns (uint32 amount) { bytes32[] memory _keyTuple = new bytes32[](3); @@ -111,6 +149,36 @@ library Inventory { return (uint32(bytes4(_blob))); } + /** Set amount */ + function setAmount(address owner, uint32 item, uint32 itemVariant, uint32 amount) internal { + bytes32[] memory _keyTuple = new bytes32[](3); + _keyTuple[0] = bytes32(uint256(uint160(owner))); + _keyTuple[1] = bytes32(uint256(item)); + _keyTuple[2] = bytes32(uint256(itemVariant)); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), _fieldLayout); + } + + /** Set amount */ + function _setAmount(address owner, uint32 item, uint32 itemVariant, uint32 amount) internal { + bytes32[] memory _keyTuple = new bytes32[](3); + _keyTuple[0] = bytes32(uint256(uint160(owner))); + _keyTuple[1] = bytes32(uint256(item)); + _keyTuple[2] = bytes32(uint256(itemVariant)); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), _fieldLayout); + } + + /** Set amount (using the specified store) */ + function setAmount(IStore _store, address owner, uint32 item, uint32 itemVariant, uint32 amount) internal { + bytes32[] memory _keyTuple = new bytes32[](3); + _keyTuple[0] = bytes32(uint256(uint160(owner))); + _keyTuple[1] = bytes32(uint256(item)); + _keyTuple[2] = bytes32(uint256(itemVariant)); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((amount)), _fieldLayout); + } + /** Set amount */ function set(address owner, uint32 item, uint32 itemVariant, uint32 amount) internal { bytes32[] memory _keyTuple = new bytes32[](3); diff --git a/packages/common/src/codegen/render-solidity/common.ts b/packages/common/src/codegen/render-solidity/common.ts index 4f20e8d965..1a7a95ebec 100644 --- a/packages/common/src/codegen/render-solidity/common.ts +++ b/packages/common/src/codegen/render-solidity/common.ts @@ -146,6 +146,22 @@ export function renderWithStore( return result; } +export function renderWithFieldSuffix( + withSuffixlessFieldMethods: boolean, + fieldName: string, + callback: (_methodNameSuffix: string) => string +): string { + const methodNameSuffix = `${fieldName[0].toUpperCase()}${fieldName.slice(1)}`; + let result = ""; + result += callback(methodNameSuffix); + + if (withSuffixlessFieldMethods) { + result += "\n" + callback(""); + } + + return result; +} + export function renderTableId(staticResourceData: StaticResourceData): { hardcodedTableId: string; tableIdDefinition: string; diff --git a/packages/common/src/codegen/render-solidity/types.ts b/packages/common/src/codegen/render-solidity/types.ts index 5ec14b3b5e..cb65df5e02 100644 --- a/packages/common/src/codegen/render-solidity/types.ts +++ b/packages/common/src/codegen/render-solidity/types.ts @@ -43,7 +43,6 @@ export interface RenderKeyTuple extends RenderType { export interface RenderField extends RenderType { arrayElement: RenderType | undefined; name: string; - methodNameSuffix: string; } export interface RenderStaticField extends RenderField { diff --git a/packages/store/src/codegen/tables/Callbacks.sol b/packages/store/src/codegen/tables/Callbacks.sol index 148bbe1fb8..f13f8f9f9e 100644 --- a/packages/store/src/codegen/tables/Callbacks.sol +++ b/packages/store/src/codegen/tables/Callbacks.sol @@ -74,6 +74,33 @@ library Callbacks { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue(bytes32 key) internal view returns (bytes24[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); + } + + /** Get value */ + function _getValue(bytes32 key) internal view returns (bytes24[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, bytes32 key) internal view returns (bytes24[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); + } + /** Get value */ function get(bytes32 key) internal view returns (bytes24[] memory value) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -101,6 +128,30 @@ library Callbacks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes24()); } + /** Set value */ + function setValue(bytes32 key, bytes24[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(bytes32 key, bytes24[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, bytes32 key, bytes24[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + /** Set value */ function set(bytes32 key, bytes24[] memory value) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -125,6 +176,39 @@ library Callbacks { _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); } + /** Get the length of value */ + function lengthValue(bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 24; + } + } + + /** Get the length of value */ + function _lengthValue(bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = StoreCore.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 24; + } + } + + /** Get the length of value (using the specified store) */ + function lengthValue(IStore _store, bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 24; + } + } + /** Get the length of value */ function length(bytes32 key) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -158,6 +242,62 @@ library Callbacks { } } + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(bytes32 key, uint256 _index) internal view returns (bytes24) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = StoreSwitch.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 24, + (_index + 1) * 24 + ); + return (bytes24(_blob)); + } + } + + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function _getItemValue(bytes32 key, uint256 _index) internal view returns (bytes24) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = StoreCore.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 24, + (_index + 1) * 24 + ); + return (bytes24(_blob)); + } + } + + /** + * Get an item of value (using the specified store) + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(IStore _store, bytes32 key, uint256 _index) internal view returns (bytes24) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 24, (_index + 1) * 24); + return (bytes24(_blob)); + } + } + /** * Get an item of value * (unchecked, returns invalid data if index overflows) @@ -214,6 +354,30 @@ library Callbacks { } } + /** Push an element to value */ + function pushValue(bytes32 key, bytes24 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value */ + function _pushValue(bytes32 key, bytes24 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value (using the specified store) */ + function pushValue(IStore _store, bytes32 key, bytes24 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + /** Push an element to value */ function push(bytes32 key, bytes24 _element) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -238,6 +402,30 @@ library Callbacks { _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); } + /** Pop an element from value */ + function popValue(bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 24, _fieldLayout); + } + + /** Pop an element from value */ + function _popValue(bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.popFromField(_tableId, _keyTuple, 0, 24, _fieldLayout); + } + + /** Pop an element from value (using the specified store) */ + function popValue(IStore _store, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.popFromField(_tableId, _keyTuple, 0, 24, _fieldLayout); + } + /** Pop an element from value */ function pop(bytes32 key) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -262,6 +450,45 @@ library Callbacks { _store.popFromField(_tableId, _keyTuple, 0, 24, _fieldLayout); } + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function updateValue(bytes32 key, uint256 _index, bytes24 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 24, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function _updateValue(bytes32 key, uint256 _index, bytes24 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + StoreCore.updateInField(_tableId, _keyTuple, 0, _index * 24, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * 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 updateValue(IStore _store, bytes32 key, uint256 _index, bytes24 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + _store.updateInField(_tableId, _keyTuple, 0, _index * 24, abi.encodePacked((_element)), _fieldLayout); + } + } + /** * Update an element of value at `_index` * (checked only to prevent modifying other tables; can corrupt own data if index overflows) diff --git a/packages/store/src/codegen/tables/Hooks.sol b/packages/store/src/codegen/tables/Hooks.sol index 5695f5a9a4..28c6a546bc 100644 --- a/packages/store/src/codegen/tables/Hooks.sol +++ b/packages/store/src/codegen/tables/Hooks.sol @@ -71,6 +71,33 @@ library Hooks { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue(bytes32 _tableId, bytes32 key) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** Get value */ + function _getValue(bytes32 _tableId, bytes32 key) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, bytes32 _tableId, bytes32 key) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + /** Get value */ function get(bytes32 _tableId, bytes32 key) internal view returns (bytes21[] memory value) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -98,6 +125,30 @@ library Hooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } + /** Set value */ + function setValue(bytes32 _tableId, bytes32 key, bytes21[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(bytes32 _tableId, bytes32 key, bytes21[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, bytes32 _tableId, bytes32 key, bytes21[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + /** Set value */ function set(bytes32 _tableId, bytes32 key, bytes21[] memory value) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -122,6 +173,39 @@ library Hooks { _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); } + /** Get the length of value */ + function lengthValue(bytes32 _tableId, bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 21; + } + } + + /** Get the length of value */ + function _lengthValue(bytes32 _tableId, bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = StoreCore.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 21; + } + } + + /** Get the length of value (using the specified store) */ + function lengthValue(IStore _store, bytes32 _tableId, bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 21; + } + } + /** Get the length of value */ function length(bytes32 _tableId, bytes32 key) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -155,6 +239,62 @@ library Hooks { } } + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(bytes32 _tableId, bytes32 key, uint256 _index) internal view returns (bytes21) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = StoreSwitch.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 21, + (_index + 1) * 21 + ); + return (bytes21(_blob)); + } + } + + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function _getItemValue(bytes32 _tableId, bytes32 key, uint256 _index) internal view returns (bytes21) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = StoreCore.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 21, + (_index + 1) * 21 + ); + return (bytes21(_blob)); + } + } + + /** + * Get an item of value (using the specified store) + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(IStore _store, bytes32 _tableId, bytes32 key, uint256 _index) internal view returns (bytes21) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 21, (_index + 1) * 21); + return (bytes21(_blob)); + } + } + /** * Get an item of value * (unchecked, returns invalid data if index overflows) @@ -211,6 +351,30 @@ library Hooks { } } + /** Push an element to value */ + function pushValue(bytes32 _tableId, bytes32 key, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value */ + function _pushValue(bytes32 _tableId, bytes32 key, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value (using the specified store) */ + function pushValue(IStore _store, bytes32 _tableId, bytes32 key, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + /** Push an element to value */ function push(bytes32 _tableId, bytes32 key, bytes21 _element) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -235,6 +399,30 @@ library Hooks { _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); } + /** Pop an element from value */ + function popValue(bytes32 _tableId, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); + } + + /** Pop an element from value */ + function _popValue(bytes32 _tableId, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); + } + + /** Pop an element from value (using the specified store) */ + function popValue(IStore _store, bytes32 _tableId, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); + } + /** Pop an element from value */ function pop(bytes32 _tableId, bytes32 key) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -259,6 +447,45 @@ library Hooks { _store.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); } + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function updateValue(bytes32 _tableId, bytes32 key, uint256 _index, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function _updateValue(bytes32 _tableId, bytes32 key, uint256 _index, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + StoreCore.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * 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 updateValue(IStore _store, bytes32 _tableId, bytes32 key, uint256 _index, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + _store.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), _fieldLayout); + } + } + /** * Update an element of value at `_index` * (checked only to prevent modifying other tables; can corrupt own data if index overflows) diff --git a/packages/store/src/codegen/tables/KeyEncoding.sol b/packages/store/src/codegen/tables/KeyEncoding.sol index 4a5afcc886..132acd4eb1 100644 --- a/packages/store/src/codegen/tables/KeyEncoding.sol +++ b/packages/store/src/codegen/tables/KeyEncoding.sol @@ -87,6 +87,70 @@ library KeyEncoding { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue( + uint256 k1, + int32 k2, + bytes16 k3, + address k4, + bool k5, + ExampleEnum k6 + ) internal view returns (bool value) { + 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))); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** Get value */ + function _getValue( + uint256 k1, + int32 k2, + bytes16 k3, + address k4, + bool k5, + ExampleEnum k6 + ) internal view returns (bool value) { + 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))); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** Get value (using the specified store) */ + function getValue( + IStore _store, + uint256 k1, + int32 k2, + bytes16 k3, + address k4, + bool k5, + ExampleEnum k6 + ) internal view returns (bool value) { + 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))); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + /** Get value */ function get( uint256 k1, @@ -151,6 +215,54 @@ library KeyEncoding { return (_toBool(uint8(bytes1(_blob)))); } + /** Set value */ + function setValue(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, ExampleEnum k6, bool value) internal { + 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))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, ExampleEnum k6, bool value) internal { + 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))); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue( + IStore _store, + uint256 k1, + int32 k2, + bytes16 k3, + address k4, + bool k5, + ExampleEnum k6, + bool value + ) internal { + 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))); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + /** Set value */ function set(uint256 k1, int32 k2, bytes16 k3, address k4, bool k5, ExampleEnum k6, bool value) internal { bytes32[] memory _keyTuple = new bytes32[](6); diff --git a/packages/store/src/codegen/tables/StoreHooks.sol b/packages/store/src/codegen/tables/StoreHooks.sol index 70e14eae9f..11c11e6c84 100644 --- a/packages/store/src/codegen/tables/StoreHooks.sol +++ b/packages/store/src/codegen/tables/StoreHooks.sol @@ -74,6 +74,33 @@ library StoreHooks { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue(bytes32 key) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** Get value */ + function _getValue(bytes32 key) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, bytes32 key) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + /** Get value */ function get(bytes32 key) internal view returns (bytes21[] memory value) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -101,6 +128,30 @@ library StoreHooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } + /** Set value */ + function setValue(bytes32 key, bytes21[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(bytes32 key, bytes21[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, bytes32 key, bytes21[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + /** Set value */ function set(bytes32 key, bytes21[] memory value) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -125,6 +176,39 @@ library StoreHooks { _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); } + /** Get the length of value */ + function lengthValue(bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 21; + } + } + + /** Get the length of value */ + function _lengthValue(bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = StoreCore.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 21; + } + } + + /** Get the length of value (using the specified store) */ + function lengthValue(IStore _store, bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 21; + } + } + /** Get the length of value */ function length(bytes32 key) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -158,6 +242,62 @@ library StoreHooks { } } + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(bytes32 key, uint256 _index) internal view returns (bytes21) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = StoreSwitch.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 21, + (_index + 1) * 21 + ); + return (bytes21(_blob)); + } + } + + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function _getItemValue(bytes32 key, uint256 _index) internal view returns (bytes21) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = StoreCore.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 21, + (_index + 1) * 21 + ); + return (bytes21(_blob)); + } + } + + /** + * Get an item of value (using the specified store) + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(IStore _store, bytes32 key, uint256 _index) internal view returns (bytes21) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 21, (_index + 1) * 21); + return (bytes21(_blob)); + } + } + /** * Get an item of value * (unchecked, returns invalid data if index overflows) @@ -214,6 +354,30 @@ library StoreHooks { } } + /** Push an element to value */ + function pushValue(bytes32 key, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value */ + function _pushValue(bytes32 key, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value (using the specified store) */ + function pushValue(IStore _store, bytes32 key, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + /** Push an element to value */ function push(bytes32 key, bytes21 _element) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -238,6 +402,30 @@ library StoreHooks { _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); } + /** Pop an element from value */ + function popValue(bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); + } + + /** Pop an element from value */ + function _popValue(bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); + } + + /** Pop an element from value (using the specified store) */ + function popValue(IStore _store, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); + } + /** Pop an element from value */ function pop(bytes32 key) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -262,6 +450,45 @@ library StoreHooks { _store.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); } + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function updateValue(bytes32 key, uint256 _index, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function _updateValue(bytes32 key, uint256 _index, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + StoreCore.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * 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 updateValue(IStore _store, bytes32 key, uint256 _index, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + _store.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), _fieldLayout); + } + } + /** * Update an element of value at `_index` * (checked only to prevent modifying other tables; can corrupt own data if index overflows) diff --git a/packages/store/ts/codegen/field.ts b/packages/store/ts/codegen/field.ts index 2b811b864c..c65307e2f7 100644 --- a/packages/store/ts/codegen/field.ts +++ b/packages/store/ts/codegen/field.ts @@ -3,6 +3,7 @@ import { renderCommonData, RenderField, RenderType, + renderWithFieldSuffix, renderWithStore, } from "@latticexyz/common/codegen"; import { RenderTableOptions } from "./types"; @@ -17,159 +18,173 @@ export function renderFieldMethods(options: RenderTableOptions) { const _typedFieldName = `${field.typeWithLocation} ${field.name}`; - result += renderWithStore( - storeArgument, - (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` - /** Get ${field.name}${_commentSuffix} */ - function ${_methodNamePrefix}get${field.methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal view returns (${_typedFieldName}) { - ${_keyTupleDefinition} - ${ - field.isDynamic - ? `bytes memory _blob = ${_store}.getDynamicField( - _tableId, - _keyTuple, - ${schemaIndex - options.staticFields.length} - );` - : `bytes32 _blob = ${_store}.getStaticField( - _tableId, - _keyTuple, - ${schemaIndex}, - _fieldLayout - );` - } - return ${renderDecodeFieldSingle(field)}; - } - ` - ); - - result += renderWithStore( - storeArgument, - (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` - /** Set ${field.name}${_commentSuffix} */ - function ${_methodNamePrefix}set${field.methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - _typedFieldName, - ])}) internal { - ${_keyTupleDefinition} - ${_store}.setField(_tableId, _keyTuple, ${schemaIndex}, ${renderEncodeFieldSingle(field)}, _fieldLayout); - } - ` - ); - - if (field.isDynamic) { - const portionData = fieldPortionData(field); - - result += renderWithStore( + result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => + renderWithStore( storeArgument, (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` - /** Get the length of ${field.name}${_commentSuffix} */ - function ${_methodNamePrefix}length${field.methodNameSuffix}(${renderArguments([ + /** Get ${field.name}${_commentSuffix} */ + function ${_methodNamePrefix}get${_methodNameSuffix}(${renderArguments([ _typedStore, _typedTableId, _typedKeyArgs, - ])}) internal view returns (uint256) { - ${_keyTupleDefinition} - uint256 _byteLength = ${_store}.getFieldLength(_tableId, _keyTuple, ${schemaIndex}, _fieldLayout); - unchecked { - return _byteLength / ${portionData.elementLength}; + ])}) internal view returns (${_typedFieldName}) { + ${_keyTupleDefinition} + ${ + field.isDynamic + ? `bytes memory _blob = ${_store}.getDynamicField( + _tableId, + _keyTuple, + ${schemaIndex - options.staticFields.length} + );` + : `bytes32 _blob = ${_store}.getStaticField( + _tableId, + _keyTuple, + ${schemaIndex}, + _fieldLayout + );` + } + return ${renderDecodeFieldSingle(field)}; } - } - ` - ); + ` + ) + ); - result += renderWithStore( + result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => + renderWithStore( storeArgument, (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` - /** - * Get an item of ${field.name}${_commentSuffix} - * (unchecked, returns invalid data if index overflows) - */ - function ${_methodNamePrefix}getItem${field.methodNameSuffix}(${renderArguments([ + /** Set ${field.name}${_commentSuffix} */ + function ${_methodNamePrefix}set${_methodNameSuffix}(${renderArguments([ _typedStore, _typedTableId, _typedKeyArgs, - "uint256 _index", - ])}) internal view returns (${portionData.typeWithLocation}) { - ${_keyTupleDefinition} - unchecked { - bytes memory _blob = ${_store}.getFieldSlice( - _tableId, - _keyTuple, - ${schemaIndex}, - _fieldLayout, - _index * ${portionData.elementLength}, - (_index + 1) * ${portionData.elementLength} - ); - return ${portionData.decoded}; + _typedFieldName, + ])}) internal { + ${_keyTupleDefinition} + ${_store}.setField(_tableId, _keyTuple, ${schemaIndex}, ${renderEncodeFieldSingle(field)}, _fieldLayout); } - } - ` + ` + ) + ); + + if (field.isDynamic) { + const portionData = fieldPortionData(field); + + result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => + renderWithStore( + storeArgument, + (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` + /** Get the length of ${field.name}${_commentSuffix} */ + function ${_methodNamePrefix}length${_methodNameSuffix}(${renderArguments([ + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal view returns (uint256) { + ${_keyTupleDefinition} + uint256 _byteLength = ${_store}.getFieldLength(_tableId, _keyTuple, ${schemaIndex}, _fieldLayout); + unchecked { + return _byteLength / ${portionData.elementLength}; + } + } + ` + ) ); - result += renderWithStore( - storeArgument, - (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` - /** Push ${portionData.title} to ${field.name}${_commentSuffix} */ - function ${_methodNamePrefix}push${field.methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - `${portionData.typeWithLocation} ${portionData.name}`, - ])}) internal { - ${_keyTupleDefinition} - ${_store}.pushToField(_tableId, _keyTuple, ${schemaIndex}, ${portionData.encoded}, _fieldLayout); - } - ` + result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => + renderWithStore( + storeArgument, + (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` + /** + * Get an item of ${field.name}${_commentSuffix} + * (unchecked, returns invalid data if index overflows) + */ + function ${_methodNamePrefix}getItem${_methodNameSuffix}(${renderArguments([ + _typedStore, + _typedTableId, + _typedKeyArgs, + "uint256 _index", + ])}) internal view returns (${portionData.typeWithLocation}) { + ${_keyTupleDefinition} + unchecked { + bytes memory _blob = ${_store}.getFieldSlice( + _tableId, + _keyTuple, + ${schemaIndex}, + _fieldLayout, + _index * ${portionData.elementLength}, + (_index + 1) * ${portionData.elementLength} + ); + return ${portionData.decoded}; + } + } + ` + ) ); - result += renderWithStore( - storeArgument, - (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` - /** Pop ${portionData.title} from ${field.name}${_commentSuffix} */ - function ${_methodNamePrefix}pop${field.methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal { - ${_keyTupleDefinition} - ${_store}.popFromField(_tableId, _keyTuple, ${schemaIndex}, ${portionData.elementLength}, _fieldLayout); - } - ` + result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => + renderWithStore( + storeArgument, + (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` + /** Push ${portionData.title} to ${field.name}${_commentSuffix} */ + function ${_methodNamePrefix}push${_methodNameSuffix}(${renderArguments([ + _typedStore, + _typedTableId, + _typedKeyArgs, + `${portionData.typeWithLocation} ${portionData.name}`, + ])}) internal { + ${_keyTupleDefinition} + ${_store}.pushToField(_tableId, _keyTuple, ${schemaIndex}, ${portionData.encoded}, _fieldLayout); + } + ` + ) ); - result += renderWithStore( - storeArgument, - (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` - /** - * Update ${portionData.title} of ${field.name}${_commentSuffix} at \`_index\` - * (checked only to prevent modifying other tables; can corrupt own data if index overflows) - */ - function ${_methodNamePrefix}update${field.methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - "uint256 _index", - `${portionData.typeWithLocation} ${portionData.name}`, - ])}) internal { - ${_keyTupleDefinition} - unchecked { - ${_store}.updateInField( - _tableId, - _keyTuple, - ${schemaIndex}, - _index * ${portionData.elementLength}, - ${portionData.encoded}, - _fieldLayout - ); - } - } - ` + result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => + renderWithStore( + storeArgument, + (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` + /** Pop ${portionData.title} from ${field.name}${_commentSuffix} */ + function ${_methodNamePrefix}pop${_methodNameSuffix}(${renderArguments([ + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal { + ${_keyTupleDefinition} + ${_store}.popFromField(_tableId, _keyTuple, ${schemaIndex}, ${portionData.elementLength}, _fieldLayout); + } + ` + ) + ); + + result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => + renderWithStore( + storeArgument, + (_typedStore, _store, _commentSuffix, _untypedStore, _methodNamePrefix) => ` + /** + * Update ${portionData.title} of ${field.name}${_commentSuffix} at \`_index\` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function ${_methodNamePrefix}update${_methodNameSuffix}(${renderArguments([ + _typedStore, + _typedTableId, + _typedKeyArgs, + "uint256 _index", + `${portionData.typeWithLocation} ${portionData.name}`, + ])}) internal { + ${_keyTupleDefinition} + unchecked { + ${_store}.updateInField( + _tableId, + _keyTuple, + ${schemaIndex}, + _index * ${portionData.elementLength}, + ${portionData.encoded}, + _fieldLayout + ); + } + } + ` + ) ); } } diff --git a/packages/store/ts/codegen/tableOptions.ts b/packages/store/ts/codegen/tableOptions.ts index fa38785757..fe66118099 100644 --- a/packages/store/ts/codegen/tableOptions.ts +++ b/packages/store/ts/codegen/tableOptions.ts @@ -28,8 +28,8 @@ export function getTableOptions(config: StoreConfig): TableOptions[] { const withStruct = tableData.dataStruct; // operate on all fields at once; for only 1 field keep them only if struct is also kept const withRecordMethods = withStruct || Object.keys(tableData.valueSchema).length > 1; - // field methods can be simply get/set if there's only 1 field and no record methods - const noFieldMethodSuffix = !withRecordMethods && Object.keys(tableData.valueSchema).length === 1; + // field methods can include simply get/set if there's only 1 field and no record methods + const withSuffixlessFieldMethods = !withRecordMethods && Object.keys(tableData.valueSchema).length === 1; // list of any symbols that need to be imported const imports: RelativeImportDatum[] = []; @@ -62,7 +62,6 @@ export function getTableOptions(config: StoreConfig): TableOptions[] { ...renderType, arrayElement: elementType !== undefined ? getSchemaTypeInfo(elementType) : undefined, name, - methodNameSuffix: noFieldMethodSuffix ? "" : `${name[0].toUpperCase()}${name.slice(1)}`, }; return field; }); @@ -100,6 +99,7 @@ export function getTableOptions(config: StoreConfig): TableOptions[] { withFieldMethods: !tableData.ephemeral, withRecordMethods: withRecordMethods && !tableData.ephemeral, withEphemeralMethods: tableData.ephemeral, + withSuffixlessFieldMethods, storeArgument: tableData.storeArgument, }, }); diff --git a/packages/store/ts/codegen/types.ts b/packages/store/ts/codegen/types.ts index 2e353f326c..ff01d2e2de 100644 --- a/packages/store/ts/codegen/types.ts +++ b/packages/store/ts/codegen/types.ts @@ -28,6 +28,8 @@ export interface RenderTableOptions { withRecordMethods: boolean; /** Whether to render emitEphemeral methods */ withEphemeralMethods: boolean; + /** Whether to additionally render field methods without a field name suffix */ + withSuffixlessFieldMethods: boolean; /** Whether to render additional methods that accept a manual `IStore` argument */ storeArgument: boolean; } diff --git a/packages/world/src/modules/core/tables/Balances.sol b/packages/world/src/modules/core/tables/Balances.sol index 05e64fc99f..d2f043c64f 100644 --- a/packages/world/src/modules/core/tables/Balances.sol +++ b/packages/world/src/modules/core/tables/Balances.sol @@ -74,6 +74,33 @@ library Balances { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get balance */ + function getBalance(bytes16 namespace) internal view returns (uint256 balance) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** Get balance */ + function _getBalance(bytes16 namespace) internal view returns (uint256 balance) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** Get balance (using the specified store) */ + function getBalance(IStore _store, bytes16 namespace) internal view returns (uint256 balance) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + /** Get balance */ function get(bytes16 namespace) internal view returns (uint256 balance) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -101,6 +128,30 @@ library Balances { return (uint256(bytes32(_blob))); } + /** Set balance */ + function setBalance(bytes16 namespace, uint256 balance) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), _fieldLayout); + } + + /** Set balance */ + function _setBalance(bytes16 namespace, uint256 balance) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), _fieldLayout); + } + + /** Set balance (using the specified store) */ + function setBalance(IStore _store, bytes16 namespace, uint256 balance) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((balance)), _fieldLayout); + } + /** Set balance */ function set(bytes16 namespace, uint256 balance) internal { bytes32[] memory _keyTuple = new bytes32[](1); diff --git a/packages/world/src/modules/core/tables/ResourceType.sol b/packages/world/src/modules/core/tables/ResourceType.sol index ac9983441a..3eede246e2 100644 --- a/packages/world/src/modules/core/tables/ResourceType.sol +++ b/packages/world/src/modules/core/tables/ResourceType.sol @@ -77,6 +77,33 @@ library ResourceType { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get resourceType */ + function getResourceType(bytes32 resourceSelector) internal view returns (Resource resourceType) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return Resource(uint8(bytes1(_blob))); + } + + /** Get resourceType */ + function _getResourceType(bytes32 resourceSelector) internal view returns (Resource resourceType) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return Resource(uint8(bytes1(_blob))); + } + + /** Get resourceType (using the specified store) */ + function getResourceType(IStore _store, bytes32 resourceSelector) internal view returns (Resource resourceType) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return Resource(uint8(bytes1(_blob))); + } + /** Get resourceType */ function get(bytes32 resourceSelector) internal view returns (Resource resourceType) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -104,6 +131,30 @@ library ResourceType { return Resource(uint8(bytes1(_blob))); } + /** Set resourceType */ + function setResourceType(bytes32 resourceSelector, Resource resourceType) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType)), _fieldLayout); + } + + /** Set resourceType */ + function _setResourceType(bytes32 resourceSelector, Resource resourceType) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType)), _fieldLayout); + } + + /** Set resourceType (using the specified store) */ + function setResourceType(IStore _store, bytes32 resourceSelector, Resource resourceType) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(resourceType)), _fieldLayout); + } + /** Set resourceType */ function set(bytes32 resourceSelector, Resource resourceType) internal { bytes32[] memory _keyTuple = new bytes32[](1); diff --git a/packages/world/src/modules/core/tables/SystemHooks.sol b/packages/world/src/modules/core/tables/SystemHooks.sol index 57bf414ebd..8e7409166f 100644 --- a/packages/world/src/modules/core/tables/SystemHooks.sol +++ b/packages/world/src/modules/core/tables/SystemHooks.sol @@ -74,6 +74,33 @@ library SystemHooks { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue(bytes32 resourceSelector) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** Get value */ + function _getValue(bytes32 resourceSelector) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, bytes32 resourceSelector) internal view returns (bytes21[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); + } + /** Get value */ function get(bytes32 resourceSelector) internal view returns (bytes21[] memory value) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -101,6 +128,30 @@ library SystemHooks { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes21()); } + /** Set value */ + function setValue(bytes32 resourceSelector, bytes21[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(bytes32 resourceSelector, bytes21[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + StoreCore.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, bytes32 resourceSelector, bytes21[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + /** Set value */ function set(bytes32 resourceSelector, bytes21[] memory value) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -125,6 +176,39 @@ library SystemHooks { _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); } + /** Get the length of value */ + function lengthValue(bytes32 resourceSelector) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 21; + } + } + + /** Get the length of value */ + function _lengthValue(bytes32 resourceSelector) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + uint256 _byteLength = StoreCore.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 21; + } + } + + /** Get the length of value (using the specified store) */ + function lengthValue(IStore _store, bytes32 resourceSelector) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 21; + } + } + /** Get the length of value */ function length(bytes32 resourceSelector) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -158,6 +242,62 @@ library SystemHooks { } } + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(bytes32 resourceSelector, uint256 _index) internal view returns (bytes21) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + unchecked { + bytes memory _blob = StoreSwitch.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 21, + (_index + 1) * 21 + ); + return (bytes21(_blob)); + } + } + + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function _getItemValue(bytes32 resourceSelector, uint256 _index) internal view returns (bytes21) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + unchecked { + bytes memory _blob = StoreCore.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 21, + (_index + 1) * 21 + ); + return (bytes21(_blob)); + } + } + + /** + * Get an item of value (using the specified store) + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(IStore _store, bytes32 resourceSelector, uint256 _index) internal view returns (bytes21) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + unchecked { + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 21, (_index + 1) * 21); + return (bytes21(_blob)); + } + } + /** * Get an item of value * (unchecked, returns invalid data if index overflows) @@ -214,6 +354,30 @@ library SystemHooks { } } + /** Push an element to value */ + function pushValue(bytes32 resourceSelector, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value */ + function _pushValue(bytes32 resourceSelector, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + StoreCore.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value (using the specified store) */ + function pushValue(IStore _store, bytes32 resourceSelector, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + /** Push an element to value */ function push(bytes32 resourceSelector, bytes21 _element) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -238,6 +402,30 @@ library SystemHooks { _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); } + /** Pop an element from value */ + function popValue(bytes32 resourceSelector) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); + } + + /** Pop an element from value */ + function _popValue(bytes32 resourceSelector) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + StoreCore.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); + } + + /** Pop an element from value (using the specified store) */ + function popValue(IStore _store, bytes32 resourceSelector) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + _store.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); + } + /** Pop an element from value */ function pop(bytes32 resourceSelector) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -262,6 +450,45 @@ library SystemHooks { _store.popFromField(_tableId, _keyTuple, 0, 21, _fieldLayout); } + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function updateValue(bytes32 resourceSelector, uint256 _index, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + unchecked { + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function _updateValue(bytes32 resourceSelector, uint256 _index, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + unchecked { + StoreCore.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * 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 updateValue(IStore _store, bytes32 resourceSelector, uint256 _index, bytes21 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = resourceSelector; + + unchecked { + _store.updateInField(_tableId, _keyTuple, 0, _index * 21, abi.encodePacked((_element)), _fieldLayout); + } + } + /** * Update an element of value at `_index` * (checked only to prevent modifying other tables; can corrupt own data if index overflows) diff --git a/packages/world/src/modules/core/tables/SystemRegistry.sol b/packages/world/src/modules/core/tables/SystemRegistry.sol index 71174911aa..81a877f73d 100644 --- a/packages/world/src/modules/core/tables/SystemRegistry.sol +++ b/packages/world/src/modules/core/tables/SystemRegistry.sol @@ -74,6 +74,33 @@ library SystemRegistry { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get resourceSelector */ + function getResourceSelector(address system) internal view returns (bytes32 resourceSelector) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(system))); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** Get resourceSelector */ + function _getResourceSelector(address system) internal view returns (bytes32 resourceSelector) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(system))); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** Get resourceSelector (using the specified store) */ + function getResourceSelector(IStore _store, address system) internal view returns (bytes32 resourceSelector) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(system))); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + /** Get resourceSelector */ function get(address system) internal view returns (bytes32 resourceSelector) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -101,6 +128,30 @@ library SystemRegistry { return (bytes32(_blob)); } + /** Set resourceSelector */ + function setResourceSelector(address system, bytes32 resourceSelector) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(system))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), _fieldLayout); + } + + /** Set resourceSelector */ + function _setResourceSelector(address system, bytes32 resourceSelector) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(system))); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), _fieldLayout); + } + + /** Set resourceSelector (using the specified store) */ + function setResourceSelector(IStore _store, address system, bytes32 resourceSelector) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(system))); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((resourceSelector)), _fieldLayout); + } + /** Set resourceSelector */ function set(address system, bytes32 resourceSelector) internal { bytes32[] memory _keyTuple = new bytes32[](1); diff --git a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol index a49c3cc511..3024469cc6 100644 --- a/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol +++ b/packages/world/src/modules/keyswithvalue/tables/KeysWithValue.sol @@ -71,6 +71,43 @@ library KeysWithValue { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get keysWithValue */ + function getKeysWithValue( + bytes32 _tableId, + bytes32 valueHash + ) internal view returns (bytes32[] memory keysWithValue) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** Get keysWithValue */ + function _getKeysWithValue( + bytes32 _tableId, + bytes32 valueHash + ) internal view returns (bytes32[] memory keysWithValue) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** Get keysWithValue (using the specified store) */ + function getKeysWithValue( + IStore _store, + bytes32 _tableId, + bytes32 valueHash + ) internal view returns (bytes32[] memory keysWithValue) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + /** Get keysWithValue */ function get(bytes32 _tableId, bytes32 valueHash) internal view returns (bytes32[] memory keysWithValue) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -102,6 +139,35 @@ library KeysWithValue { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); } + /** Set keysWithValue */ + function setKeysWithValue(bytes32 _tableId, bytes32 valueHash, bytes32[] memory keysWithValue) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), _fieldLayout); + } + + /** Set keysWithValue */ + function _setKeysWithValue(bytes32 _tableId, bytes32 valueHash, bytes32[] memory keysWithValue) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + StoreCore.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), _fieldLayout); + } + + /** Set keysWithValue (using the specified store) */ + function setKeysWithValue( + IStore _store, + bytes32 _tableId, + bytes32 valueHash, + bytes32[] memory keysWithValue + ) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), _fieldLayout); + } + /** Set keysWithValue */ function set(bytes32 _tableId, bytes32 valueHash, bytes32[] memory keysWithValue) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -126,6 +192,39 @@ library KeysWithValue { _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((keysWithValue)), _fieldLayout); } + /** Get the length of keysWithValue */ + function lengthKeysWithValue(bytes32 _tableId, bytes32 valueHash) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 32; + } + } + + /** Get the length of keysWithValue */ + function _lengthKeysWithValue(bytes32 _tableId, bytes32 valueHash) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + uint256 _byteLength = StoreCore.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 32; + } + } + + /** Get the length of keysWithValue (using the specified store) */ + function lengthKeysWithValue(IStore _store, bytes32 _tableId, bytes32 valueHash) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 32; + } + } + /** Get the length of keysWithValue */ function length(bytes32 _tableId, bytes32 valueHash) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -159,6 +258,67 @@ library KeysWithValue { } } + /** + * Get an item of keysWithValue + * (unchecked, returns invalid data if index overflows) + */ + function getItemKeysWithValue(bytes32 _tableId, bytes32 valueHash, uint256 _index) internal view returns (bytes32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + unchecked { + bytes memory _blob = StoreSwitch.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 32, + (_index + 1) * 32 + ); + return (bytes32(_blob)); + } + } + + /** + * Get an item of keysWithValue + * (unchecked, returns invalid data if index overflows) + */ + function _getItemKeysWithValue(bytes32 _tableId, bytes32 valueHash, uint256 _index) internal view returns (bytes32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + unchecked { + bytes memory _blob = StoreCore.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 32, + (_index + 1) * 32 + ); + return (bytes32(_blob)); + } + } + + /** + * Get an item of keysWithValue (using the specified store) + * (unchecked, returns invalid data if index overflows) + */ + function getItemKeysWithValue( + IStore _store, + bytes32 _tableId, + bytes32 valueHash, + uint256 _index + ) internal view returns (bytes32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + unchecked { + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 32, (_index + 1) * 32); + return (bytes32(_blob)); + } + } + /** * Get an item of keysWithValue * (unchecked, returns invalid data if index overflows) @@ -215,6 +375,30 @@ library KeysWithValue { } } + /** Push an element to keysWithValue */ + function pushKeysWithValue(bytes32 _tableId, bytes32 valueHash, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to keysWithValue */ + function _pushKeysWithValue(bytes32 _tableId, bytes32 valueHash, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + StoreCore.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to keysWithValue (using the specified store) */ + function pushKeysWithValue(IStore _store, bytes32 _tableId, bytes32 valueHash, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + /** Push an element to keysWithValue */ function push(bytes32 _tableId, bytes32 valueHash, bytes32 _element) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -239,6 +423,30 @@ library KeysWithValue { _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); } + /** Pop an element from keysWithValue */ + function popKeysWithValue(bytes32 _tableId, bytes32 valueHash) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 32, _fieldLayout); + } + + /** Pop an element from keysWithValue */ + function _popKeysWithValue(bytes32 _tableId, bytes32 valueHash) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + StoreCore.popFromField(_tableId, _keyTuple, 0, 32, _fieldLayout); + } + + /** Pop an element from keysWithValue (using the specified store) */ + function popKeysWithValue(IStore _store, bytes32 _tableId, bytes32 valueHash) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + _store.popFromField(_tableId, _keyTuple, 0, 32, _fieldLayout); + } + /** Pop an element from keysWithValue */ function pop(bytes32 _tableId, bytes32 valueHash) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -263,6 +471,51 @@ library KeysWithValue { _store.popFromField(_tableId, _keyTuple, 0, 32, _fieldLayout); } + /** + * Update an element of keysWithValue at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function updateKeysWithValue(bytes32 _tableId, bytes32 valueHash, uint256 _index, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + unchecked { + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * Update an element of keysWithValue at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function _updateKeysWithValue(bytes32 _tableId, bytes32 valueHash, uint256 _index, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + unchecked { + StoreCore.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * Update an element of keysWithValue (using the specified store) at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function updateKeysWithValue( + IStore _store, + bytes32 _tableId, + bytes32 valueHash, + uint256 _index, + bytes32 _element + ) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = valueHash; + + unchecked { + _store.updateInField(_tableId, _keyTuple, 0, _index * 32, abi.encodePacked((_element)), _fieldLayout); + } + } + /** * Update an element of keysWithValue at `_index` * (checked only to prevent modifying other tables; can corrupt own data if index overflows) diff --git a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol index e0dae09e55..679c67d270 100644 --- a/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol +++ b/packages/world/src/modules/std-delegations/tables/CallboundDelegations.sol @@ -80,6 +80,58 @@ library CallboundDelegations { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get availableCalls */ + function getAvailableCalls( + address delegator, + address delegatee, + bytes32 resourceSelector, + bytes32 callDataHash + ) internal view returns (uint256 availableCalls) { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + _keyTuple[2] = resourceSelector; + _keyTuple[3] = callDataHash; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** Get availableCalls */ + function _getAvailableCalls( + address delegator, + address delegatee, + bytes32 resourceSelector, + bytes32 callDataHash + ) internal view returns (uint256 availableCalls) { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + _keyTuple[2] = resourceSelector; + _keyTuple[3] = callDataHash; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** Get availableCalls (using the specified store) */ + function getAvailableCalls( + IStore _store, + address delegator, + address delegatee, + bytes32 resourceSelector, + bytes32 callDataHash + ) internal view returns (uint256 availableCalls) { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + _keyTuple[2] = resourceSelector; + _keyTuple[3] = callDataHash; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + /** Get availableCalls */ function get( address delegator, @@ -132,6 +184,58 @@ library CallboundDelegations { return (uint256(bytes32(_blob))); } + /** Set availableCalls */ + function setAvailableCalls( + address delegator, + address delegatee, + bytes32 resourceSelector, + bytes32 callDataHash, + uint256 availableCalls + ) internal { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + _keyTuple[2] = resourceSelector; + _keyTuple[3] = callDataHash; + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); + } + + /** Set availableCalls */ + function _setAvailableCalls( + address delegator, + address delegatee, + bytes32 resourceSelector, + bytes32 callDataHash, + uint256 availableCalls + ) internal { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + _keyTuple[2] = resourceSelector; + _keyTuple[3] = callDataHash; + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); + } + + /** Set availableCalls (using the specified store) */ + function setAvailableCalls( + IStore _store, + address delegator, + address delegatee, + bytes32 resourceSelector, + bytes32 callDataHash, + uint256 availableCalls + ) internal { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + _keyTuple[2] = resourceSelector; + _keyTuple[3] = callDataHash; + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((availableCalls)), _fieldLayout); + } + /** Set availableCalls */ function set( address delegator, diff --git a/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol b/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol index 17cbd3702b..34e0f8ae48 100644 --- a/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol +++ b/packages/world/src/modules/std-delegations/tables/TimeboundDelegations.sol @@ -76,6 +76,40 @@ library TimeboundDelegations { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get maxTimestamp */ + function getMaxTimestamp(address delegator, address delegatee) internal view returns (uint256 maxTimestamp) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** Get maxTimestamp */ + function _getMaxTimestamp(address delegator, address delegatee) internal view returns (uint256 maxTimestamp) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** Get maxTimestamp (using the specified store) */ + function getMaxTimestamp( + IStore _store, + address delegator, + address delegatee + ) internal view returns (uint256 maxTimestamp) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + /** Get maxTimestamp */ function get(address delegator, address delegatee) internal view returns (uint256 maxTimestamp) { bytes32[] memory _keyTuple = new bytes32[](2); @@ -106,6 +140,33 @@ library TimeboundDelegations { return (uint256(bytes32(_blob))); } + /** Set maxTimestamp */ + function setMaxTimestamp(address delegator, address delegatee, uint256 maxTimestamp) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout); + } + + /** Set maxTimestamp */ + function _setMaxTimestamp(address delegator, address delegatee, uint256 maxTimestamp) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout); + } + + /** Set maxTimestamp (using the specified store) */ + function setMaxTimestamp(IStore _store, address delegator, address delegatee, uint256 maxTimestamp) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((maxTimestamp)), _fieldLayout); + } + /** Set maxTimestamp */ function set(address delegator, address delegatee, uint256 maxTimestamp) internal { bytes32[] memory _keyTuple = new bytes32[](2); diff --git a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol index 240d9abe37..4c9032669d 100644 --- a/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol +++ b/packages/world/src/modules/uniqueentity/tables/UniqueEntity.sol @@ -69,6 +69,30 @@ library UniqueEntity { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue(bytes32 _tableId) internal view returns (uint256 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** Get value */ + function _getValue(bytes32 _tableId) internal view returns (uint256 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, bytes32 _tableId) internal view returns (uint256 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + /** Get value */ function get(bytes32 _tableId) internal view returns (uint256 value) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -93,6 +117,27 @@ library UniqueEntity { return (uint256(bytes32(_blob))); } + /** Set value */ + function setValue(bytes32 _tableId, uint256 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(bytes32 _tableId, uint256 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, bytes32 _tableId, uint256 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + /** Set value */ function set(bytes32 _tableId, uint256 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); diff --git a/packages/world/src/tables/Delegations.sol b/packages/world/src/tables/Delegations.sol index 5b592ab79e..91e5be6c27 100644 --- a/packages/world/src/tables/Delegations.sol +++ b/packages/world/src/tables/Delegations.sol @@ -76,6 +76,46 @@ library Delegations { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get delegationControlId */ + function getDelegationControlId( + address delegator, + address delegatee + ) internal view returns (bytes32 delegationControlId) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** Get delegationControlId */ + function _getDelegationControlId( + address delegator, + address delegatee + ) internal view returns (bytes32 delegationControlId) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** Get delegationControlId (using the specified store) */ + function getDelegationControlId( + IStore _store, + address delegator, + address delegatee + ) internal view returns (bytes32 delegationControlId) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + /** Get delegationControlId */ function get(address delegator, address delegatee) internal view returns (bytes32 delegationControlId) { bytes32[] memory _keyTuple = new bytes32[](2); @@ -110,6 +150,38 @@ library Delegations { return (bytes32(_blob)); } + /** Set delegationControlId */ + function setDelegationControlId(address delegator, address delegatee, bytes32 delegationControlId) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((delegationControlId)), _fieldLayout); + } + + /** Set delegationControlId */ + function _setDelegationControlId(address delegator, address delegatee, bytes32 delegationControlId) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((delegationControlId)), _fieldLayout); + } + + /** Set delegationControlId (using the specified store) */ + function setDelegationControlId( + IStore _store, + address delegator, + address delegatee, + bytes32 delegationControlId + ) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(uint256(uint160(delegator))); + _keyTuple[1] = bytes32(uint256(uint160(delegatee))); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((delegationControlId)), _fieldLayout); + } + /** Set delegationControlId */ function set(address delegator, address delegatee, bytes32 delegationControlId) internal { bytes32[] memory _keyTuple = new bytes32[](2); diff --git a/packages/world/src/tables/InstalledModules.sol b/packages/world/src/tables/InstalledModules.sol index 541f7bc36c..7d87929aec 100644 --- a/packages/world/src/tables/InstalledModules.sol +++ b/packages/world/src/tables/InstalledModules.sol @@ -76,6 +76,40 @@ library InstalledModules { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get moduleAddress */ + function getModuleAddress(bytes16 moduleName, bytes32 argumentsHash) internal view returns (address moduleAddress) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(moduleName); + _keyTuple[1] = argumentsHash; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); + } + + /** Get moduleAddress */ + function _getModuleAddress(bytes16 moduleName, bytes32 argumentsHash) internal view returns (address moduleAddress) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(moduleName); + _keyTuple[1] = argumentsHash; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); + } + + /** Get moduleAddress (using the specified store) */ + function getModuleAddress( + IStore _store, + bytes16 moduleName, + bytes32 argumentsHash + ) internal view returns (address moduleAddress) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(moduleName); + _keyTuple[1] = argumentsHash; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); + } + /** Get moduleAddress */ function get(bytes16 moduleName, bytes32 argumentsHash) internal view returns (address moduleAddress) { bytes32[] memory _keyTuple = new bytes32[](2); @@ -106,6 +140,33 @@ library InstalledModules { return (address(bytes20(_blob))); } + /** Set moduleAddress */ + function setModuleAddress(bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(moduleName); + _keyTuple[1] = argumentsHash; + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), _fieldLayout); + } + + /** Set moduleAddress */ + function _setModuleAddress(bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(moduleName); + _keyTuple[1] = argumentsHash; + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), _fieldLayout); + } + + /** Set moduleAddress (using the specified store) */ + function setModuleAddress(IStore _store, bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = bytes32(moduleName); + _keyTuple[1] = argumentsHash; + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((moduleAddress)), _fieldLayout); + } + /** Set moduleAddress */ function set(bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal { bytes32[] memory _keyTuple = new bytes32[](2); diff --git a/packages/world/src/tables/NamespaceOwner.sol b/packages/world/src/tables/NamespaceOwner.sol index 4c5977fb41..f16a4f1b0c 100644 --- a/packages/world/src/tables/NamespaceOwner.sol +++ b/packages/world/src/tables/NamespaceOwner.sol @@ -74,6 +74,33 @@ library NamespaceOwner { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get owner */ + function getOwner(bytes16 namespace) internal view returns (address owner) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); + } + + /** Get owner */ + function _getOwner(bytes16 namespace) internal view returns (address owner) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); + } + + /** Get owner (using the specified store) */ + function getOwner(IStore _store, bytes16 namespace) internal view returns (address owner) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (address(bytes20(_blob))); + } + /** Get owner */ function get(bytes16 namespace) internal view returns (address owner) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -101,6 +128,30 @@ library NamespaceOwner { return (address(bytes20(_blob))); } + /** Set owner */ + function setOwner(bytes16 namespace, address owner) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout); + } + + /** Set owner */ + function _setOwner(bytes16 namespace, address owner) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout); + } + + /** Set owner (using the specified store) */ + function setOwner(IStore _store, bytes16 namespace, address owner) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(namespace); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout); + } + /** Set owner */ function set(bytes16 namespace, address owner) internal { bytes32[] memory _keyTuple = new bytes32[](1); diff --git a/packages/world/src/tables/ResourceAccess.sol b/packages/world/src/tables/ResourceAccess.sol index 553447e59f..8745ef7353 100644 --- a/packages/world/src/tables/ResourceAccess.sol +++ b/packages/world/src/tables/ResourceAccess.sol @@ -76,6 +76,36 @@ library ResourceAccess { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get access */ + function getAccess(bytes32 resourceSelector, address caller) internal view returns (bool access) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = resourceSelector; + _keyTuple[1] = bytes32(uint256(uint160(caller))); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** Get access */ + function _getAccess(bytes32 resourceSelector, address caller) internal view returns (bool access) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = resourceSelector; + _keyTuple[1] = bytes32(uint256(uint160(caller))); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** Get access (using the specified store) */ + function getAccess(IStore _store, bytes32 resourceSelector, address caller) internal view returns (bool access) { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = resourceSelector; + _keyTuple[1] = bytes32(uint256(uint160(caller))); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + /** Get access */ function get(bytes32 resourceSelector, address caller) internal view returns (bool access) { bytes32[] memory _keyTuple = new bytes32[](2); @@ -106,6 +136,33 @@ library ResourceAccess { return (_toBool(uint8(bytes1(_blob)))); } + /** Set access */ + function setAccess(bytes32 resourceSelector, address caller, bool access) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = resourceSelector; + _keyTuple[1] = bytes32(uint256(uint160(caller))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((access)), _fieldLayout); + } + + /** Set access */ + function _setAccess(bytes32 resourceSelector, address caller, bool access) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = resourceSelector; + _keyTuple[1] = bytes32(uint256(uint160(caller))); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((access)), _fieldLayout); + } + + /** Set access (using the specified store) */ + function setAccess(IStore _store, bytes32 resourceSelector, address caller, bool access) internal { + bytes32[] memory _keyTuple = new bytes32[](2); + _keyTuple[0] = resourceSelector; + _keyTuple[1] = bytes32(uint256(uint160(caller))); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((access)), _fieldLayout); + } + /** Set access */ function set(bytes32 resourceSelector, address caller, bool access) internal { bytes32[] memory _keyTuple = new bytes32[](2); diff --git a/packages/world/test/tables/AddressArray.sol b/packages/world/test/tables/AddressArray.sol index b5bed3519a..f702e371e4 100644 --- a/packages/world/test/tables/AddressArray.sol +++ b/packages/world/test/tables/AddressArray.sol @@ -71,6 +71,33 @@ library AddressArray { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue(bytes32 _tableId, bytes32 key) internal view returns (address[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); + } + + /** Get value */ + function _getValue(bytes32 _tableId, bytes32 key) internal view returns (address[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, bytes32 _tableId, bytes32 key) internal view returns (address[] memory value) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); + } + /** Get value */ function get(bytes32 _tableId, bytes32 key) internal view returns (address[] memory value) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -98,6 +125,30 @@ library AddressArray { return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_address()); } + /** Set value */ + function setValue(bytes32 _tableId, bytes32 key, address[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(bytes32 _tableId, bytes32 key, address[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, bytes32 _tableId, bytes32 key, address[] memory value) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); + } + /** Set value */ function set(bytes32 _tableId, bytes32 key, address[] memory value) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -122,6 +173,39 @@ library AddressArray { _store.setField(_tableId, _keyTuple, 0, EncodeArray.encode((value)), _fieldLayout); } + /** Get the length of value */ + function lengthValue(bytes32 _tableId, bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = StoreSwitch.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 20; + } + } + + /** Get the length of value */ + function _lengthValue(bytes32 _tableId, bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = StoreCore.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 20; + } + } + + /** Get the length of value (using the specified store) */ + function lengthValue(IStore _store, bytes32 _tableId, bytes32 key) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + uint256 _byteLength = _store.getFieldLength(_tableId, _keyTuple, 0, _fieldLayout); + unchecked { + return _byteLength / 20; + } + } + /** Get the length of value */ function length(bytes32 _tableId, bytes32 key) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](1); @@ -155,6 +239,62 @@ library AddressArray { } } + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(bytes32 _tableId, bytes32 key, uint256 _index) internal view returns (address) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = StoreSwitch.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 20, + (_index + 1) * 20 + ); + return (address(bytes20(_blob))); + } + } + + /** + * Get an item of value + * (unchecked, returns invalid data if index overflows) + */ + function _getItemValue(bytes32 _tableId, bytes32 key, uint256 _index) internal view returns (address) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = StoreCore.getFieldSlice( + _tableId, + _keyTuple, + 0, + _fieldLayout, + _index * 20, + (_index + 1) * 20 + ); + return (address(bytes20(_blob))); + } + } + + /** + * Get an item of value (using the specified store) + * (unchecked, returns invalid data if index overflows) + */ + function getItemValue(IStore _store, bytes32 _tableId, bytes32 key, uint256 _index) internal view returns (address) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + bytes memory _blob = _store.getFieldSlice(_tableId, _keyTuple, 0, _fieldLayout, _index * 20, (_index + 1) * 20); + return (address(bytes20(_blob))); + } + } + /** * Get an item of value * (unchecked, returns invalid data if index overflows) @@ -211,6 +351,30 @@ library AddressArray { } } + /** Push an element to value */ + function pushValue(bytes32 _tableId, bytes32 key, address _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value */ + function _pushValue(bytes32 _tableId, bytes32 key, address _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + + /** Push an element to value (using the specified store) */ + function pushValue(IStore _store, bytes32 _tableId, bytes32 key, address _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); + } + /** Push an element to value */ function push(bytes32 _tableId, bytes32 key, address _element) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -235,6 +399,30 @@ library AddressArray { _store.pushToField(_tableId, _keyTuple, 0, abi.encodePacked((_element)), _fieldLayout); } + /** Pop an element from value */ + function popValue(bytes32 _tableId, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreSwitch.popFromField(_tableId, _keyTuple, 0, 20, _fieldLayout); + } + + /** Pop an element from value */ + function _popValue(bytes32 _tableId, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + StoreCore.popFromField(_tableId, _keyTuple, 0, 20, _fieldLayout); + } + + /** Pop an element from value (using the specified store) */ + function popValue(IStore _store, bytes32 _tableId, bytes32 key) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + _store.popFromField(_tableId, _keyTuple, 0, 20, _fieldLayout); + } + /** Pop an element from value */ function pop(bytes32 _tableId, bytes32 key) internal { bytes32[] memory _keyTuple = new bytes32[](1); @@ -259,6 +447,45 @@ library AddressArray { _store.popFromField(_tableId, _keyTuple, 0, 20, _fieldLayout); } + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function updateValue(bytes32 _tableId, bytes32 key, uint256 _index, address _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + StoreSwitch.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * Update an element of value at `_index` + * (checked only to prevent modifying other tables; can corrupt own data if index overflows) + */ + function _updateValue(bytes32 _tableId, bytes32 key, uint256 _index, address _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + StoreCore.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), _fieldLayout); + } + } + + /** + * 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 updateValue(IStore _store, bytes32 _tableId, bytes32 key, uint256 _index, address _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = key; + + unchecked { + _store.updateInField(_tableId, _keyTuple, 0, _index * 20, abi.encodePacked((_element)), _fieldLayout); + } + } + /** * Update an element of value at `_index` * (checked only to prevent modifying other tables; can corrupt own data if index overflows) diff --git a/packages/world/test/tables/Bool.sol b/packages/world/test/tables/Bool.sol index af0defcbfe..f02424ce1c 100644 --- a/packages/world/test/tables/Bool.sol +++ b/packages/world/test/tables/Bool.sol @@ -69,6 +69,30 @@ library Bool { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue(bytes32 _tableId) internal view returns (bool value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** Get value */ + function _getValue(bytes32 _tableId) internal view returns (bool value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, bytes32 _tableId) internal view returns (bool value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + /** Get value */ function get(bytes32 _tableId) internal view returns (bool value) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -93,6 +117,27 @@ library Bool { return (_toBool(uint8(bytes1(_blob)))); } + /** Set value */ + function setValue(bytes32 _tableId, bool value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(bytes32 _tableId, bool value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, bytes32 _tableId, bool value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + /** Set value */ function set(bytes32 _tableId, bool value) internal { bytes32[] memory _keyTuple = new bytes32[](0); diff --git a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol index e6ebcd912f..997749a23d 100644 --- a/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol @@ -72,6 +72,30 @@ library Counter { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue() internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value */ + function _getValue() internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + /** Get value */ function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -96,6 +120,27 @@ library Counter { return (uint32(bytes4(_blob))); } + /** Set value */ + function setValue(uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + /** Set value */ function set(uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); diff --git a/templates/react/packages/contracts/src/codegen/tables/Counter.sol b/templates/react/packages/contracts/src/codegen/tables/Counter.sol index e6ebcd912f..997749a23d 100644 --- a/templates/react/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/react/packages/contracts/src/codegen/tables/Counter.sol @@ -72,6 +72,30 @@ library Counter { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue() internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value */ + function _getValue() internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + /** Get value */ function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -96,6 +120,27 @@ library Counter { return (uint32(bytes4(_blob))); } + /** Set value */ + function setValue(uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + /** Set value */ function set(uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0); diff --git a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol index e6ebcd912f..997749a23d 100644 --- a/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +++ b/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol @@ -72,6 +72,30 @@ library Counter { _store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } + /** Get value */ + function getValue() internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value */ + function _getValue() internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store) internal view returns (uint32 value) { + bytes32[] memory _keyTuple = new bytes32[](0); + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint32(bytes4(_blob))); + } + /** Get value */ function get() internal view returns (uint32 value) { bytes32[] memory _keyTuple = new bytes32[](0); @@ -96,6 +120,27 @@ library Counter { return (uint32(bytes4(_blob))); } + /** Set value */ + function setValue(uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value */ + function _setValue(uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + StoreCore.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint32 value) internal { + bytes32[] memory _keyTuple = new bytes32[](0); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout); + } + /** Set value */ function set(uint32 value) internal { bytes32[] memory _keyTuple = new bytes32[](0);