The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hyperlane-monorepo/solidity/contracts/hooks/ConfigFallbackDomainRouting...

56 lines
1.6 KiB

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/
import {Message} from "../libs/Message.sol";
import {IPostDispatchHook} from "../interfaces/hooks/IPostDispatchHook.sol";
import {IMailbox} from "../interfaces/IMailbox.sol";
contract ConfigFallbackDomainRoutingHook is IPostDispatchHook {
using Message for bytes;
IMailbox public immutable mailbox;
/// @notice message sender => destination => recipient => hook
mapping(address => mapping(uint32 => mapping(bytes32 => IPostDispatchHook)))
public customHooks;
constructor(address _mailbox) {
mailbox = IMailbox(_mailbox);
}
function postDispatch(bytes calldata metadata, bytes calldata message)
public
payable
override
{
IPostDispatchHook configuredHook = customHooks[message.senderAddress()][
message.destination()
][message.recipient()];
if (address(configuredHook) == address(0)) {
configuredHook = mailbox.defaultHook();
}
configuredHook.postDispatch{value: msg.value}(metadata, message);
}
function setHook(
uint32 destinationDomain,
bytes32 recipient,
IPostDispatchHook hook
) external {
customHooks[msg.sender][destinationDomain][recipient] = hook;
}
}