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/routing/FallbackDomainRoutingHook.sol

52 lines
1.5 KiB

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/
import {IPostDispatchHook} from "../../interfaces/hooks/IPostDispatchHook.sol";
import {IMailbox} from "../../interfaces/IMailbox.sol";
import {DomainRoutingHook} from "./DomainRoutingHook.sol";
import {Message} from "../../libs/Message.sol";
/**
* @title FallbackDomainRoutingHook
* @notice Delegates to a hook based on the destination domain of the message.
* If no hook is configured for the destination domain, delegates to a fallback hook.
*/
contract FallbackDomainRoutingHook is DomainRoutingHook {
using Message for bytes;
IPostDispatchHook public immutable fallbackHook;
constructor(
address _mailbox,
address _owner,
address _fallback
) DomainRoutingHook(_mailbox, _owner) {
fallbackHook = IPostDispatchHook(_fallback);
}
// ============ Internal Functions ============
function _getConfiguredHook(bytes calldata message)
internal
view
override
returns (IPostDispatchHook hook)
{
hook = hooks[message.destination()];
if (address(hook) == address(0)) {
hook = fallbackHook;
}
}
}