World
Git Source (opens in a new tab)
Inherits: StoreKernel, IWorldKernel
This contract is the core "World" contract containing various methods for data manipulation, system calls, and dynamic function selector handling.
World doesn't inherit Store
because the IStoreRegistration
methods are added via the InitModule
.
State Variables
creator
Address of the contract's creator.
address public immutable creator;
Functions
worldVersion
function worldVersion() public pure returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The current version of the world contract. |
constructor
Event emitted when the World contract is created.
constructor();
prohibitDirectCallback
Prevents the World contract from calling itself.
If the World is able to call itself via delegatecall
from a system, the system would have root access to context like internal tables, causing a potential vulnerability.
Ideally this should not happen because all operations to internal tables happen as internal library calls, and all calls to root systems happen as a delegatecall
to the system.
However, since this is an important invariant, we make it explicit by reverting if msg.sender
is address(this)
in all World
methods.
modifier prohibitDirectCallback();
initialize
Initializes the World by installing the core module.
Only the initial creator can initialize. This can be done only once.
function initialize(IModule initModule) public prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
initModule | IModule | The core module to initialize the World with. |
installRootModule
Installs a given root module in the World.
The caller must own the root namespace.
function installRootModule(IModule module, bytes memory encodedArgs) public prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
module | IModule | The module to be installed. |
encodedArgs | bytes | The ABI encoded arguments for module installation. |
setRecord
WORLD STORE METHODS
Writes a record in the table identified by tableId
.
Requires the caller to have access to the table's namespace or name (encoded in the tableId).
function setRecord(
ResourceId tableId,
bytes32[] calldata keyTuple,
bytes calldata staticData,
EncodedLengths encodedLengths,
bytes calldata dynamicData
) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record. |
staticData | bytes | Static data (fixed length fields) of the record. |
encodedLengths | EncodedLengths | Encoded lengths of data. |
dynamicData | bytes | Dynamic data (variable length fields) of the record. |
spliceStaticData
Modifies static (fixed length) data in a record at the specified position.
function spliceStaticData(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint48 start,
bytes calldata data
) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record. |
start | uint48 | Position from where the static data modification should start. |
data | bytes | Data to splice into the static data of the record. |
spliceDynamicData
Modifies dynamic (variable length) data in a record for a specified field.
function spliceDynamicData(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
bytes calldata data
) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record. |
dynamicFieldIndex | uint8 | Index of the dynamic field to modify. |
startWithinField | uint40 | Start position within the specified dynamic field. |
deleteCount | uint40 | Number of bytes to delete starting from the startWithinField . |
data | bytes | Data to splice into the dynamic data of the field. |
setField
Writes data into a specified field in the table identified by tableId
.
function setField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 fieldIndex,
bytes calldata data
) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record. |
fieldIndex | uint8 | Index of the field to modify. |
data | bytes | Data to write into the specified field. |
setField
Writes data into a specified field in the table, adhering to a specific layout.
function setField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 fieldIndex,
bytes calldata data,
FieldLayout fieldLayout
) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record. |
fieldIndex | uint8 | Index of the field to modify. |
data | bytes | Data to write into the specified field. |
fieldLayout | FieldLayout | The layout to adhere to when modifying the field. |
setStaticField
Writes data into a static (fixed length) field in the table identified by tableId
.
Requires the caller to have access to the table's namespace or name (encoded in the tableId).
function setStaticField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 fieldIndex,
bytes calldata data,
FieldLayout fieldLayout
) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record. |
fieldIndex | uint8 | Index of the static field to modify. |
data | bytes | Data to write into the specified static field. |
fieldLayout | FieldLayout | The layout to adhere to when modifying the field. |
setDynamicField
Writes data into a dynamic (varible length) field in the table identified by tableId
.
function setDynamicField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 dynamicFieldIndex,
bytes calldata data
) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record. |
dynamicFieldIndex | uint8 | Index of the dynamic field to modify. |
data | bytes | Data to write into the specified dynamic field. |
pushToDynamicField
Appends data to the end of a dynamic (variable length) field in the table identified by tableId
.
function pushToDynamicField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 dynamicFieldIndex,
bytes calldata dataToPush
) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record. |
dynamicFieldIndex | uint8 | Index of the dynamic field to append to. |
dataToPush | bytes | Data to append to the specified dynamic field. |
popFromDynamicField
Removes a specified amount of data from the end of a dynamic (variable length) field in the table identified by tableId
.
function popFromDynamicField(
ResourceId tableId,
bytes32[] calldata keyTuple,
uint8 dynamicFieldIndex,
uint256 byteLengthToPop
) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record. |
dynamicFieldIndex | uint8 | Index of the dynamic field to remove data from. |
byteLengthToPop | uint256 | The number of bytes to remove from the end of the dynamic field. |
deleteRecord
Deletes a record from the table identified by tableId
.
Requires the caller to have access to the table's namespace or name.
function deleteRecord(ResourceId tableId, bytes32[] calldata keyTuple) public virtual prohibitDirectCallback;
Parameters
Name | Type | Description |
---|---|---|
tableId | ResourceId | The unique identifier for the table. |
keyTuple | bytes32[] | Array of keys identifying the record to delete. |
call
SYSTEM CALLS
Calls a system with a given system ID.
If system is private, caller must have appropriate access.
function call(
ResourceId systemId,
bytes memory callData
) external payable virtual prohibitDirectCallback returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
systemId | ResourceId | The ID of the system to be called. |
callData | bytes | The data for the system call. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Return data from the system call. |
callFrom
Calls a system with a given system ID on behalf of the given delegator.
If system is private, caller must have appropriate access.
function callFrom(
address delegator,
ResourceId systemId,
bytes memory callData
) external payable virtual prohibitDirectCallback returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
delegator | address | The address on whose behalf the system is called. |
systemId | ResourceId | The ID of the system to be called. |
callData | bytes | The ABI data for the system call. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Return data from the system call. |
receive
DYNAMIC FUNCTION SELECTORS
Accepts ETH and adds to the root namespace's balance.
receive() external payable;
fallback
Fallback function to call registered function selectors.
fallback() external payable prohibitDirectCallback;
WorldFactory
Git Source (opens in a new tab)
Inherits: IWorldFactory
A factory contract to deploy new World instances.
This contract allows users to deploy a new World, install the InitModule, and transfer the ownership.
State Variables
initModule
Address of the init module to be set in the World instances.
IModule public immutable initModule;
Functions
constructor
constructor(IModule _initModule);
Parameters
Name | Type | Description |
---|---|---|
_initModule | IModule | The address of the init module. |
deployWorld
Deploys a new World instance, installs the InitModule and transfers ownership to the caller.
Uses the Create2 for deterministic deployment.
function deployWorld(bytes memory salt) public returns (address worldAddress);
Parameters
Name | Type | Description |
---|---|---|
salt | bytes | User defined salt for deterministic world addresses across chains |
Returns
Name | Type | Description |
---|---|---|
worldAddress | address | The address of the newly deployed World contract. |