#
Solidity API
#
AccessControl
#
hasAccess
function hasAccess(bytes16 namespace, bytes16 name, address caller) internal view returns (bool)
Returns true if the caller has access to the namespace or name, false otherwise.
#
requireAccess
function requireAccess(bytes16 namespace, bytes16 name, address caller) internal view returns (bytes32 resourceSelector)
Check for access at the given namespace or name. Returns the resourceSelector if the caller has access. Reverts with AccessDenied if the caller has no access.
#
requireOwnerOrSelf
function requireOwnerOrSelf(bytes16 namespace, bytes16 name, address caller) internal view returns (bytes32 resourceSelector)
#
Call
#
withSender
function withSender(address msgSender, address target, bytes funcSelectorAndArgs, bool delegate, uint256 value) internal returns (bytes)
Call a contract with delegatecall/call and append the given msgSender to the calldata. If the call is successfall, return the returndata as bytes memory. Else, forward the error (with a revert)
#
ROOT_NAMESPACE_STRING
bytes16 ROOT_NAMESPACE_STRING
#
ROOT_NAME_STRING
bytes16 ROOT_NAME_STRING
#
ResourceSelector
#
from
function from(bytes16 namespace, bytes16 name) internal pure returns (bytes32)
Create a 32-byte resource selector from a namespace and a name.
A ResourceSelector is a 32-byte value that uniquely identifies a resource. The first 16 bytes represent the namespace, the last 16 bytes represent the name.
#
from
function from(bytes16 namespace) internal pure returns (bytes32)
Create a 32-byte resource selector from a namespace. The selector points to the namespace's root name.
#
getNamespace
function getNamespace(bytes32 resourceSelector) internal pure returns (bytes16)
Get the namespace of a ResourceSelector.
#
getName
function getName(bytes32 resourceSelector) internal pure returns (bytes16)
Get the name of a ResourceSelector.
#
toString
function toString(bytes32 resourceSelector) internal pure returns (string)
Convert a selector to a string for more readable logs
#
toTrimmedString
function toTrimmedString(bytes16 selector) internal pure returns (string)
Convert a selector to a trimmed string (no trailing null
ASCII characters)
#
System
#
Resource
enum Resource {
NONE,
NAMESPACE,
TABLE,
SYSTEM
}
#
World
#
constructor
constructor() public
#
installRootModule
function installRootModule(contract IModule module, bytes args) public
Install the given root module in the World. Requires the caller to own the root namespace. The module is delegatecalled and installed in the root namespace.
#
setRecord
function setRecord(bytes16 namespace, bytes16 name, bytes32[] key, bytes data) public virtual
Write a record in the table at the given namespace and name. Requires the caller to have access to the namespace or name.
#
setField
function setField(bytes16 namespace, bytes16 name, bytes32[] key, uint8 schemaIndex, bytes data) public virtual
Write a field in the table at the given namespace and name. Requires the caller to have access to the namespace or name.
#
pushToField
function pushToField(bytes16 namespace, bytes16 name, bytes32[] key, uint8 schemaIndex, bytes dataToPush) public virtual
Push data to the end of a field in the table at the given namespace and name. Requires the caller to have access to the namespace or name.
#
updateInField
function updateInField(bytes16 namespace, bytes16 name, bytes32[] key, uint8 schemaIndex, uint256 startByteIndex, bytes dataToSet) public virtual
Update data at startByteIndex
of a field in the table at the given namespace and name.
Requires the caller to have access to the namespace or name.
#
deleteRecord
function deleteRecord(bytes16 namespace, bytes16 name, bytes32[] key) public virtual
Delete a record in the table at the given namespace and name. Requires the caller to have access to the namespace or name.
#
setRecord
function setRecord(bytes32 tableId, bytes32[] key, bytes data) public virtual
Write a record in the table at the given tableId.
This overload exists to conform with the IStore
interface.
Access is checked based on the namespace or name (encoded in the tableId).
#
setField
function setField(bytes32 tableId, bytes32[] key, uint8 schemaIndex, bytes data) public virtual
Write a field in the table at the given tableId.
This overload exists to conform with the IStore
interface.
Access is checked based on the namespace or name (encoded in the tableId).
#
pushToField
function pushToField(bytes32 tableId, bytes32[] key, uint8 schemaIndex, bytes dataToPush) public
Push data to the end of a field in the table at the given tableId.
This overload exists to conform with the IStore
interface.
Access is checked based on the namespace or name (encoded in the tableId).
#
updateInField
function updateInField(bytes32 tableId, bytes32[] key, uint8 schemaIndex, uint256 startByteIndex, bytes dataToSet) public virtual
Update data at startByteIndex
of a field in the table at the given tableId.
This overload exists to conform with the IStore
interface.
Access is checked based on the namespace or name (encoded in the tableId).
#
deleteRecord
function deleteRecord(bytes32 tableId, bytes32[] key) public virtual
Delete a record in the table at the given tableId.
This overload exists to conform with the IStore
interface.
Access is checked based on the namespace or name (encoded in the tableId).
#
call
function call(bytes16 namespace, bytes16 name, bytes funcSelectorAndArgs) external payable virtual returns (bytes)
Call the system at the given namespace and name. If the system is not public, the caller must have access to the namespace or name.
#
_call
function _call(bytes16 namespace, bytes16 name, bytes funcSelectorAndArgs, uint256 value) internal virtual returns (bytes)
Call the system at the given namespace and name and pass the given value. If the system is not public, the caller must have access to the namespace or name.
#
receive
receive() external payable
Allow the World to receive ETH
#
fallback
fallback() external payable
Fallback function to call registered function selectors
#
WorldContext
#
_msgSender
function _msgSender() internal view returns (address sender)
#
_world
function _world() internal view returns (address)
#
ROOT_NAMESPACE
bytes16 ROOT_NAMESPACE
#
ROOT_NAME
bytes16 ROOT_NAME
#
IAccessManagementSystem
#
grantAccess
function grantAccess(bytes16 namespace, bytes16 name, address grantee) external
#
revokeAccess
function revokeAccess(bytes16 namespace, bytes16 name, address grantee) external
#
IBaseWorld
The IBaseWorld interface includes all systems dynamically added to the World during the deploy process.
#
ICoreSystem
#
IErrors
#
ResourceExists
error ResourceExists(string resource)
#
ResourceNotFound
error ResourceNotFound(string resource)
#
AccessDenied
error AccessDenied(string resource, address caller)
#
InvalidSelector
error InvalidSelector(string resource)
#
SystemExists
error SystemExists(address system)
#
FunctionSelectorExists
error FunctionSelectorExists(bytes4 functionSelector)
#
FunctionSelectorNotFound
error FunctionSelectorNotFound(bytes4 functionSelector)
#
ModuleAlreadyInstalled
error ModuleAlreadyInstalled(string module)
#
IModule
#
RequiredModuleNotFound
error RequiredModuleNotFound(string resourceSelector)
#
getName
function getName() external view returns (bytes16 name)
Return the module name as a bytes16.
#
install
function install(bytes args) external
A module expects to be called via the World contract, and therefore installs itself on its msg.sender
.
#
IModuleInstallationSystem
#
installModule
function installModule(contract IModule module, bytes args) external
#
IStoreRegistrationSystem
#
registerSchema
function registerSchema(bytes32 tableId, Schema valueSchema, Schema keySchema) external
#
setMetadata
function setMetadata(bytes32 tableId, string tableName, string[] fieldNames) external
#
registerStoreHook
function registerStoreHook(bytes32 tableId, contract IStoreHook hook) external
#
ISystemHook
#
onCallSystem
function onCallSystem(address msgSender, address systemAddress, bytes funcSelectorAndArgs) external
#
IUniqueEntitySystem
#
uniqueEntity_system_getUniqueEntity
function uniqueEntity_system_getUniqueEntity() external returns (bytes32 uniqueEntity)
#
IWorldData
The IWorldData interface includes methods for reading and writing table values. These methods are frequently invoked during runtime, so it is essential to prioritize optimizing their gas cost, and they are part of the World contract's internal bytecode.
#
setRecord
function setRecord(bytes16 namespace, bytes16 name, bytes32[] key, bytes data) external
Write a record in the table at the given namespace and name. Requires the caller to have access to the namespace or name.
#
setField
function setField(bytes16 namespace, bytes16 name, bytes32[] key, uint8 schemaIndex, bytes data) external
Write a field in the table at the given namespace and name. Requires the caller to have access to the namespace or name.
#
pushToField
function pushToField(bytes16 namespace, bytes16 name, bytes32[] key, uint8 schemaIndex, bytes dataToPush) external
Push data to the end of a field in the table at the given namespace and name. Requires the caller to have access to the namespace or name.
#
updateInField
function updateInField(bytes16 namespace, bytes16 name, bytes32[] key, uint8 schemaIndex, uint256 startByteIndex, bytes dataToSet) external
Update data at startByteIndex
of a field in the table at the given namespace and name.
Requires the caller to have access to the namespace or name.
#
deleteRecord
function deleteRecord(bytes16 namespace, bytes16 name, bytes32[] key) external
Delete a record in the table at the given namespace and name. Requires the caller to have access to the namespace or name.
#
IWorldModuleInstallation
#
installRootModule
function installRootModule(contract IModule module, bytes args) external
Install the given root module in the World. Requires the caller to own the root namespace. The module is delegatecalled and installed in the root namespace.
#
IWorldCall
#
call
function call(bytes16 namespace, bytes16 name, bytes funcSelectorAndArgs) external payable returns (bytes)
Call the system at the given namespace and name. If the system is not public, the caller must have access to the namespace or name.
#
IWorldKernel
The IWorldKernel interface includes all methods that are part of the World contract's internal bytecode.
Consumers should use the IBaseWorld
interface instead, which includes dynamically
registered functions selectors from the CoreModule
.
#
IWorldRegistrationSystem
#
registerNamespace
function registerNamespace(bytes16 namespace) external
#
registerTable
function registerTable(bytes16 namespace, bytes16 name, Schema valueSchema, Schema keySchema) external returns (bytes32 resourceSelector)
#
setMetadata
function setMetadata(bytes16 namespace, bytes16 name, string tableName, string[] fieldNames) external
#
registerHook
function registerHook(bytes16 namespace, bytes16 name, address hook) external
#
registerTableHook
function registerTableHook(bytes16 namespace, bytes16 name, contract IStoreHook hook) external
#
registerSystemHook
function registerSystemHook(bytes16 namespace, bytes16 name, contract ISystemHook hook) external
#
registerSystem
function registerSystem(bytes16 namespace, bytes16 name, contract System system, bool publicAccess) external returns (bytes32 resourceSelector)
#
registerFunctionSelector
function registerFunctionSelector(bytes16 namespace, bytes16 name, string systemFunctionName, string systemFunctionArguments) external returns (bytes4 worldFunctionSelector)
#
registerRootFunctionSelector
function registerRootFunctionSelector(bytes16 namespace, bytes16 name, bytes4 worldFunctionSelector, bytes4 systemFunctionSelector) external returns (bytes4)
#
CoreModule
The CoreModule registers internal World tables, the CoreSystem, and its function selectors.
Note:
This module is required to be delegatecalled (via World.registerRootSystem
),
because it needs to install root tables, systems and function selectors.
#
coreSystem
address coreSystem
#
getName
function getName() public pure returns (bytes16)
Return the module name as a bytes16.
#
install
function install(bytes) public
#
_registerCoreTables
function _registerCoreTables() internal
Register core tables in the World
#
_registerCoreSystem
function _registerCoreSystem() internal
Register the CoreSystem in the World
#
_registerFunctionSelectors
function _registerFunctionSelectors() internal
Register function selectors for all CoreSystem functions in the World
#
CoreSystem
The CoreSystem includes all World functionality that is externalized from the World contract to keep the World contract's bytecode as lean as possible.
#
CORE_MODULE_NAME
bytes16 CORE_MODULE_NAME
#
CORE_SYSTEM_NAME
bytes16 CORE_SYSTEM_NAME
#
AccessManagementSystem
Granting and revoking access from/to resources.
#
grantAccess
function grantAccess(bytes16 namespace, bytes16 name, address grantee) public virtual
Grant access to the resource at the given namespace and name. Requires the caller to own the namespace.
#
revokeAccess
function revokeAccess(bytes16 namespace, bytes16 name, address grantee) public virtual
Revoke access from the resource at the given namespace and name. Requires the caller to own the namespace.
#
ModuleInstallationSystem
Installation of (non-root) modules in the World.
#
installModule
function installModule(contract IModule module, bytes args) public
Install the given module at the given namespace in the World.
#
StoreRegistrationSystem
World framework implementation of IStoreRegistration.
See
#
registerSchema
function registerSchema(bytes32 tableId, Schema valueSchema, Schema keySchema) public virtual
Register the given schema for the given table id. This overload exists to conform with the IStore interface. Access is checked based on the namespace or name (encoded in the tableId).
#
setMetadata
function setMetadata(bytes32 tableId, string tableName, string[] fieldNames) public virtual
Register metadata (tableName, fieldNames) for the table at the given tableId.
This overload exists to conform with the IStore
interface.
Access is checked based on the namespace or name (encoded in the tableId).
#
registerStoreHook
function registerStoreHook(bytes32 tableId, contract IStoreHook hook) public virtual
Register a hook for the table at the given tableId.
This overload exists to conform with the IStore
interface.
Access is checked based on the namespace or name (encoded in the tableId).
#
WorldRegistrationSystem
Functions related to registering resources in the World.
#
registerNamespace
function registerNamespace(bytes16 namespace) public virtual
Register a new namespace
#
registerTable
function registerTable(bytes16 namespace, bytes16 name, Schema valueSchema, Schema keySchema) public virtual returns (bytes32 resourceSelector)
Register a table with given schema in the given namespace
#
setMetadata
function setMetadata(bytes16 namespace, bytes16 name, string tableName, string[] fieldNames) public virtual
Register metadata (tableName, fieldNames) for the table at the given namespace and name. Requires the caller to own the namespace.
#
registerHook
function registerHook(bytes16 namespace, bytes16 name, address hook) public virtual
Register the given store hook for the table at the given namespace and name. Hooks on table names must implement the IStoreHook interface, and hooks on system names must implement the ISystemHook interface.
#
registerTableHook
function registerTableHook(bytes16 namespace, bytes16 name, contract IStoreHook hook) public virtual
Register a hook for the table at the given namepace and name. Requires the caller to own the namespace.
#
registerSystemHook
function registerSystemHook(bytes16 namespace, bytes16 name, contract ISystemHook hook) public virtual
Register a hook for the system at the given namespace and name
#
registerSystem
function registerSystem(bytes16 namespace, bytes16 name, contract System system, bool publicAccess) public virtual returns (bytes32 resourceSelector)
Register the given system in the given namespace. If the namespace doesn't exist yet, it is registered. The system is granted access to its namespace, so it can write to any table in the same namespace. If publicAccess is true, no access control check is performed for calling the system.
#
registerFunctionSelector
function registerFunctionSelector(bytes16 namespace, bytes16 name, string systemFunctionName, string systemFunctionArguments) public returns (bytes4 worldFunctionSelector)
Register a World function selector for the given namespace, name and system function. TODO: instead of mapping to a resource, the function selector could map direcly to a system function, which would save one sload per call, but add some complexity to upgrading systems. TBD. (see https://github.com/latticexyz/mud/issues/444)
#
registerRootFunctionSelector
function registerRootFunctionSelector(bytes16 namespace, bytes16 name, bytes4 worldFunctionSelector, bytes4 systemFunctionSelector) public returns (bytes4)
Register a root World function selector (without namespace / name prefix). Requires the caller to own the root namespace. TODO: instead of mapping to a resource, the function selector could map direcly to a system function, which would save one sload per call, but add some complexity to upgrading systems. TBD. (see https://github.com/latticexyz/mud/issues/444)
#
_tableId
bytes32 _tableId
#
FunctionSelectorsTableId
bytes32 FunctionSelectorsTableId
#
FunctionSelectors
#
getSchema
function getSchema() internal pure returns (Schema)
Get the table's schema
#
getKeySchema
function getKeySchema() internal pure returns (Schema)
#
getMetadata
function getMetadata() internal pure returns (string, string[])
Get the table's metadata
#
registerSchema
function registerSchema() internal
Register the table's schema
#
registerSchema
function registerSchema(contract IStore _store) internal
Register the table's schema (using the specified store)
#
setMetadata
function setMetadata() internal
Set the table's metadata
#
setMetadata
function setMetadata(contract IStore _store) internal
Set the table's metadata (using the specified store)
#
getNamespace
function getNamespace(bytes4 functionSelector) internal view returns (bytes16 namespace)
Get namespace
#
getNamespace
function getNamespace(contract IStore _store, bytes4 functionSelector) internal view returns (bytes16 namespace)
Get namespace (using the specified store)
#
setNamespace
function setNamespace(bytes4 functionSelector, bytes16 namespace) internal
Set namespace
#
setNamespace
function setNamespace(contract IStore _store, bytes4 functionSelector, bytes16 namespace) internal
Set namespace (using the specified store)
#
getName
function getName(bytes4 functionSelector) internal view returns (bytes16 name)
Get name
#
getName
function getName(contract IStore _store, bytes4 functionSelector) internal view returns (bytes16 name)
Get name (using the specified store)
#
setName
function setName(bytes4 functionSelector, bytes16 name) internal
Set name
#
setName
function setName(contract IStore _store, bytes4 functionSelector, bytes16 name) internal
Set name (using the specified store)
#
getSystemFunctionSelector
function getSystemFunctionSelector(bytes4 functionSelector) internal view returns (bytes4 systemFunctionSelector)
Get systemFunctionSelector
#
getSystemFunctionSelector
function getSystemFunctionSelector(contract IStore _store, bytes4 functionSelector) internal view returns (bytes4 systemFunctionSelector)
Get systemFunctionSelector (using the specified store)
#
setSystemFunctionSelector
function setSystemFunctionSelector(bytes4 functionSelector, bytes4 systemFunctionSelector) internal
Set systemFunctionSelector
#
setSystemFunctionSelector
function setSystemFunctionSelector(contract IStore _store, bytes4 functionSelector, bytes4 systemFunctionSelector) internal
Set systemFunctionSelector (using the specified store)
#
get
function get(bytes4 functionSelector) internal view returns (bytes16 namespace, bytes16 name, bytes4 systemFunctionSelector)
Get the full data
#
get
function get(contract IStore _store, bytes4 functionSelector) internal view returns (bytes16 namespace, bytes16 name, bytes4 systemFunctionSelector)
Get the full data (using the specified store)
#
set
function set(bytes4 functionSelector, bytes16 namespace, bytes16 name, bytes4 systemFunctionSelector) internal
Set the full data using individual values
#
set
function set(contract IStore _store, bytes4 functionSelector, bytes16 namespace, bytes16 name, bytes4 systemFunctionSelector) internal
Set the full data using individual values (using the specified store)
#
decode
function decode(bytes _blob) internal pure returns (bytes16 namespace, bytes16 name, bytes4 systemFunctionSelector)
Decode the tightly packed blob using this table's schema
#
encode
function encode(bytes16 namespace, bytes16 name, bytes4 systemFunctionSelector) internal view returns (bytes)
Tightly pack full data using this table's schema
#
deleteRecord
function deleteRecord(bytes4 functionSelector) internal
#
deleteRecord
function deleteRecord(contract IStore _store, bytes4 functionSelector) internal
#
_tableId
bytes32 _tableId
#
ResourceTypeTableId
bytes32 ResourceTypeTableId
#
ResourceType
#
getSchema
function getSchema() internal pure returns (Schema)
Get the table's schema
#
getKeySchema
function getKeySchema() internal pure returns (Schema)
#
getMetadata
function getMetadata() internal pure returns (string, string[])
Get the table's metadata
#
registerSchema
function registerSchema() internal
Register the table's schema
#
registerSchema
function registerSchema(contract IStore _store) internal
Register the table's schema (using the specified store)
#
setMetadata
function setMetadata() internal
Set the table's metadata
#
setMetadata
function setMetadata(contract IStore _store) internal
Set the table's metadata (using the specified store)
#
get
function get(bytes32 resourceSelector) internal view returns (enum Resource resourceType)
Get resourceType
#
get
function get(contract IStore _store, bytes32 resourceSelector) internal view returns (enum Resource resourceType)
Get resourceType (using the specified store)
#
set
function set(bytes32 resourceSelector, enum Resource resourceType) internal
Set resourceType
#
set
function set(contract IStore _store, bytes32 resourceSelector, enum Resource resourceType) internal
Set resourceType (using the specified store)
#
encode
function encode(enum Resource resourceType) internal view returns (bytes)
Tightly pack full data using this table's schema
#
deleteRecord
function deleteRecord(bytes32 resourceSelector) internal
#
deleteRecord
function deleteRecord(contract IStore _store, bytes32 resourceSelector) internal
#
_tableId
bytes32 _tableId
#
SystemRegistryTableId
bytes32 SystemRegistryTableId
#
SystemRegistry
#
getSchema
function getSchema() internal pure returns (Schema)
Get the table's schema
#
getKeySchema
function getKeySchema() internal pure returns (Schema)
#
getMetadata
function getMetadata() internal pure returns (string, string[])
Get the table's metadata
#
registerSchema
function registerSchema() internal
Register the table's schema
#
registerSchema
function registerSchema(contract IStore _store) internal
Register the table's schema (using the specified store)
#
setMetadata
function setMetadata() internal
Set the table's metadata
#
setMetadata
function setMetadata(contract IStore _store) internal
Set the table's metadata (using the specified store)
#
get
function get(address system) internal view returns (bytes32 resourceSelector)
Get resourceSelector
#
get
function get(contract IStore _store, address system) internal view returns (bytes32 resourceSelector)
Get resourceSelector (using the specified store)
#
set
function set(address system, bytes32 resourceSelector) internal
Set resourceSelector
#
set
function set(contract IStore _store, address system, bytes32 resourceSelector) internal
Set resourceSelector (using the specified store)
#
encode
function encode(bytes32 resourceSelector) internal view returns (bytes)
Tightly pack full data using this table's schema
#
deleteRecord
function deleteRecord(address system) internal
#
deleteRecord
function deleteRecord(contract IStore _store, address system) internal
#
_tableId
bytes32 _tableId
#
SystemsTableId
bytes32 SystemsTableId
#
Systems
#
getSchema
function getSchema() internal pure returns (Schema)
Get the table's schema
#
getKeySchema
function getKeySchema() internal pure returns (Schema)
#
getMetadata
function getMetadata() internal pure returns (string, string[])
Get the table's metadata
#
registerSchema
function registerSchema() internal
Register the table's schema
#
registerSchema
function registerSchema(contract IStore _store) internal
Register the table's schema (using the specified store)
#
setMetadata
function setMetadata() internal
Set the table's metadata
#
setMetadata
function setMetadata(contract IStore _store) internal
Set the table's metadata (using the specified store)
#
getSystem
function getSystem(bytes32 resourceSelector) internal view returns (address system)
Get system
#
getSystem
function getSystem(contract IStore _store, bytes32 resourceSelector) internal view returns (address system)
Get system (using the specified store)
#
setSystem
function setSystem(bytes32 resourceSelector, address system) internal
Set system
#
setSystem
function setSystem(contract IStore _store, bytes32 resourceSelector, address system) internal
Set system (using the specified store)
#
getPublicAccess
function getPublicAccess(bytes32 resourceSelector) internal view returns (bool publicAccess)
Get publicAccess
#
getPublicAccess
function getPublicAccess(contract IStore _store, bytes32 resourceSelector) internal view returns (bool publicAccess)
Get publicAccess (using the specified store)
#
setPublicAccess
function setPublicAccess(bytes32 resourceSelector, bool publicAccess) internal
Set publicAccess
#
setPublicAccess
function setPublicAccess(contract IStore _store, bytes32 resourceSelector, bool publicAccess) internal
Set publicAccess (using the specified store)
#
get
function get(bytes32 resourceSelector) internal view returns (address system, bool publicAccess)
Get the full data
#
get
function get(contract IStore _store, bytes32 resourceSelector) internal view returns (address system, bool publicAccess)
Get the full data (using the specified store)
#
set
function set(bytes32 resourceSelector, address system, bool publicAccess) internal
Set the full data using individual values
#
set
function set(contract IStore _store, bytes32 resourceSelector, address system, bool publicAccess) internal
Set the full data using individual values (using the specified store)
#
decode
function decode(bytes _blob) internal pure returns (address system, bool publicAccess)
Decode the tightly packed blob using this table's schema
#
encode
function encode(address system, bool publicAccess) internal view returns (bytes)
Tightly pack full data using this table's schema
#
deleteRecord
function deleteRecord(bytes32 resourceSelector) internal
#
deleteRecord
function deleteRecord(contract IStore _store, bytes32 resourceSelector) internal
#
freeFunction
freeFunction _toBool(uint8 value) internal pure returns (bool result)
#
KeysWithValueHook
This is a very naive and inefficient implementation for now.
We can optimize this by adding support for setIndexOfField
in Store
and then replicate logic from solecs's Set.sol.
(See https://github.com/latticexyz/mud/issues/444)
Note: if a table with composite keys is used, only the first key is indexed
#
onSetRecord
function onSetRecord(bytes32 sourceTableId, bytes32[] key, bytes data) public
#
onBeforeSetField
function onBeforeSetField(bytes32 sourceTableId, bytes32[] key, uint8, bytes) public
#
onAfterSetField
function onAfterSetField(bytes32 sourceTableId, bytes32[] key, uint8, bytes) public
#
onDeleteRecord
function onDeleteRecord(bytes32 sourceTableId, bytes32[] key) public
#
_removeKeyFromList
function _removeKeyFromList(bytes32 targetTableId, bytes32 key, bytes32 valueHash) internal
#
KeysWithValueModule
This module deploys a hook that is called when a value is set in the sourceTableId
provided in the install methods arguments. The hook keeps track of the keys that map to a given value.
from value to list of keys with this value. This mapping is stored in a table registered
by the module at the targetTableId
provided in the install methods arguments.
Note: if a table with composite keys is used, only the first key is indexed
Note: this module currently expects to be delegatecalled
via World.installRootModule.
Support for installing it via World.installModule
depends on World.callFrom
being implemented.
#
hook
contract KeysWithValueHook hook
#
getName
function getName() public pure returns (bytes16)
Return the module name as a bytes16.
#
install
function install(bytes args) public
A module expects to be called via the World contract, and therefore installs itself on its msg.sender
.
#
MODULE_NAMESPACE
bytes8 MODULE_NAMESPACE
#
freeFunction
freeFunction getKeysWithValue(bytes32 tableId, bytes value) internal view returns (bytes32[] keysWithValue)
Get a list of keys with the given value.
Note: this util can only be called within the context of a Store (e.g. from a System or Module). For usage outside of a Store, use the overload that takes an explicit store argument.
#
freeFunction
freeFunction getKeysWithValue(contract IStore store, bytes32 tableId, bytes value) internal view returns (bytes32[] keysWithValue)
Get a list of keys with the given value for the given store.
#
KeysWithValue
#
getSchema
function getSchema() internal pure returns (Schema)
Get the table's schema
#
getKeySchema
function getKeySchema() internal pure returns (Schema)
#
getMetadata
function getMetadata() internal pure returns (string, string[])
Get the table's metadata
#
registerSchema
function registerSchema(bytes32 _tableId) internal
Register the table's schema
#
registerSchema
function registerSchema(contract IStore _store, bytes32 _tableId) internal
Register the table's schema (using the specified store)
#
setMetadata
function setMetadata(bytes32 _tableId) internal
Set the table's metadata
#
setMetadata
function setMetadata(contract IStore _store, bytes32 _tableId) internal
Set the table's metadata (using the specified store)
#
get
function get(bytes32 _tableId, bytes32 valueHash) internal view returns (bytes32[] keysWithValue)
Get keysWithValue
#
get
function get(contract IStore _store, bytes32 _tableId, bytes32 valueHash) internal view returns (bytes32[] keysWithValue)
Get keysWithValue (using the specified store)
#
set
function set(bytes32 _tableId, bytes32 valueHash, bytes32[] keysWithValue) internal
Set keysWithValue
#
set
function set(contract IStore _store, bytes32 _tableId, bytes32 valueHash, bytes32[] keysWithValue) internal
Set keysWithValue (using the specified store)
#
push
function push(bytes32 _tableId, bytes32 valueHash, bytes32 _element) internal
Push an element to keysWithValue
#
push
function push(contract IStore _store, bytes32 _tableId, bytes32 valueHash, bytes32 _element) internal
Push an element to keysWithValue (using the specified store)
#
update
function update(bytes32 _tableId, bytes32 valueHash, uint256 _index, bytes32 _element) internal
Update an element of keysWithValue at _index
#
update
function update(contract IStore _store, bytes32 _tableId, bytes32 valueHash, uint256 _index, bytes32 _element) internal
Update an element of keysWithValue (using the specified store) at _index
#
encode
function encode(bytes32[] keysWithValue) internal view returns (bytes)
Tightly pack full data using this table's schema
#
deleteRecord
function deleteRecord(bytes32 _tableId, bytes32 valueHash) internal
#
deleteRecord
function deleteRecord(contract IStore _store, bytes32 _tableId, bytes32 valueHash) internal
#
UniqueEntityModule
This module creates a table that stores a nonce, and a public system that returns an incremented nonce each time.
#
uniqueEntitySystem
contract UniqueEntitySystem uniqueEntitySystem
#
getName
function getName() public pure returns (bytes16)
Return the module name as a bytes16.
#
install
function install(bytes) public
#
UniqueEntitySystem
#
getUniqueEntity
function getUniqueEntity() public virtual returns (bytes32)
Increment and get an entity nonce.
#
NAMESPACE
bytes16 NAMESPACE
#
MODULE_NAME
bytes16 MODULE_NAME
#
SYSTEM_NAME
bytes16 SYSTEM_NAME
#
TABLE_NAME
bytes16 TABLE_NAME
#
freeFunction
freeFunction getUniqueEntity() internal returns (bytes32 uniqueEntity)
Increment and get an entity nonce.
Note: this util can only be called within the context of a World (e.g. from a System or Module). For usage outside of a World, use the overload that takes an explicit store argument.
#
freeFunction
freeFunction getUniqueEntity(contract IBaseWorld world) internal returns (bytes32 uniqueEntity)
Increment and get an entity nonce.
#
UniqueEntity
#
getSchema
function getSchema() internal pure returns (Schema)
Get the table's schema
#
getKeySchema
function getKeySchema() internal pure returns (Schema)
#
getMetadata
function getMetadata() internal pure returns (string, string[])
Get the table's metadata
#
registerSchema
function registerSchema(bytes32 _tableId) internal
Register the table's schema
#
registerSchema
function registerSchema(contract IStore _store, bytes32 _tableId) internal
Register the table's schema (using the specified store)
#
setMetadata
function setMetadata(bytes32 _tableId) internal
Set the table's metadata
#
setMetadata
function setMetadata(contract IStore _store, bytes32 _tableId) internal
Set the table's metadata (using the specified store)
#
get
function get(bytes32 _tableId) internal view returns (uint256 value)
Get value
#
get
function get(contract IStore _store, bytes32 _tableId) internal view returns (uint256 value)
Get value (using the specified store)
#
set
function set(bytes32 _tableId, uint256 value) internal
Set value
#
set
function set(contract IStore _store, bytes32 _tableId, uint256 value) internal
Set value (using the specified store)
#
encode
function encode(uint256 value) internal view returns (bytes)
Tightly pack full data using this table's schema
#
deleteRecord
function deleteRecord(bytes32 _tableId) internal
#
deleteRecord
function deleteRecord(contract IStore _store, bytes32 _tableId) internal
#
ArrayLib
#
includes
function includes(bytes32[] arr, bytes32 element) internal pure returns (bool)
#
filter
function filter(bytes32[] arr, bytes32 element) internal pure returns (bytes32[])
#
freeFunction
freeFunction getTargetTableSelector(bytes8 moduleNamespace, bytes32 sourceTableId) internal pure returns (bytes32)
Get a deterministic selector for the reverse mapping table for the given source table. The selector is constructed as follows:
- The first 8 bytes are the module namespace
- The next 8 bytes are the first 8 bytes of the source table namespace -- This is to avoid collisions between tables with the same name in different namespaces (Note that collisions are still possible if the first 8 bytes of the namespace are the same, in which case installing the module fails)
- The last 16 bytes are the source table name
#
_tableId
bytes32 _tableId
#
InstalledModulesTableId
bytes32 InstalledModulesTableId
#
InstalledModulesData
struct InstalledModulesData {
address moduleAddress;
}
#
InstalledModules
#
getSchema
function getSchema() internal pure returns (Schema)
Get the table's schema
#
getKeySchema
function getKeySchema() internal pure returns (Schema)
#
getMetadata
function getMetadata() internal pure returns (string, string[])
Get the table's metadata
#
registerSchema
function registerSchema() internal
Register the table's schema
#
registerSchema
function registerSchema(contract IStore _store) internal
Register the table's schema (using the specified store)
#
setMetadata
function setMetadata() internal
Set the table's metadata
#
setMetadata
function setMetadata(contract IStore _store) internal
Set the table's metadata (using the specified store)
#
getModuleAddress
function getModuleAddress(bytes16 moduleName, bytes32 argumentsHash) internal view returns (address moduleAddress)
Get moduleAddress
#
getModuleAddress
function getModuleAddress(contract IStore _store, bytes16 moduleName, bytes32 argumentsHash) internal view returns (address moduleAddress)
Get moduleAddress (using the specified store)
#
setModuleAddress
function setModuleAddress(bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal
Set moduleAddress
#
setModuleAddress
function setModuleAddress(contract IStore _store, bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal
Set moduleAddress (using the specified store)
#
get
function get(bytes16 moduleName, bytes32 argumentsHash) internal view returns (struct InstalledModulesData _table)
Get the full data
#
get
function get(contract IStore _store, bytes16 moduleName, bytes32 argumentsHash) internal view returns (struct InstalledModulesData _table)
Get the full data (using the specified store)
#
set
function set(bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal
Set the full data using individual values
#
set
function set(contract IStore _store, bytes16 moduleName, bytes32 argumentsHash, address moduleAddress) internal
Set the full data using individual values (using the specified store)
#
set
function set(bytes16 moduleName, bytes32 argumentsHash, struct InstalledModulesData _table) internal
Set the full data using the data struct
#
set
function set(contract IStore _store, bytes16 moduleName, bytes32 argumentsHash, struct InstalledModulesData _table) internal
Set the full data using the data struct (using the specified store)
#
decode
function decode(bytes _blob) internal pure returns (struct InstalledModulesData _table)
Decode the tightly packed blob using this table's schema
#
encode
function encode(address moduleAddress) internal view returns (bytes)
Tightly pack full data using this table's schema
#
deleteRecord
function deleteRecord(bytes16 moduleName, bytes32 argumentsHash) internal
#
deleteRecord
function deleteRecord(contract IStore _store, bytes16 moduleName, bytes32 argumentsHash) internal
#
_tableId
bytes32 _tableId
#
NamespaceOwnerTableId
bytes32 NamespaceOwnerTableId
#
NamespaceOwner
#
getSchema
function getSchema() internal pure returns (Schema)
Get the table's schema
#
getKeySchema
function getKeySchema() internal pure returns (Schema)
#
getMetadata
function getMetadata() internal pure returns (string, string[])
Get the table's metadata
#
registerSchema
function registerSchema() internal
Register the table's schema
#
registerSchema
function registerSchema(contract IStore _store) internal
Register the table's schema (using the specified store)
#
setMetadata
function setMetadata() internal
Set the table's metadata
#
setMetadata
function setMetadata(contract IStore _store) internal
Set the table's metadata (using the specified store)
#
get
function get(bytes16 namespace) internal view returns (address owner)
Get owner
#
get
function get(contract IStore _store, bytes16 namespace) internal view returns (address owner)
Get owner (using the specified store)
#
set
function set(bytes16 namespace, address owner) internal
Set owner
#
set
function set(contract IStore _store, bytes16 namespace, address owner) internal
Set owner (using the specified store)
#
encode
function encode(address owner) internal view returns (bytes)
Tightly pack full data using this table's schema
#
deleteRecord
function deleteRecord(bytes16 namespace) internal
#
deleteRecord
function deleteRecord(contract IStore _store, bytes16 namespace) internal
#
_tableId
bytes32 _tableId
#
ResourceAccessTableId
bytes32 ResourceAccessTableId
#
ResourceAccess
#
getSchema
function getSchema() internal pure returns (Schema)
Get the table's schema
#
getKeySchema
function getKeySchema() internal pure returns (Schema)
#
getMetadata
function getMetadata() internal pure returns (string, string[])
Get the table's metadata
#
registerSchema
function registerSchema() internal
Register the table's schema
#
registerSchema
function registerSchema(contract IStore _store) internal
Register the table's schema (using the specified store)
#
setMetadata
function setMetadata() internal
Set the table's metadata
#
setMetadata
function setMetadata(contract IStore _store) internal
Set the table's metadata (using the specified store)
#
get
function get(bytes32 resourceSelector, address caller) internal view returns (bool access)
Get access
#
get
function get(contract IStore _store, bytes32 resourceSelector, address caller) internal view returns (bool access)
Get access (using the specified store)
#
set
function set(bytes32 resourceSelector, address caller, bool access) internal
Set access
#
set
function set(contract IStore _store, bytes32 resourceSelector, address caller, bool access) internal
Set access (using the specified store)
#
encode
function encode(bool access) internal view returns (bytes)
Tightly pack full data using this table's schema
#
deleteRecord
function deleteRecord(bytes32 resourceSelector, address caller) internal
#
deleteRecord
function deleteRecord(contract IStore _store, bytes32 resourceSelector, address caller) internal
#
freeFunction
freeFunction _toBool(uint8 value) internal pure returns (bool result)