Skip to content

Commit

Permalink
Run actions
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Jan 9, 2025
1 parent 161bb62 commit 8c336d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
13 changes: 11 additions & 2 deletions contracts/schain/ExecutionLayer/ExecutionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
});
}

function getExecutorAddress(ExecutorId id) external view returns (Executor executor) {
function getExecutor(ExecutorId id) public view returns (Executor executor) {
return Executor(_executors.get(ExecutorId.unwrap(id)));
}

Expand Down Expand Up @@ -293,6 +293,14 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
returns (TokenInfo[] memory resultTokens)
{
console.log("_executeActions");
Protocol.Action[] memory actions = Protocol.decodeActions(metaAction.metaAction.actions);
TokenInfo[] memory currentTokens = tokens;
for (uint256 i = 0; i < actions.length; ++i) {
Executor executor = getExecutor(actions[i].executor);
// TODO: add gas limit guard
currentTokens = executor.execute(currentTokens, actions[i].arguments);
}
resultTokens = currentTokens;
}

function _postExecuteMetaAction(MetaActionContainer storage metaAction) private {
Expand All @@ -302,7 +310,8 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
function _sendNextMetaAction(MetaActionContainer storage metaAction, TokenInfo[] memory tokens) private {
console.log("_sendNextMetaAction");
if (metaAction.metaAction.hasNextMetaAction()) {
console.log("has next");
console.log("tokens length");
console.log(tokens.length);
Protocol.MetaAction memory nextMetaAction = Protocol.decodeMetaAction(metaAction.metaAction.nextMetaAction);
SchainHash targetChainHash = nextMetaAction.targetChainHash;
address remoteExecutionManagerAddress = address(_getRemoteExecutionManager(targetChainHash));
Expand Down
10 changes: 9 additions & 1 deletion contracts/schain/ExecutionLayer/Protocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ library Protocol {
}

function decodeActions(bytes memory encodedActions) internal pure returns (Action[] memory actions) {
console.log("decodeActions");
console.log(encodedActions.length);
if (encodedActions.length == 0) {
return new Action[](0);
}
return abi.decode(encodedActions, (Action[]));
}

Expand All @@ -110,7 +115,7 @@ library Protocol {
version: VERSION,
messageType: MessageType.META_ACTION,
metaActionId: id,
payload: abi.encode(encodeMetaAction(metaAction), tokens)
payload: abi.encode(metaAction, tokens)
}));
}

Expand All @@ -121,12 +126,15 @@ library Protocol {
pure
returns (MetaAction memory metaAction, TokenInfo[] memory tokens)
{
console.log("decodeMetaActionMessage");
if (message.version != VERSION) {
revert IncompatibleVersion(message.version);
}
console.log("Version checked");
if (message.messageType != MessageType.META_ACTION) {
revert IncorrectMessageType(message.messageType, MessageType.META_ACTION);
}
console.log("Message type checked");
return abi.decode(message.payload, (MetaAction, TokenInfo[]));
}

Expand Down
2 changes: 1 addition & 1 deletion test/ExecutionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe("ExecutionManager", () => {

const send = await ethers.getContractAt(
"Send",
await sourceExecutionManager.getExecutorAddress(
await sourceExecutionManager.getExecutor(
ethers.id("Send")
)
);
Expand Down

0 comments on commit 8c336d9

Please sign in to comment.