-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
Co-authored-by: alvarius <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
"@latticexyz/world": minor | ||
--- | ||
|
||
The `World` now has a `callBatch` method which allows multiple system calls to be batched into a single transaction. | ||
|
||
```solidity | ||
import { SystemCallData } from "@latticexyz/world/modules/core/types.sol"; | ||
interface IBaseWorld { | ||
function callBatch(SystemCallData[] calldata systemCalls) external returns (bytes[] memory returnDatas); | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.21; | ||
|
||
/* Autogenerated file. Do not edit manually. */ | ||
|
||
import { SystemCallData } from "./../modules/core/types.sol"; | ||
|
||
interface ICallBatchSystem { | ||
function callBatch(SystemCallData[] calldata systemCalls) external returns (bytes[] memory returnDatas); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
import { System } from "../../../System.sol"; | ||
import { IBaseWorld } from "../../../interfaces/IBaseWorld.sol"; | ||
import { revertWithBytes } from "../../../revertWithBytes.sol"; | ||
|
||
import { SystemCallData } from "../types.sol"; | ||
|
||
contract CallBatchSystem is System { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
alvrs
Author
Member
|
||
/** | ||
* Batch calls to multiple systems into a single transaction, return the array of return data. | ||
*/ | ||
function callBatch(SystemCallData[] calldata systemCalls) public returns (bytes[] memory returnDatas) { | ||
IBaseWorld world = IBaseWorld(_world()); | ||
returnDatas = new bytes[](systemCalls.length); | ||
|
||
for (uint256 i; i < systemCalls.length; i++) { | ||
(bool success, bytes memory returnData) = address(world).delegatecall( | ||
abi.encodeCall(world.call, (systemCalls[i].systemId, systemCalls[i].callData)) | ||
); | ||
if (!success) revertWithBytes(returnData); | ||
|
||
returnDatas[i] = abi.decode(returnData, (bytes)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
alvrs
Author
Member
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.21; | ||
|
||
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||
|
||
struct SystemCallData { | ||
ResourceId systemId; | ||
bytes callData; | ||
} |
I still liked
BatchCallSystem
andbatchCall
🙈