Store
Reference
IStore (external)

IStore

Git Source (opens in a new tab)

Inherits: IStoreKernel, IStoreRegistration

IStoreEvents

Git Source (opens in a new tab)

Events

HelloStore

Emitted when the Store is created.

event HelloStore(bytes32 indexed storeVersion);

Parameters

NameTypeDescription
storeVersionbytes32The protocol version of the Store.

Store_SetRecord

Emitted when a new record is set in the store.

event Store_SetRecord(
  ResourceId indexed tableId,
  bytes32[] keyTuple,
  bytes staticData,
  EncodedLengths encodedLengths,
  bytes dynamicData
);

Parameters

NameTypeDescription
tableIdResourceIdThe ID of the table where the record is set.
keyTuplebytes32[]An array representing the composite key for the record.
staticDatabytesThe static data of the record.
encodedLengthsEncodedLengthsThe encoded lengths of the dynamic data of the record.
dynamicDatabytesThe 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

NameTypeDescription
tableIdResourceIdThe ID of the table where the data is spliced.
keyTuplebytes32[]An array representing the key for the record.
startuint48The start position in bytes for the splice operation.
databytesThe 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,
  EncodedLengths encodedLengths,
  bytes data
);

Parameters

NameTypeDescription
tableIdResourceIdThe ID of the table where the data is spliced.
keyTuplebytes32[]An array representing the composite key for the record.
dynamicFieldIndexuint8The 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)
startuint48The start position in bytes for the splice operation.
deleteCountuint40The number of bytes to delete in the splice operation.
encodedLengthsEncodedLengthsThe encoded lengths of the dynamic data of the record.
databytesThe 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

NameTypeDescription
tableIdResourceIdThe ID of the table where the record is deleted.
keyTuplebytes32[]An array representing the composite key for the record.

IStoreErrors

Git Source (opens in a new tab)

This interface includes errors for Store.

We bundle these errors in an interface (instead of at the file-level or in their corresponding library) so they can be inherited by IStore. This ensures that all possible errors are included in the IStore ABI for proper decoding in the frontend.

Errors

Store_TableAlreadyExists

Error raised if the provided table already exists.

error Store_TableAlreadyExists(ResourceId tableId, string tableIdString);

Parameters

NameTypeDescription
tableIdResourceIdThe ID of the table.
tableIdStringstringThe stringified ID of the table (for easier debugging if cleartext tableIds are used).

Store_TableNotFound

Error raised if the provided table cannot be found.

error Store_TableNotFound(ResourceId tableId, string tableIdString);

Parameters

NameTypeDescription
tableIdResourceIdThe ID of the table.
tableIdStringstringThe stringified ID of the table (for easier debugging if cleartext tableIds are used).

Store_InvalidResourceType

Error raised if the provided resource ID cannot be found.

error Store_InvalidResourceType(bytes2 expected, ResourceId resourceId, string resourceIdString);

Parameters

NameTypeDescription
expectedbytes2The expected resource type.
resourceIdResourceIdThe resource ID.
resourceIdStringstringThe stringified resource ID (for easier debugging).

Store_InvalidBounds

Error raised if the provided slice bounds are invalid.

error Store_InvalidBounds(uint256 start, uint256 end);

Parameters

NameTypeDescription
startuint256The start index within the dynamic field for the slice operation (inclusive).
enduint256The end index within the dynamic field for the slice operation (exclusive).

Store_IndexOutOfBounds

Error raised if the provided index is out of bounds.

Raised if the start index is larger than the previous length of the field.

error Store_IndexOutOfBounds(uint256 length, uint256 accessedIndex);

Parameters

NameTypeDescription
lengthuint256FIXME
accessedIndexuint256FIXME

Store_InvalidStaticDataLength

Error raised if the provided static data length is invalid.

error Store_InvalidStaticDataLength(uint256 expected, uint256 received);

Parameters

NameTypeDescription
expecteduint256The expected length.
receiveduint256The provided length.

Store_InvalidKeyNamesLength

Error raised if the provided key names length is invalid.

error Store_InvalidKeyNamesLength(uint256 expected, uint256 received);

Parameters

NameTypeDescription
expecteduint256The expected length.
receiveduint256The provided length.

Store_InvalidFieldNamesLength

Error raised if the provided field names length is invalid.

error Store_InvalidFieldNamesLength(uint256 expected, uint256 received);

Parameters

NameTypeDescription
expecteduint256The expected length.
receiveduint256The provided length.

Store_InvalidValueSchemaLength

Error raised if the provided value schema length is invalid.

error Store_InvalidValueSchemaLength(uint256 expected, uint256 received);

Parameters

NameTypeDescription
expecteduint256The expected length.
receiveduint256The provided length.

Store_InvalidValueSchemaStaticLength

Error raised if the provided schema static length is invalid.

error Store_InvalidValueSchemaStaticLength(uint256 expected, uint256 received);

Parameters

NameTypeDescription
expecteduint256The expected length.
receiveduint256The provided length.

Store_InvalidValueSchemaDynamicLength

Error raised if the provided schema dynamic length is invalid.

error Store_InvalidValueSchemaDynamicLength(uint256 expected, uint256 received);

Parameters

NameTypeDescription
expecteduint256The expected length.
receiveduint256The provided length.

