CrossChainEnabled.sol 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.6.0) (crosschain/CrossChainEnabled.sol)
  3. pragma solidity ^0.8.4;
  4. import "./errors.sol";
  5. /**
  6. * @dev Provides information for building cross-chain aware contracts. This
  7. * abstract contract provides accessors and modifiers to control the execution
  8. * flow when receiving cross-chain messages.
  9. *
  10. * Actual implementations of cross-chain aware contracts, which are based on
  11. * this abstraction, will have to inherit from a bridge-specific
  12. * specialization. Such specializations are provided under
  13. * `crosschain/<chain>/CrossChainEnabled<chain>.sol`.
  14. *
  15. * _Available since v4.6._
  16. */
  17. abstract contract CrossChainEnabled {
  18. /**
  19. * @dev Throws if the current function call is not the result of a
  20. * cross-chain execution.
  21. */
  22. modifier onlyCrossChain() {
  23. if (!_isCrossChain()) revert NotCrossChainCall();
  24. _;
  25. }
  26. /**
  27. * @dev Throws if the current function call is not the result of a
  28. * cross-chain execution initiated by `account`.
  29. */
  30. modifier onlyCrossChainSender(address expected) {
  31. address actual = _crossChainSender();
  32. if (expected != actual) revert InvalidCrossChainSender(actual, expected);
  33. _;
  34. }
  35. /**
  36. * @dev Returns whether the current function call is the result of a
  37. * cross-chain message.
  38. */
  39. function _isCrossChain() internal view virtual returns (bool);
  40. /**
  41. * @dev Returns the address of the sender of the cross-chain message that
  42. * triggered the current function call.
  43. *
  44. * IMPORTANT: Should revert with `NotCrossChainCall` if the current function
  45. * call is not the result of a cross-chain message.
  46. */
  47. function _crossChainSender() internal view virtual returns (address);
  48. }