StoreCore
Git Source (opens in a new tab)
This library includes implementations for all IStore methods and events related to the store actions.
Functions
initialize
Initialize the store address in StoreSwitch.
Consumers must call this function in their constructor. StoreSwitch uses the storeAddress to decide where to write data to. If StoreSwitch is called in the context of a Store contract (storeAddress == address(this)), StoreSwitch uses internal methods to write data instead of external calls.
function initialize() internal;
registerInternalTables
Register Store protocol's internal tables in the store.
Consumers must call this function in their constructor before setting any table data to allow indexers to decode table events.
function registerInternalTables() internal;
getFieldLayout
SCHEMA
Get the field layout for the given table ID.
function getFieldLayout(ResourceId tableId) internal view returns (FieldLayout);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table for which to get the field layout. |
Returns
Name | Type | Description |
---|---|---|
<none> | FieldLayout | The field layout for the given table ID. |
getKeySchema
Get the key schema for the given table ID.
Reverts if the table ID is not registered.
function getKeySchema(ResourceId tableId) internal view returns (Schema keySchema);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table for which to get the key schema. |
Returns
Name | Type | Description |
---|---|---|
keySchema | Schema | The key schema for the given table ID. |
getValueSchema
Get the value schema for the given table ID.
Reverts if the table ID is not registered.
function getValueSchema(ResourceId tableId) internal view returns (Schema valueSchema);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table for which to get the value schema. |
Returns
Name | Type | Description |
---|---|---|
valueSchema | Schema | The value schema for the given table ID. |
registerTable
Register a new table with the given configuration.
*This method reverts if
- The table ID is not of type RESOURCE_TABLE or RESOURCE_OFFCHAIN_TABLE.
- The field layout is invalid.
- The key schema is invalid.
- The value schema is invalid.
- The number of key names does not match the number of key schema types.
- The number of field names does not match the number of field layout fields.*
function registerTable(
ResourceId tableId,
FieldLayout fieldLayout,
Schema keySchema,
Schema valueSchema,
string[] memory keyNames,
string[] memory fieldNames
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to register. |
fieldLayout | FieldLayout | The field layout of the table. |
keySchema | Schema | The key schema of the table. |
valueSchema | Schema | The value schema of the table. |
keyNames | string[] | The names of the keys in the table. |
fieldNames | string[] | The names of the fields in the table. |
registerStoreHook
REGISTER HOOKS
Register hooks to be called when a record or field is set or deleted.
This method reverts for all resource IDs other than tables. Hooks are not supported for offchain tables.
function registerStoreHook(ResourceId tableId, IStoreHook hookAddress, uint8 enabledHooksBitmap) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to register the hook for. |
hookAddress | IStoreHook | The address of the hook contract to register. |
enabledHooksBitmap | uint8 | The bitmap of enabled hooks. |
unregisterStoreHook
Unregister a hook from the given table ID.
function unregisterStoreHook(ResourceId tableId, IStoreHook hookAddress) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to unregister the hook from. |
hookAddress | IStoreHook | The address of the hook to unregister. |
setRecord
Set a full record for the given table ID and key tuple.
Calling this method emits a Store_SetRecord event. This method internally calls another overload of setRecord by fetching the field layout for the given table ID. If the field layout is available to the caller, it is recommended to use the other overload to avoid an additional storage read.
function setRecord(
ResourceId tableId,
bytes32[] memory keyTuple,
bytes memory staticData,
PackedCounter encodedLengths,
bytes memory dynamicData
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to set the record for. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
staticData | bytes | The static data of the record. |
encodedLengths | PackedCounter | The encoded lengths of the dynamic data of the record. |
dynamicData | bytes | The dynamic data of the record. |
setRecord
Set a full data record for the given table ID, key tuple, and field layout.
For onchain tables, the method emits a Store_SetRecord
event, updates the data in storage,
calls onBeforeSetRecord
hooks before actually modifying the state, and calls onAfterSetRecord
hooks after modifying the state. For offchain tables, the method returns early after emitting the
event without calling hooks or modifying the state.
function setRecord(
ResourceId tableId,
bytes32[] memory keyTuple,
bytes memory staticData,
PackedCounter encodedLengths,
bytes memory dynamicData,
FieldLayout fieldLayout
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to set the record for. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
staticData | bytes | The static data of the record. |
encodedLengths | PackedCounter | The encoded lengths of the dynamic data of the record. |
dynamicData | bytes | The dynamic data of the record. |
fieldLayout | FieldLayout | The field layout for the record. |
spliceStaticData
Splice the static data for the given table ID and key tuple.
This method emits a Store_SpliceStaticData
event, updates the data in storage, and calls
onBeforeSpliceStaticData
and onAfterSpliceStaticData
hooks.
For offchain tables, it returns early after emitting the event.
function spliceStaticData(ResourceId tableId, bytes32[] memory keyTuple, uint48 start, bytes memory data) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to splice the static data for. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
start | uint48 | The start position in bytes for the splice operation. |
data | bytes | The data to write to the static data of the record at the start byte. |
spliceDynamicData
Splice the dynamic data for the given table ID, key tuple, and dynamic field index.
This method emits a Store_SpliceDynamicData
event, updates the data in storage, and calls
onBeforeSpliceDynamicData
and onAfterSpliceDynamicData
hooks.
For offchain tables, it returns early after emitting the event.
function spliceDynamicData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
bytes memory data
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to splice the dynamic data for. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to splice. (Dynamic field index = field index - number of static fields) |
startWithinField | uint40 | The start position within the field for the splice operation. |
deleteCount | uint40 | The number of bytes to delete in the splice operation. |
data | bytes | The data to insert into the dynamic data of the record at the start byte. |
setField
Set data for a field at the given index in a table with the given tableId, key tuple, and value field layout.
This method internally calls another overload of setField by fetching the field layout for the given table ID.
If the field layout is available to the caller, it is recommended to use the other overload to avoid an additional storage read.
This function emits a Store_SpliceStaticData
or Store_SpliceDynamicData
event and calls the corresponding hooks.
For offchain tables, it returns early after emitting the event.
function setField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, bytes memory data) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to set the field for. |
keyTuple | bytes32[] | An array representing the key for the record. |
fieldIndex | uint8 | The index of the field to set. |
data | bytes | The data to set for the field. |
setField
Set data for a field at the given index in a table with the given tableId, key tuple, and value field layout.
This method internally calls to setStaticField
or setDynamicField
based on the field index and layout.
Calling setStaticField
or setDynamicField
directly is recommended if the caller is aware of the field layout.
This function emits a Store_SpliceStaticData
or Store_SpliceDynamicData
event, updates the data in storage,
and calls the corresponding hooks.
For offchain tables, it returns early after emitting the event.
function setField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
bytes memory data,
FieldLayout fieldLayout
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to set the field for. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
fieldIndex | uint8 | The index of the field to set. |
data | bytes | The data to set for the field. |
fieldLayout | FieldLayout | The field layout for the record. |
setStaticField
Set a static field for the given table ID, key tuple, field index, and field layout.
This method emits a Store_SpliceStaticData
event, updates the data in storage and calls the
onBeforeSpliceStaticData
and onAfterSpliceStaticData
hooks.
For offchain tables, it returns early after emitting the event.
function setStaticField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
bytes memory data,
FieldLayout fieldLayout
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to set the static field for. |
keyTuple | bytes32[] | An array representing the key for the record. |
fieldIndex | uint8 | The index of the field to set. |
data | bytes | The data to set for the static field. |
fieldLayout | FieldLayout | The field layout for the record. |
setDynamicField
Set a dynamic field for the given table ID, key tuple, and dynamic field index.
This method emits a Store_SpliceDynamicData
event, updates the data in storage and calls the
onBeforeSpliceDynamicaData
and onAfterSpliceDynamicData
hooks.
For offchain tables, it returns early after emitting the event.
function setDynamicField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
bytes memory data
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to set the dynamic field for. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to set. (Dynamic field index = field index - number of static fields). |
data | bytes | The data to set for the dynamic field. |
deleteRecord
Delete a record for the given table ID and key tuple.
This method internally calls another overload of deleteRecord by fetching the field layout for the given table ID.
This method deletes static data and sets the dynamic data length to 0, but does not
actually modify the dynamic data. It emits a Store_DeleteRecord
event and emits the
onBeforeDeleteRecord
and onAfterDeleteRecord
hooks.
For offchain tables, it returns early after emitting the event.
function deleteRecord(ResourceId tableId, bytes32[] memory keyTuple) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to delete the record from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
deleteRecord
Delete a record for the given table ID and key tuple.
This method deletes static data and sets the dynamic data length to 0, but does not
actually modify the dynamic data. It emits a Store_DeleteRecord
event and emits the
onBeforeDeleteRecord
and onAfterDeleteRecord
hooks.
For offchain tables, it returns early after emitting the event.
function deleteRecord(ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to delete the record from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
fieldLayout | FieldLayout | The field layout for the record. |
pushToDynamicField
Push data to a field at the dynamic field index in a table with the given table ID and key tuple.
This method emits a Store_SpliceDynamicData
event, updates the data in storage and calls the
onBeforeSpliceDynamicData
and onAfterSpliceDynamicData
hooks.
For offchain tables, it returns early after emitting the event.
function pushToDynamicField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
bytes memory dataToPush
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to push data to the dynamic field. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to push data to. |
dataToPush | bytes | The data to push to the dynamic field. |
popFromDynamicField
Pop data from a field at the dynamic field index in a table with the given table ID and key tuple.
This method emits a Store_SpliceDynamicData
event, updates the data in storage and calls the
onBeforeSpliceDynamicData
and onAfterSpliceDynamicData
hooks.
For offchain tables, it returns early after emitting the event.
function popFromDynamicField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint256 byteLengthToPop
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to pop data from the dynamic field. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to pop data from. |
byteLengthToPop | uint256 | The byte length to pop from the dynamic field. |
getRecord
Get the full record (all fields, static and dynamic data) for the given table ID and key tuple.
This function internally calls another overload of getRecord
, loading the field layout from storage.
If the field layout is available to the caller, it is recommended to use the other overload to avoid an additional storage read.
function getRecord(
ResourceId tableId,
bytes32[] memory keyTuple
) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the record from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
Returns
Name | Type | Description |
---|---|---|
staticData | bytes | The static data of the record. |
encodedLengths | PackedCounter | The encoded lengths of the dynamic data of the record. |
dynamicData | bytes | The dynamic data of the record. |
getRecord
Get the full record (all fields, static and dynamic data) for the given table ID and key tuple, with the given field layout.
function getRecord(
ResourceId tableId,
bytes32[] memory keyTuple,
FieldLayout fieldLayout
) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the record from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
fieldLayout | FieldLayout | The field layout for the record. |
Returns
Name | Type | Description |
---|---|---|
staticData | bytes | The static data of the record. |
encodedLengths | PackedCounter | The encoded lengths of the dynamic data of the record. |
dynamicData | bytes | The dynamic data of the record. |
getField
Get a single field from the given table ID and key tuple.
This function internally calls another overload of getField
, loading the field layout from storage.
function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the field from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
fieldIndex | uint8 | The index of the field to get. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | The data of the field. |
getField
Get a single field from the given table ID and key tuple, with the given field layout.
function getField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the field from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
fieldIndex | uint8 | The index of the field to get. |
fieldLayout | FieldLayout | The field layout for the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | The data of the field. |
getStaticField
Get a single static field from the given table ID and key tuple, with the given value field layout.
The field value is left-aligned in the returned bytes32, the rest of the word is not zeroed out. Consumers are expected to truncate the returned value as needed.
function getStaticField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) internal view returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the static field from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
fieldIndex | uint8 | The index of the field to get. |
fieldLayout | FieldLayout | The field layout for the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The data of the static field. |
getDynamicField
Get a single dynamic field from the given table ID and key tuple.
function getDynamicField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex
) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the dynamic field from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to get, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | The data of the dynamic field. |
getFieldLength
Get the byte length of a single field from the given table ID and key tuple.
This function internally calls another overload of getFieldLength
, loading the field layout from storage.
If the field layout is available to the caller, it is recommended to use the other overload to avoid an additional storage read.
function getFieldLength(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex
) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the field length from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
fieldIndex | uint8 | The index of the field to get the length for. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The byte length of the field. |
getFieldLength
Get the byte length of a single field from the given table ID and key tuple.
function getFieldLength(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the field length from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
fieldIndex | uint8 | The index of the field to get the length for. |
fieldLayout | FieldLayout | The field layout for the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The byte length of the field. |
getDynamicFieldLength
Get the byte length of a single dynamic field from the given table ID and key tuple.
function getDynamicFieldLength(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex
) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the dynamic field length from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to get the length for, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The byte length of the dynamic field. |
getDynamicFieldSlice
Get a byte slice (including start, excluding end) of a single dynamic field from the given table ID and key tuple.
function getDynamicFieldSlice(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint256 start,
uint256 end
) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the dynamic field slice from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to get the slice from, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) |
start | uint256 | The start index within the dynamic field for the slice operation (inclusive). |
end | uint256 | The end index within the dynamic field for the slice operation (exclusive). |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | The byte slice of the dynamic field. |
Events
Store_SetRecord
Emitted when a new record is set in the store.
event Store_SetRecord(
ResourceId indexed tableId, bytes32[] keyTuple, bytes staticData, PackedCounter encodedLengths, bytes dynamicData
);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table where the record is set. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
staticData | bytes | The static data of the record. |
encodedLengths | PackedCounter | The encoded lengths of the dynamic data of the record. |
dynamicData | bytes | The dynamic data of the record. |
Store_SpliceStaticData
Emitted when static data in the store is spliced.
In static data, data is always overwritten starting at the start position, so the total length of the data remains the same and no data is shifted.
event Store_SpliceStaticData(ResourceId indexed tableId, bytes32[] keyTuple, uint48 start, bytes data);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table where the data is spliced. |
keyTuple | bytes32[] | An array representing the key for the record. |
start | uint48 | The start position in bytes for the splice operation. |
data | bytes | The data to write to the static data of the record at the start byte. |
Store_SpliceDynamicData
Emitted when dynamic data in the store is spliced.
event Store_SpliceDynamicData(
ResourceId indexed tableId,
bytes32[] keyTuple,
uint8 dynamicFieldIndex,
uint48 start,
uint40 deleteCount,
PackedCounter encodedLengths,
bytes data
);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table where the data is spliced. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to splice data, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) |
start | uint48 | The start position in bytes for the splice operation. |
deleteCount | uint40 | The number of bytes to delete in the splice operation. |
encodedLengths | PackedCounter | The encoded lengths of the dynamic data of the record. |
data | bytes | The data to insert into the dynamic data of the record at the start byte. |
Store_DeleteRecord
Emitted when a record is deleted from the store.
event Store_DeleteRecord(ResourceId indexed tableId, bytes32[] keyTuple);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table where the record is deleted. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
StoreCoreInternal
Git Source (opens in a new tab)
This library contains internal functions used by StoreCore. They are not intended to be used directly by consumers of StoreCore.
State Variables
SLOT
bytes32 internal constant SLOT = keccak256("mud.store");
DYNAMIC_DATA_SLOT
bytes32 internal constant DYNAMIC_DATA_SLOT = keccak256("mud.store.dynamicData");
DYNAMIC_DATA_LENGTH_SLOT
bytes32 internal constant DYNAMIC_DATA_LENGTH_SLOT = keccak256("mud.store.dynamicDataLength");
Functions
_spliceDynamicData
Splice dynamic data in the store.
This function checks various conditions to ensure the operation is valid.
It emits a Store_SpliceDynamicData
event, calls onBeforeSpliceDynamicData
hooks before actually modifying the storage,
and calls onAfterSpliceDynamicData
hooks after modifying the storage.
It reverts with Store_InvalidResourceType
if the table ID is not a table.
(Splicing dynamic data is not supported for offchain tables, as it requires reading the previous encoded lengths from storage.)
It reverts with Store_InvalidSplice
if the splice total length of the field is changed but the splice is not at the end of the field.
It reverts with Store_IndexOutOfBounds
if the start index is larger than the previous length of the field.
function _spliceDynamicData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
bytes memory data,
PackedCounter previousEncodedLengths
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to splice dynamic data. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to splice data, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) |
startWithinField | uint40 | The start index within the field for the splice operation. |
deleteCount | uint40 | The number of bytes to delete in the splice operation. |
data | bytes | The data to insert into the dynamic data of the record at the start byte. |
previousEncodedLengths | PackedCounter | The previous encoded lengths of the dynamic data of the record. |
_getStaticData
Get full static data for the given table ID and key tuple, with the given length in bytes.
function _getStaticData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint256 length
) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the static data from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
length | uint256 | The length of the static data to retrieve. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | The full static data of the specified length. |
_getStaticFieldBytes
Get a single static field from the given table ID and key tuple, with the given value field layout.
function _getStaticFieldBytes(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to get the static field from. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
fieldIndex | uint8 | The index of the field to get. |
fieldLayout | FieldLayout | The field layout for the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | The static field data as dynamic bytes in the size of the field. |
_getStaticDataLocation
Compute the storage location based on table ID and key tuple.
function _getStaticDataLocation(ResourceId tableId, bytes32[] memory keyTuple) internal pure returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The computed storage location based on table ID and key tuple. |
_getStaticDataLocation
Compute the storage location based on table ID and a single key.
function _getStaticDataLocation(ResourceId tableId, bytes32 key) internal pure returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
key | bytes32 | The single key for the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The computed storage location based on table ID and key. |
_getStaticDataOffset
Get storage offset for the given value field layout and index.
function _getStaticDataOffset(FieldLayout fieldLayout, uint8 fieldIndex) internal pure returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
fieldLayout | FieldLayout | The field layout for the record. |
fieldIndex | uint8 | The index of the field to get the offset for. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The storage offset for the specified field layout and index. |
_getDynamicDataLocation
Compute the storage location based on table ID, key tuple, and dynamic field index.
function _getDynamicDataLocation(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex
) internal pure returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field, relative to the start of the dynamic fields. (Dynamic field index = field index - number of static fields) |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The computed storage location based on table ID, key tuple, and dynamic field index. |
_getDynamicDataLengthLocation
Compute the storage location for the length of the dynamic data based on table ID and key tuple.
function _getDynamicDataLengthLocation(ResourceId tableId, bytes32[] memory keyTuple) internal pure returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The computed storage location for the length of the dynamic data based on table ID and key tuple. |
_loadEncodedDynamicDataLength
Load the encoded dynamic data length from storage for the given table ID and key tuple.
function _loadEncodedDynamicDataLength(
ResourceId tableId,
bytes32[] memory keyTuple
) internal view returns (PackedCounter);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | An array representing the composite key for the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | PackedCounter | The loaded encoded dynamic data length from storage for the given table ID and key tuple. |
StoreData
Git Source (opens in a new tab)
Inherits: IStoreData, StoreRead
This contract integrates the core storage functionalities and provides an interface for data storage.
This abstract contract initializes StoreCore
, implements storeVersion
, and read methods,
but not write methods.
Functions
constructor
Constructs the StoreData contract and initializes the StoreCore.
Emits a HelloStore event upon creation.
constructor();
storeVersion
Retrieves the version of the store.
function storeVersion() public pure returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The current version of the store as a bytes32. |
StoreRead
Git Source (opens in a new tab)
Inherits: IStoreRead
A contract that provides read operations for storage tables using StoreCore
.
Functions
getFieldLayout
Fetches the field layout for a given table.
function getFieldLayout(ResourceId tableId) public view virtual returns (FieldLayout fieldLayout);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table for which to retrieve the field layout. |
Returns
Name | Type | Description |
---|---|---|
fieldLayout | FieldLayout | The layout of fields in the specified table. |
getValueSchema
Retrieves the value schema for a given table.
function getValueSchema(ResourceId tableId) public view virtual returns (Schema valueSchema);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
Returns
Name | Type | Description |
---|---|---|
valueSchema | Schema | The schema for values in the specified table. |
getKeySchema
Retrieves the key schema for a given table.
function getKeySchema(ResourceId tableId) public view virtual returns (Schema keySchema);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
Returns
Name | Type | Description |
---|---|---|
keySchema | Schema | The schema for keys in the specified table. |
getRecord
Fetches a record from a specified table using a provided key tuple.
function getRecord(
ResourceId tableId,
bytes32[] calldata keyTuple
) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key to fetch the record. |
Returns
Name | Type | Description |
---|---|---|
staticData | bytes | The static data of the record. |
encodedLengths | PackedCounter | Encoded lengths of dynamic data. |
dynamicData | bytes | The dynamic data of the record. |
getRecord
Fetches a record from a specified table using a provided key tuple and field layout.
function getRecord(
ResourceId tableId,
bytes32[] calldata keyTuple,
FieldLayout fieldLayout
) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key to fetch the record. |
fieldLayout | FieldLayout | The layout of fields to retrieve. |
Returns
Name | Type | Description |
---|---|---|
staticData | bytes | The static data of the record. |
encodedLengths | PackedCounter | Encoded lengths of dynamic data. |
dynamicData | bytes | The dynamic data of the record. |
getField
Retrieves data for a specified field in a record.
This overload loads the FieldLayout from storage. If the table's FieldLayout is known to the caller, it should be passed in to the other overload to avoid the storage read.
function getField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 fieldIndex
) public view virtual returns (bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key to fetch the field. |
fieldIndex | uint8 | Index of the field to retrieve. |
Returns
Name | Type | Description |
---|---|---|
data | bytes | The data of the specified field. |
getField
Retrieves data for a specified field in a record.
function getField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) public view virtual returns (bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key to fetch the field. |
fieldIndex | uint8 | Index of the field to retrieve. |
fieldLayout | FieldLayout | The layout of fields for the retrieval. |
Returns
Name | Type | Description |
---|---|---|
data | bytes | The data of the specified field. |
getStaticField
Retrieves data for a specific static (fixed length) field in a record.
function getStaticField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) public view virtual returns (bytes32 data);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key to fetch the static field. |
fieldIndex | uint8 | Index of the static field to retrieve. |
fieldLayout | FieldLayout | The layout of fields for the retrieval. |
Returns
Name | Type | Description |
---|---|---|
data | bytes32 | The static data of the specified field. |
getDynamicField
Retrieves data for a specific dynamic (variable length) field in a record.
function getDynamicField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 dynamicFieldIndex
) public view virtual returns (bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key to fetch the dynamic field. |
dynamicFieldIndex | uint8 | Index of the dynamic field to retrieve. |
Returns
Name | Type | Description |
---|---|---|
data | bytes | The dynamic data of the specified field. |
getFieldLength
Calculates the length of a specified field in a record.
This overload loads the FieldLayout from storage. If the table's FieldLayout is known to the caller, it should be passed in to the other overload to avoid the storage read.
function getFieldLength(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex
) public view virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key. |
fieldIndex | uint8 | Index of the field to measure. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The length of the specified field. |
getFieldLength
Calculates the length of a specified field in a record.
function getFieldLength(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) public view virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key. |
fieldIndex | uint8 | Index of the field to measure. |
fieldLayout | FieldLayout | The layout of fields for measurement. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The length of the specified field. |
getDynamicFieldLength
Calculates the length of a specified dynamic (variable length) field in a record.
function getDynamicFieldLength(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex
) public view virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key. |
dynamicFieldIndex | uint8 | Index of the dynamic field to measure. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The length of the specified dynamic field. |
getDynamicFieldSlice
Retrieves a slice of a dynamic (variable length) field.
function getDynamicFieldSlice(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint256 start,
uint256 end
) public view virtual returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table. |
keyTuple | bytes32[] | The tuple used as a key to fetch the dynamic field slice. |
dynamicFieldIndex | uint8 | Index of the dynamic field to slice. |
start | uint256 | The starting position of the slice. |
end | uint256 | The ending position of the slice. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | The sliced data from the specified dynamic field. |
StoreSwitch
Usage Sample | Git Source (opens in a new tab) |
---|
This library serves as an interface switch to interact with the store, either by directing calls to itself or to a designated external store.
The primary purpose is to abstract the storage details, such that the calling function doesn't need to know if it's interacting with its own storage or with an external contract's storage.
State Variables
STORAGE_SLOT
Internal constant representing the storage slot used by the library.
bytes32 private constant STORAGE_SLOT = keccak256("mud.store.storage.StoreSwitch");
Functions
_layout
Gets the storage layout.
function _layout() private pure returns (StorageSlotLayout storage layout);
Returns
Name | Type | Description |
---|---|---|
layout | StorageSlotLayout | The current storage layout. |
getStoreAddress
Fetch the store address to be used for data operations. If _storeAddress is zero, it means that it's uninitialized and therefore it's the default (msg.sender).
function getStoreAddress() internal view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | Address of the store, or msg.sender if uninitialized. |
setStoreAddress
Set the store address for subsequent operations.
If it stays uninitialized, StoreSwitch falls back to calling store methods on msg.sender.
function setStoreAddress(address _storeAddress) internal;
Parameters
Name | Type | Description |
---|---|---|
_storeAddress | address | The address of the external store contract. |
registerStoreHook
Register a store hook for a particular table.
function registerStoreHook(ResourceId tableId, IStoreHook hookAddress, uint8 enabledHooksBitmap) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | Unique identifier of the table. |
hookAddress | IStoreHook | Address of the hook contract. |
enabledHooksBitmap | uint8 | Bitmap representing the hooks which this contract overrides. |
unregisterStoreHook
Unregister a previously registered store hook.
function unregisterStoreHook(ResourceId tableId, IStoreHook hookAddress) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | Unique identifier of the table. |
hookAddress | IStoreHook | Address of the hook contract to be unregistered. |
getFieldLayout
Fetches the field layout for a specified table.
function getFieldLayout(ResourceId tableId) internal view returns (FieldLayout fieldLayout);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table for which to retrieve the field layout. |
Returns
Name | Type | Description |
---|---|---|
fieldLayout | FieldLayout | The layout of the fields in the specified table. |
getValueSchema
Retrieves the value schema for a specified table.
function getValueSchema(ResourceId tableId) internal view returns (Schema valueSchema);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table for which to retrieve the value schema. |
Returns
Name | Type | Description |
---|---|---|
valueSchema | Schema | The schema for values in the specified table. |
getKeySchema
Retrieves the key schema for a specified table.
function getKeySchema(ResourceId tableId) internal view returns (Schema keySchema);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table for which to retrieve the key schema. |
Returns
Name | Type | Description |
---|---|---|
keySchema | Schema | The schema for keys in the specified table. |
registerTable
Registers a table with specified configurations.
function registerTable(
ResourceId tableId,
FieldLayout fieldLayout,
Schema keySchema,
Schema valueSchema,
string[] memory keyNames,
string[] memory fieldNames
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to register. |
fieldLayout | FieldLayout | The layout of the fields for the table. |
keySchema | Schema | The schema for keys in the table. |
valueSchema | Schema | The schema for values in the table. |
keyNames | string[] | Names of keys in the table. |
fieldNames | string[] | Names of fields in the table. |
setRecord
Sets a record in the store.
function setRecord(
ResourceId tableId,
bytes32[] memory keyTuple,
bytes memory staticData,
PackedCounter encodedLengths,
bytes memory dynamicData
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The table's ID. |
keyTuple | bytes32[] | Array of key values. |
staticData | bytes | Fixed-length fields data. |
encodedLengths | PackedCounter | Encoded lengths for dynamic data. |
dynamicData | bytes | Dynamic-length fields data. |
spliceStaticData
Splices the static (fixed length) data for a given table ID and key tuple, starting at a specific point.
function spliceStaticData(ResourceId tableId, bytes32[] memory keyTuple, uint48 start, bytes memory data) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the resource table. |
keyTuple | bytes32[] | An array of bytes32 keys identifying the data record. |
start | uint48 | The position to begin splicing. |
data | bytes | The data to splice into the record. |
spliceDynamicData
Splices the dynamic data for a given table ID, key tuple, and dynamic field index.
function spliceDynamicData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
bytes memory data
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the resource table. |
keyTuple | bytes32[] | An array of bytes32 keys identifying the data record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to splice. |
startWithinField | uint40 | The position within the dynamic field to start splicing. |
deleteCount | uint40 | The number of bytes to delete starting from the splice point. |
data | bytes | The data to splice into the dynamic field. |
setField
Sets the data for a specific field in a record identified by table ID and key tuple.
function setField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, bytes memory data) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the resource table. |
keyTuple | bytes32[] | An array of bytes32 keys identifying the data record. |
fieldIndex | uint8 | The index of the field to set. |
data | bytes | The data to set for the field. |
setField
Sets the data for a specific field in a record, considering a specific field layout.
function setField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
bytes memory data,
FieldLayout fieldLayout
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the resource table. |
keyTuple | bytes32[] | An array of bytes32 keys identifying the data record. |
fieldIndex | uint8 | The index of the field to set. |
data | bytes | The data to set for the field. |
fieldLayout | FieldLayout | The layout structure of the field. |
setStaticField
Sets the data for a specific static (fixed length) field in a record, considering a specific field layout.
function setStaticField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
bytes memory data,
FieldLayout fieldLayout
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the resource table. |
keyTuple | bytes32[] | An array of bytes32 keys identifying the data record. |
fieldIndex | uint8 | The index of the field to set. |
data | bytes | The data to set for the field. |
fieldLayout | FieldLayout | The layout structure of the field. |
setDynamicField
Sets the value of a specific dynamic (variable-length) field in a record.
function setDynamicField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
bytes memory data
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to set. |
data | bytes | The data to set for the field. |
pushToDynamicField
Appends data to a specific dynamic (variable length) field of a record.
function pushToDynamicField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
bytes memory dataToPush
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field. |
dataToPush | bytes | The data to append to the field. |
popFromDynamicField
Removes data from the end of a specific dynamic (variable length) field of a record.
function popFromDynamicField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint256 byteLengthToPop
) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field. |
byteLengthToPop | uint256 | The number of bytes to remove from the end of the field. |
deleteRecord
Deletes a record from a table.
function deleteRecord(ResourceId tableId, bytes32[] memory keyTuple) internal;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
getRecord
Retrieves a record from a table.
function getRecord(
ResourceId tableId,
bytes32[] memory keyTuple
) internal view returns (bytes memory, PackedCounter, bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | staticData The static data of the record. |
<none> | PackedCounter | encodedLengths Encoded lengths of dynamic data. |
<none> | bytes | dynamicData The dynamic data of the record. |
getRecord
Retrieves a record from a table with a specific layout.
function getRecord(
ResourceId tableId,
bytes32[] memory keyTuple,
FieldLayout fieldLayout
) internal view returns (bytes memory, PackedCounter, bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
fieldLayout | FieldLayout | The layout of the fields in the record. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | staticData The static data of the record. |
<none> | PackedCounter | encodedLengths Encoded lengths of dynamic data. |
<none> | bytes | dynamicData The dynamic data of the record. |
getField
Retrieves a specific field from a record.
function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
fieldIndex | uint8 | The index of the field to retrieve. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Returns the data of the specified field. |
getField
Retrieves a specific field from a record with a given layout.
function getField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
fieldIndex | uint8 | The index of the field to retrieve. |
fieldLayout | FieldLayout | The layout of the field being retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Returns the data of the specified field. |
getStaticField
Retrieves a specific static (fixed length) field from a record with a given layout.
function getStaticField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) internal view returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
fieldIndex | uint8 | The index of the static field to retrieve. |
fieldLayout | FieldLayout | The layout of the static field being retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | Returns the data of the specified static field. |
getDynamicField
Retrieves a specific dynamic (variable length) field from a record.
function getDynamicField(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex
) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field to retrieve. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Returns the data of the specified dynamic field. |
getFieldLength
Retrieves the length of a specific field in a record.
function getFieldLength(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex
) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
fieldIndex | uint8 | The index of the field whose length is to be retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Returns the length of the specified field. |
getFieldLength
Retrieves the length of a specific field in a record with a given layout.
function getFieldLength(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
fieldIndex | uint8 | The index of the field whose length is to be retrieved. |
fieldLayout | FieldLayout | The layout of the field whose length is to be retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Returns the length of the specified field. |
getDynamicFieldLength
Retrieves the length of a specific dynamic (variable length) field in a record.
function getDynamicFieldLength(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex
) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field whose length is to be retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Returns the length of the specified dynamic field. |
getDynamicFieldSlice
Retrieves a slice of a dynamic (variable length) field from a record.
function getDynamicFieldSlice(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint256 start,
uint256 end
) internal view returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The ID of the table to which the record belongs. |
keyTuple | bytes32[] | An array representing the key for the record. |
dynamicFieldIndex | uint8 | The index of the dynamic field from which to get the slice. |
start | uint256 | The starting index of the slice. |
end | uint256 | The ending index of the slice. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Returns the sliced data from the specified dynamic field. |
Structs
StorageSlotLayout
Represents the layout of the storage slot (currently just the address)
struct StorageSlotLayout {
address storeAddress;
}