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/test/TestQuery.sol

41 lines
1.5 KiB

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;
import {InterchainQueryRouter} from "../middleware/InterchainQueryRouter.sol";
import {TypeCasts} from "../libs/TypeCasts.sol";
import {CallLib} from "../middleware/libs/Call.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
contract TestQuery {
InterchainQueryRouter public router;
event Owner(uint256, address);
constructor(address _router) {
router = InterchainQueryRouter(_router);
}
/**
* @dev Fetches owner of InterchainQueryRouter on provided domain and passes along with provided secret to `this.receiveRouterOwner`
*/
function queryRouterOwner(uint32 domain, uint256 secret) external {
address target = TypeCasts.bytes32ToAddress(router.routers(domain));
CallLib.StaticCallWithCallback[]
memory calls = new CallLib.StaticCallWithCallback[](1);
calls[0] = CallLib.build(
target,
abi.encodeWithSelector(Ownable.owner.selector),
abi.encodeWithSelector(this.receiveRouterOwner.selector, secret)
);
router.query(domain, calls);
}
/**
* @dev `msg.sender` must be restricted to `this.router` to prevent any local account from spoofing query data.
*/
function receiveRouterOwner(uint256 secret, address owner) external {
require(msg.sender == address(router), "TestQuery: not from router");
emit Owner(secret, owner);
}
}