Skip to content

Commit

Permalink
onlyGateway
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 4, 2024
1 parent e959412 commit c01dac3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions examples/token/contracts/Connected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ contract Connected is ERC20, Ownable {
GatewayEVM public immutable gateway;
address public counterparty;

modifier onlyGateway() {
require(msg.sender == address(gateway), "Caller is not the gateway");
_;
}

function setCounterparty(address contractAddress) external onlyOwner {
counterparty = contractAddress;
}
Expand Down Expand Up @@ -55,7 +60,7 @@ contract Connected is ERC20, Ownable {
function onCall(
MessageContext calldata messageContext,
bytes calldata message
) external payable returns (bytes4) {
) external payable onlyGateway returns (bytes4) {
if (messageContext.sender != counterparty) revert("Unauthorized");
(address receiver, uint256 amount) = abi.decode(
message,
Expand All @@ -64,7 +69,7 @@ contract Connected is ERC20, Ownable {
_mint(receiver, amount);
}

function onRevert(RevertContext calldata context) external {}
function onRevert(RevertContext calldata context) external onlyGateway {}

receive() external payable {}

Expand Down
9 changes: 7 additions & 2 deletions examples/token/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ contract Universal is ERC20, Ownable, UniversalContract {

event CounterpartySet(address indexed zrc20, bytes indexed contractAddress);

modifier onlyGateway() {
require(msg.sender == address(gateway), "Caller is not the gateway");
_;
}

constructor(
address payable gatewayAddress,
address initialOwner
Expand Down Expand Up @@ -81,7 +86,7 @@ contract Universal is ERC20, Ownable, UniversalContract {
address zrc20,
uint256 amount,
bytes calldata message
) external override {
) external override onlyGateway {
if (keccak256(messageContext.origin) != keccak256(counterparty[zrc20]))
revert("Unauthorized");
(address receiver, uint256 tokenAmount, address destination) = abi
Expand Down Expand Up @@ -110,5 +115,5 @@ contract Universal is ERC20, Ownable, UniversalContract {
}
}

function onRevert(RevertContext calldata context) external {}
function onRevert(RevertContext calldata context) external onlyGateway {}
}

0 comments on commit c01dac3

Please sign in to comment.