Created
October 28, 2022 18:22
-
-
Save jboetticher/f85dd837ca4a4845357a375f2495fa91 to your computer and use it in GitHub Desktop.
Hyperlane SimpleGeneralMessage
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
// SPDX-License-Identifier: Apache-2.0 | |
pragma solidity ^0.8.13; | |
// ============ External Imports ============ | |
import {Router} from "@hyperlane-xyxz/app/contracts/Router.sol"; | |
contract SimpleGeneralMessage is Router { | |
mapping(address => string) public lastMessage; | |
constructor( | |
address _abacusConnectionManager, | |
address _interchainGasPaymaster | |
) { | |
// Transfer ownership of the contract to deployer | |
_transferOwnership(msg.sender); | |
// Set the addresses for the ACM and IGP | |
// Alternatively, this could be done later in an initialize method | |
_setAbacusConnectionManager(_abacusConnectionManager); | |
_setInterchainGasPaymaster(_interchainGasPaymaster); | |
} | |
// ============ External functions ============ | |
/** | |
* @notice Sends a message to the _destinationDomain. Any msg.value is | |
* used as interchain gas payment. | |
* @param _destinationDomain The destination domain to send the message to. | |
*/ | |
function sendMessage(uint32 _destinationDomain, string calldata message) | |
external | |
payable | |
{ | |
bytes memory payload = abi.encode(msg.sender, message); | |
_dispatchWithGas(_destinationDomain, payload, msg.value); | |
} | |
// ============ Internal functions ============ | |
/** | |
* @notice Handles a message from a remote router. | |
* @dev Only called for messages sent from a remote router, as enforced by Router.sol. | |
* @param _message The message body. | |
*/ | |
function _handle( | |
uint32, | |
bytes32, | |
bytes calldata _message | |
) internal override { | |
// Do some checks if you want | |
(address from, string memory message) = abi.decode(_message, (address, string)); | |
lastMessage[from] = message; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment