Update docs
This commit is contained in:
36
contracts/crosschain/optimism/LibOptimism.sol
Normal file
36
contracts/crosschain/optimism/LibOptimism.sol
Normal file
@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.6.0) (crosschain/optimism/LibOptimism.sol)
|
||||
|
||||
pragma solidity ^0.8.4;
|
||||
|
||||
import {ICrossDomainMessenger as Optimism_Bridge} from "../../vendor/optimism/ICrossDomainMessenger.sol";
|
||||
import "../errors.sol";
|
||||
|
||||
/**
|
||||
* @dev Primitives for cross-chain aware contracts for [Optimism](https://www.optimism.io/).
|
||||
* See the [documentation](https://community.optimism.io/docs/developers/bridge/messaging/#accessing-msg-sender)
|
||||
* for the functionality used here.
|
||||
*/
|
||||
library LibOptimism {
|
||||
/**
|
||||
* @dev Returns whether the current function call is the result of a
|
||||
* cross-chain message relayed by `messenger`.
|
||||
*/
|
||||
function isCrossChain(address messenger) internal view returns (bool) {
|
||||
return msg.sender == messenger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the address of the sender that triggered the current
|
||||
* cross-chain message through `messenger`.
|
||||
*
|
||||
* NOTE: {isCrossChain} should be checked before trying to recover the
|
||||
* sender, as it will revert with `NotCrossChainCall` if the current
|
||||
* function call is not the result of a cross-chain message.
|
||||
*/
|
||||
function crossChainSender(address messenger) internal view returns (address) {
|
||||
if (!isCrossChain(messenger)) revert NotCrossChainCall();
|
||||
|
||||
return Optimism_Bridge(messenger).xDomainMessageSender();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user