Store_InvalidSplice

Error raised if the provided splice is invalid.

Raised if the splice total length of the field is changed but the splice is not at the end of the field.

error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength);

Parameters

NameTypeDescription
startWithinFielduint40The start index within the field for the splice operation.
deleteCountuint40The number of bytes to delete in the splice operation.
fieldLengthuint40The field length for the splice operation.

IStoreRead

Git Source (opens in a new tab)

Functions

getFieldLayout

function getFieldLayout(ResourceId tableId) external view returns (FieldLayout fieldLayout);

getValueSchema

function getValueSchema(ResourceId tableId) external view returns (Schema valueSchema);

getKeySchema

function getKeySchema(ResourceId tableId) external view returns (Schema keySchema);

getRecord

Get full record (all fields, static and dynamic data) for the given tableId and key tuple, loading the field layout from storage

function getRecord(
  ResourceId tableId,
  bytes32[] calldata keyTuple
) external view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData);

getRecord

Get full record (all fields, static and dynamic data) for the given tableId and key tuple, with the given field layout

function getRecord(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  FieldLayout fieldLayout
) external view returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData);

getField

Get a single field from the given tableId and key tuple, loading the field layout from storage

function getField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 fieldIndex
) external view returns (bytes memory data);

getField

Get a single field from the given tableId and key tuple, with the given field layout

function getField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 fieldIndex,
  FieldLayout fieldLayout
) external view returns (bytes memory data);

getStaticField

Get a single static field from the given tableId and key tuple, with the given value field layout. Note: 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[] calldata keyTuple,
  uint8 fieldIndex,
  FieldLayout fieldLayout
) external view returns (bytes32);

getDynamicField

Get a single dynamic field from the given tableId and key tuple at the given dynamic field index. (Dynamic field index = field index - number of static fields)

function getDynamicField(
  ResourceId tableId,
  bytes32[] memory keyTuple,
  uint8 dynamicFieldIndex
) external view returns (bytes memory);

getFieldLength

Get the byte length of a single field from the given tableId and key tuple, loading the field layout from storage

function getFieldLength(
  ResourceId tableId,
  bytes32[] memory keyTuple,
  uint8 fieldIndex
) external view returns (uint256);

getFieldLength

Get the byte length of a single field from the given tableId and key tuple, with the given value field layout

function getFieldLength(
  ResourceId tableId,
  bytes32[] memory keyTuple,
  uint8 fieldIndex,
  FieldLayout fieldLayout
) external view returns (uint256);

getDynamicFieldLength

Get the byte length of a single dynamic field from the given tableId and key tuple

function getDynamicFieldLength(
  ResourceId tableId,
  bytes32[] memory keyTuple,
  uint8 dynamicFieldIndex
) external view returns (uint256);

getDynamicFieldSlice

Get a byte slice (including start, excluding end) of a single dynamic field from the given tableId and key tuple, with the given value field layout. The slice is unchecked and will return invalid data if start:end overflow.

function getDynamicFieldSlice(
  ResourceId tableId,
  bytes32[] memory keyTuple,
  uint8 dynamicFieldIndex,
  uint256 start,
  uint256 end
) external view returns (bytes memory data);

IStoreWrite

Git Source (opens in a new tab)

Inherits: IStoreEvents

Functions

setRecord

function setRecord(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  bytes calldata staticData,
  EncodedLengths encodedLengths,
  bytes calldata dynamicData
) external;

spliceStaticData

function spliceStaticData(ResourceId tableId, bytes32[] calldata keyTuple, uint48 start, bytes calldata data) external;

spliceDynamicData

function spliceDynamicData(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 dynamicFieldIndex,
  uint40 startWithinField,
  uint40 deleteCount,
  bytes calldata data
) external;

setField

function setField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, bytes calldata data) external;

setField

function setField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 fieldIndex,
  bytes calldata data,
  FieldLayout fieldLayout
) external;

setStaticField

function setStaticField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 fieldIndex,
  bytes calldata data,
  FieldLayout fieldLayout
) external;

setDynamicField

function setDynamicField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 dynamicFieldIndex,
  bytes calldata data
) external;

pushToDynamicField

function pushToDynamicField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 dynamicFieldIndex,
  bytes calldata dataToPush
) external;

popFromDynamicField

function popFromDynamicField(
  ResourceId tableId,
  bytes32[] calldata keyTuple,
  uint8 dynamicFieldIndex,
  uint256 byteLengthToPop
) external;

deleteRecord

function deleteRecord(ResourceId tableId, bytes32[] memory keyTuple) external;

IStoreRegistration

Git Source (opens in a new tab)

This interface includes methods for managing table field layouts, metadata, and hooks, which are usually called once in the setup phase of an application, making them less performance critical than the methods.

Functions

registerTable

Usage Sample

function registerTable(
  ResourceId tableId,
  FieldLayout fieldLayout,
  Schema keySchema,
  Schema valueSchema,
  string[] calldata keyNames,
  string[] calldata fieldNames
) external;

registerStoreHook

Usage Sample

function registerStoreHook(ResourceId tableId, IStoreHook hookAddress, uint8 enabledHooksBitmap) external;

unregisterStoreHook

function unregisterStoreHook(ResourceId tableId, IStoreHook hookAddress) external;