// SPDX-License-Identifier: MIT pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct InventoryItemTransferData { uint256 toObjectId; address previousOwner; address currentOwner; uint256 quantity; uint256 updatedAt; } library InventoryItemTransfer { // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "evefrontier", name: "InventoryItemTra", typeId: RESOURCE_TABLE });` ResourceId constant _tableId = ResourceId.wrap(0x746265766566726f6e74696572000000496e76656e746f72794974656d547261); FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0088050020141420200000000000000000000000000000000000000000000000); // Hex-encoded key schema of (uint256, uint256) Schema constant _keySchema = Schema.wrap(0x004002001f1f0000000000000000000000000000000000000000000000000000); // Hex-encoded value schema of (uint256, address, address, uint256, uint256) Schema constant _valueSchema = Schema.wrap(0x008805001f61611f1f0000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. * @return keyNames An array of strings with the names of key fields. */ function getKeyNames() internal pure returns (string[] memory keyNames) { keyNames = new string[](2); keyNames[0] = "smartObjectId"; keyNames[1] = "itemObjectId"; } /** * @notice Get the table's value field names. * @return fieldNames An array of strings with the names of value fields. */ function getFieldNames() internal pure returns (string[] memory fieldNames) { fieldNames = new string[](5); fieldNames[0] = "toObjectId"; fieldNames[1] = "previousOwner"; fieldNames[2] = "currentOwner"; fieldNames[3] = "quantity"; fieldNames[4] = "updatedAt"; } /** * @notice Register the table with its config. */ function register() internal { StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Get toObjectId. */ function getToObjectId(uint256 smartObjectId, uint256 itemObjectId) internal view returns (uint256 toObjectId) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return (uint256(bytes32(_blob))); } /** * @notice Get toObjectId. */ function _getToObjectId(uint256 smartObjectId, uint256 itemObjectId) internal view returns (uint256 toObjectId) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return (uint256(bytes32(_blob))); } /** * @notice Set toObjectId. */ function setToObjectId(uint256 smartObjectId, uint256 itemObjectId, uint256 toObjectId) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((toObjectId)), _fieldLayout); } /** * @notice Set toObjectId. */ function _setToObjectId(uint256 smartObjectId, uint256 itemObjectId, uint256 toObjectId) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((toObjectId)), _fieldLayout); } /** * @notice Get previousOwner. */ function getPreviousOwner(uint256 smartObjectId, uint256 itemObjectId) internal view returns (address previousOwner) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); return (address(bytes20(_blob))); } /** * @notice Get previousOwner. */ function _getPreviousOwner( uint256 smartObjectId, uint256 itemObjectId ) internal view returns (address previousOwner) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); return (address(bytes20(_blob))); } /** * @notice Set previousOwner. */ function setPreviousOwner(uint256 smartObjectId, uint256 itemObjectId, address previousOwner) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((previousOwner)), _fieldLayout); } /** * @notice Set previousOwner. */ function _setPreviousOwner(uint256 smartObjectId, uint256 itemObjectId, address previousOwner) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((previousOwner)), _fieldLayout); } /** * @notice Get currentOwner. */ function getCurrentOwner(uint256 smartObjectId, uint256 itemObjectId) internal view returns (address currentOwner) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); return (address(bytes20(_blob))); } /** * @notice Get currentOwner. */ function _getCurrentOwner(uint256 smartObjectId, uint256 itemObjectId) internal view returns (address currentOwner) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); return (address(bytes20(_blob))); } /** * @notice Set currentOwner. */ function setCurrentOwner(uint256 smartObjectId, uint256 itemObjectId, address currentOwner) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreSwitch.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((currentOwner)), _fieldLayout); } /** * @notice Set currentOwner. */ function _setCurrentOwner(uint256 smartObjectId, uint256 itemObjectId, address currentOwner) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((currentOwner)), _fieldLayout); } /** * @notice Get quantity. */ function getQuantity(uint256 smartObjectId, uint256 itemObjectId) internal view returns (uint256 quantity) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); return (uint256(bytes32(_blob))); } /** * @notice Get quantity. */ function _getQuantity(uint256 smartObjectId, uint256 itemObjectId) internal view returns (uint256 quantity) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); return (uint256(bytes32(_blob))); } /** * @notice Set quantity. */ function setQuantity(uint256 smartObjectId, uint256 itemObjectId, uint256 quantity) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreSwitch.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((quantity)), _fieldLayout); } /** * @notice Set quantity. */ function _setQuantity(uint256 smartObjectId, uint256 itemObjectId, uint256 quantity) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreCore.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((quantity)), _fieldLayout); } /** * @notice Get updatedAt. */ function getUpdatedAt(uint256 smartObjectId, uint256 itemObjectId) internal view returns (uint256 updatedAt) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); return (uint256(bytes32(_blob))); } /** * @notice Get updatedAt. */ function _getUpdatedAt(uint256 smartObjectId, uint256 itemObjectId) internal view returns (uint256 updatedAt) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); return (uint256(bytes32(_blob))); } /** * @notice Set updatedAt. */ function setUpdatedAt(uint256 smartObjectId, uint256 itemObjectId, uint256 updatedAt) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreSwitch.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((updatedAt)), _fieldLayout); } /** * @notice Set updatedAt. */ function _setUpdatedAt(uint256 smartObjectId, uint256 itemObjectId, uint256 updatedAt) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreCore.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((updatedAt)), _fieldLayout); } /** * @notice Get the full data. */ function get( uint256 smartObjectId, uint256 itemObjectId ) internal view returns (InventoryItemTransferData memory _table) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout ); return decode(_staticData, _encodedLengths, _dynamicData); } /** * @notice Get the full data. */ function _get( uint256 smartObjectId, uint256 itemObjectId ) internal view returns (InventoryItemTransferData memory _table) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout ); return decode(_staticData, _encodedLengths, _dynamicData); } /** * @notice Set the full data using individual values. */ function set( uint256 smartObjectId, uint256 itemObjectId, uint256 toObjectId, address previousOwner, address currentOwner, uint256 quantity, uint256 updatedAt ) internal { bytes memory _staticData = encodeStatic(toObjectId, previousOwner, currentOwner, quantity, updatedAt); EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); } /** * @notice Set the full data using individual values. */ function _set( uint256 smartObjectId, uint256 itemObjectId, uint256 toObjectId, address previousOwner, address currentOwner, uint256 quantity, uint256 updatedAt ) internal { bytes memory _staticData = encodeStatic(toObjectId, previousOwner, currentOwner, quantity, updatedAt); EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** * @notice Set the full data using the data struct. */ function set(uint256 smartObjectId, uint256 itemObjectId, InventoryItemTransferData memory _table) internal { bytes memory _staticData = encodeStatic( _table.toObjectId, _table.previousOwner, _table.currentOwner, _table.quantity, _table.updatedAt ); EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); } /** * @notice Set the full data using the data struct. */ function _set(uint256 smartObjectId, uint256 itemObjectId, InventoryItemTransferData memory _table) internal { bytes memory _staticData = encodeStatic( _table.toObjectId, _table.previousOwner, _table.currentOwner, _table.quantity, _table.updatedAt ); EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ function decodeStatic( bytes memory _blob ) internal pure returns (uint256 toObjectId, address previousOwner, address currentOwner, uint256 quantity, uint256 updatedAt) { toObjectId = (uint256(Bytes.getBytes32(_blob, 0))); previousOwner = (address(Bytes.getBytes20(_blob, 32))); currentOwner = (address(Bytes.getBytes20(_blob, 52))); quantity = (uint256(Bytes.getBytes32(_blob, 72))); updatedAt = (uint256(Bytes.getBytes32(_blob, 104))); } /** * @notice Decode the tightly packed blobs using this table's field layout. * @param _staticData Tightly packed static fields. * * */ function decode( bytes memory _staticData, EncodedLengths, bytes memory ) internal pure returns (InventoryItemTransferData memory _table) { (_table.toObjectId, _table.previousOwner, _table.currentOwner, _table.quantity, _table.updatedAt) = decodeStatic( _staticData ); } /** * @notice Delete all data for given keys. */ function deleteRecord(uint256 smartObjectId, uint256 itemObjectId) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreSwitch.deleteRecord(_tableId, _keyTuple); } /** * @notice Delete all data for given keys. */ function _deleteRecord(uint256 smartObjectId, uint256 itemObjectId) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. */ function encodeStatic( uint256 toObjectId, address previousOwner, address currentOwner, uint256 quantity, uint256 updatedAt ) internal pure returns (bytes memory) { return abi.encodePacked(toObjectId, previousOwner, currentOwner, quantity, updatedAt); } /** * @notice Encode all of a record's fields. * @return The static (fixed length) data, encoded into a sequence of bytes. * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ function encode( uint256 toObjectId, address previousOwner, address currentOwner, uint256 quantity, uint256 updatedAt ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(toObjectId, previousOwner, currentOwner, quantity, updatedAt); EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); } /** * @notice Encode keys as a bytes32 array using this table's field layout. */ function encodeKeyTuple(uint256 smartObjectId, uint256 itemObjectId) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(smartObjectId)); _keyTuple[1] = bytes32(uint256(itemObjectId)); return _keyTuple; } }