From 58c95dab4c106b1c063b2cfad181eee6a32deb47 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 20 Nov 2024 17:53:13 +0300 Subject: [PATCH] refactor --- examples/router/contracts/Connected.sol | 3 +++ examples/router/contracts/Universal.sol | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/router/contracts/Connected.sol b/examples/router/contracts/Connected.sol index f51eee72..c365e81e 100644 --- a/examples/router/contracts/Connected.sol +++ b/examples/router/contracts/Connected.sol @@ -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 { diff --git a/examples/router/contracts/Universal.sol b/examples/router/contracts/Universal.sol index 9e20b1bf..062a0367 100644 --- a/examples/router/contracts/Universal.sol +++ b/examples/router/contracts/Universal.sol @@ -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, @@ -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"); @@ -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) ); }