receiver.sol 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: UNLICENSED
  2. pragma solidity ^0.8.0;
  3. contract receiver {
  4. address public endpoint;
  5. mapping(uint16 => bytes) public trustedRemoteLookup;
  6. address public owner;
  7. event done(address from);
  8. constructor(address _endpoint) {
  9. owner = msg.sender;
  10. endpoint = _endpoint;
  11. }
  12. modifier onlyOwner() {
  13. require(owner == msg.sender, "not owner");
  14. _;
  15. }
  16. function setEndpoint(address _endpoint) external onlyOwner {
  17. endpoint = _endpoint;
  18. }
  19. function setTrustRemoteLookup(uint16 _chainId, bytes memory _address) external onlyOwner {
  20. trustedRemoteLookup[_chainId] = _address;
  21. }
  22. function lzReceive(
  23. uint16 _srcChainId,
  24. bytes memory _srcAddress,
  25. uint64 _nonce,
  26. bytes memory _payload
  27. ) external payable{
  28. require(msg.sender == address(endpoint));
  29. require(keccak256(_srcAddress) == keccak256(trustedRemoteLookup[_srcChainId]));
  30. address fromAddress;
  31. assembly {
  32. fromAddress := mload(add(_srcAddress, 20))
  33. }
  34. emit done(fromAddress);
  35. }
  36. }