-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(world): add
batchCallFrom
(#1594)
- Loading branch information
Showing
14 changed files
with
301 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
"@latticexyz/world": major | ||
--- | ||
|
||
- `IBaseWorld` now has a `batchCallFrom` method, which allows system calls via `callFrom` to be executed in batch. | ||
|
||
```solidity | ||
import { SystemCallFromData } from "@latticexyz/world/modules/core/types.sol"; | ||
interface IBaseWorld { | ||
function batchCallFrom(SystemCallFromData[] calldata systemCalls) external returns (bytes[] memory returnDatas); | ||
} | ||
``` | ||
|
||
- The `callBatch` method of `IBaseWorld` has been renamed to `batchCall` to align better with the `batchCallFrom` method. | ||
|
||
```diff | ||
interface IBaseWorld { | ||
- function callBatch(SystemCallData[] calldata systemCalls) external returns (bytes[] memory returnDatas); | ||
+ function batchCall(SystemCallData[] calldata systemCalls) external returns (bytes[] memory returnDatas); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
packages/world/src/codegen/interfaces/IBatchCallSystem.sol
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages/world/src/codegen/interfaces/ICallBatchSystem.sol
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/world/src/modules/core/implementations/BatchCallSystem.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
import { System } from "../../../System.sol"; | ||
import { IBaseWorld } from "../../../codegen/interfaces/IBaseWorld.sol"; | ||
import { revertWithBytes } from "../../../revertWithBytes.sol"; | ||
|
||
import { SystemCallData, SystemCallFromData } from "../types.sol"; | ||
|
||
contract BatchCallSystem is System { | ||
/** | ||
* Batch calls to multiple systems into a single transaction, return the array of return data. | ||
*/ | ||
function batchCall(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)); | ||
} | ||
} | ||
|
||
/** | ||
* Batch calls to multiple systems into a single transaction, return the array of return data. | ||
*/ | ||
function batchCallFrom(SystemCallFromData[] 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.callFrom, (systemCalls[i].from, systemCalls[i].systemId, systemCalls[i].callData)) | ||
); | ||
if (!success) revertWithBytes(returnData); | ||
|
||
returnDatas[i] = abi.decode(returnData, (bytes)); | ||
} | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
packages/world/src/modules/core/implementations/CallBatchSystem.sol
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.