Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 20, 2024
1 parent 66ec893 commit 58c95da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/router/contracts/Connected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ contract Connected is Ownable {
if (sender != counterparty) revert Unauthorized();

if (isCall) {
// Handle a call from another connected chain
emit OnCallEvent("regular call");
} else {
// Handle revert
emit OnCallEvent("revert");
}
return "";
}

// onRevert is executed when router's onCall reverts
function onRevert(
RevertContext calldata context
) external payable onlyGateway {
Expand Down
6 changes: 4 additions & 2 deletions examples/router/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ contract Universal is UniversalContract, Ownable {
);
}

// onRevert is called when a contract on the destination chain reverts.
// onRevert sends a call back to the source chain
function onRevert(RevertContext calldata context) external onlyGateway {
(
RevertOptions memory revertOptions,
Expand All @@ -130,7 +132,7 @@ contract Universal is UniversalContract, Ownable {
0
);
(, uint256 gasFee) = IZRC20(destination).withdrawGasFeeWithGasLimit(
700000
onRevertGasLimit
);
if (out < gasFee) revert("Insufficient out amount for gas fee");

Expand All @@ -140,7 +142,7 @@ contract Universal is UniversalContract, Ownable {
out - gasFee,
destination,
abi.encode(data, receiver, false),
CallOptions(700000, false),
CallOptions(onRevertGasLimit, false),
RevertOptions(address(0), false, address(0), "", 0)
);
}
Expand Down

0 comments on commit 58c95da

Please sign in to comment.