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/DestinationRecipientRouting...

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 {DomainRoutingHook} from "./DomainRoutingHook.sol";
contract DestinationRecipientRoutingHook is DomainRoutingHook {
using Message for bytes;
/// @notice destination => recipient =>custom hook
mapping(uint32 => mapping(bytes32 => address)) public customHooks;
constructor(
address mailbox,
address owner
) DomainRoutingHook(mailbox, owner) {}
function _postDispatch(
bytes calldata metadata,
bytes calldata message
) internal override {
address customHookPreset = customHooks[message.destination()][
message.recipient()
];
if (customHookPreset != address(0)) {
IPostDispatchHook(customHookPreset).postDispatch{value: msg.value}(
metadata,
message
);
} else {
super._postDispatch(metadata, message);
}
}
function configCustomHook(
uint32 destinationDomain,
bytes32 recipient,
address hook
) external onlyOwner {
customHooks[destinationDomain][recipient] = hook;
}
}