WorldContextConsumer
Git Source (opens in a new tab)
Inherits: IWorldContextConsumer
This contract is designed to extract trusted context values (like msg.sender and msg.value) from the appended calldata. It provides mechanisms similar to EIP-2771 (https://eips.ethereum.org/EIPS/eip-2771 (opens in a new tab)), but allowing any contract to be the trusted forwarder.
This contract should only be used for contracts without their own storage, like Systems.
Functions
_msgSender
Extract the msg.sender
from the context appended to the calldata.
function _msgSender() public view returns (address sender);
Returns
Name | Type | Description |
---|---|---|
sender | address | The msg.sender in the call to the World contract before the World routed the call to the WorldContextConsumer contract. |
_msgValue
Extract the msg.value
from the context appended to the calldata.
function _msgValue() public pure returns (uint256 value);
Returns
Name | Type | Description |
---|---|---|
value | uint256 | The msg.value in the call to the World contract before the World routed the call to the WorldContextConsumer contract. |
_world
Get the address of the World contract that routed the call to this WorldContextConsumer.
function _world() public view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the World contract that routed the call to this WorldContextConsumer. |
supportsInterface
Checks if an interface is supported by the contract. using ERC-165 supportsInterface (see https://eips.ethereum.org/EIPS/eip-165 (opens in a new tab))
function supportsInterface(bytes4 interfaceId) public pure virtual returns (bool);
Parameters
Name | Type | Description |
---|---|---|
interfaceId | bytes4 | The ID of the interface in question. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if the interface is supported, false otherwise. |
WorldContext.sol constants
Git Source (opens in a new tab)
CONTEXT_BYTES
uint256 constant CONTEXT_BYTES = 20 + 32;
WorldContextConsumerLib
Git Source (opens in a new tab)
Helpers for working with data in the context of calling a World
Functions
_msgSender
Extract the msg.sender
from the context appended to the calldata.
function _msgSender() internal view returns (address sender);
Returns
Name | Type | Description |
---|---|---|
sender | address | The msg.sender in the call to the World contract before the World routed the call to the WorldContextConsumer contract. |
_msgValue
Extract the msg.value
from the context appended to the calldata.
function _msgValue() internal pure returns (uint256 value);
Returns
Name | Type | Description |
---|---|---|
value | uint256 | The msg.value in the call to the World contract before the World routed the call to the WorldContextConsumer contract. |
_world
Get the address of the World contract that routed the call to this WorldContextConsumer.
function _world() internal view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the World contract that routed the call to this WorldContextConsumer. |
WorldContextProviderLib
Git Source (opens in a new tab)
This library provides functions to make calls or delegatecalls to other contracts, appending the context values (like msg.sender and msg.value) to the calldata for WorldContextConsumer to consume.
Functions
appendContext
Appends context values to the given calldata.
function appendContext(bytes memory callData, address msgSender, uint256 msgValue) internal pure returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
callData | bytes | The original calldata. |
msgSender | address | The address of the transaction sender. |
msgValue | uint256 | The amount of ether sent with the original transaction. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | The new calldata with context values appended. |
callWithContext
Makes a call to the target contract with context values appended to the calldata.
function callWithContext(
address msgSender,
uint256 msgValue,
address target,
bytes memory callData
) internal returns (bool success, bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
msgSender | address | The address of the transaction sender. |
msgValue | uint256 | The amount of ether sent with the original transaction. |
target | address | The address of the contract to call. |
callData | bytes | The calldata for the call. |
Returns
Name | Type | Description |
---|---|---|
success | bool | A boolean indicating whether the call was successful or not. |
data | bytes | The abi encoded return data from the call. |
staticcallWithContext
Makes a staticcall to the target contract with context values appended to the calldata.
function staticcallWithContext(
address msgSender,
address target,
bytes memory callData
) internal view returns (bool success, bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
msgSender | address | The address of the transaction sender. |
target | address | The address of the contract to call. |
callData | bytes | The calldata for the staticcall. |
Returns
Name | Type | Description |
---|---|---|
success | bool | A boolean indicating whether the staticcall was successful or not. |
data | bytes | The abi encoded return data from the staticcall. |
delegatecallWithContext
Makes a delegatecall to the target contract with context values appended to the calldata.
function delegatecallWithContext(
address msgSender,
uint256 msgValue,
address target,
bytes memory callData
) internal returns (bool success, bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
msgSender | address | The address of the transaction sender. |
msgValue | uint256 | The amount of ether sent with the original transaction. |
target | address | The address of the contract to call. |
callData | bytes | The calldata for the call. |
Returns
Name | Type | Description |
---|---|---|
success | bool | A boolean indicating whether the call was successful or not. |
data | bytes | The abi encoded return data from the call. |
callWithContextOrRevert
Makes a call to the target contract with context values appended to the calldata.
Revert in the case of failure.
function callWithContextOrRevert(
address msgSender,
uint256 msgValue,
address target,
bytes memory callData
) internal returns (bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
msgSender | address | The address of the transaction sender. |
msgValue | uint256 | The amount of ether sent with the original transaction. |
target | address | The address of the contract to call. |
callData | bytes | The calldata for the call. |
Returns
Name | Type | Description |
---|---|---|
data | bytes | The abi encoded return data from the call. |
delegatecallWithContextOrRevert
Makes a delegatecall to the target contract with context values appended to the calldata.
Revert in the case of failure.
function delegatecallWithContextOrRevert(
address msgSender,
uint256 msgValue,
address target,
bytes memory callData
) internal returns (bytes memory data);
Parameters
Name | Type | Description |
---|---|---|
msgSender | address | The address of the transaction sender. |
msgValue | uint256 | The amount of ether sent with the original transaction. |
target | address | The address of the contract to call. |
callData | bytes | The calldata for the call. |
Returns
Name | Type | Description |
---|---|---|
data | bytes | The abi encoded return data from the call. |