Created
July 4, 2022 14:09
-
-
Save PaulRBerg/c3a51e1f33255204aa70867ab46e6123 to your computer and use it in GitHub Desktop.
Dummy contract to access a struct member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity >=0.8.15; | |
contract StructMemberGetter { | |
error NotAuthorized(address caller); | |
struct MyStruct { | |
address owner; | |
} | |
mapping(uint256 => MyStruct) internal myStructs; | |
modifier onlyOwner(uint256 id) { | |
if (myStructs[id].owner != msg.sender) { | |
revert NotAuthorized(msg.sender); | |
} | |
_; | |
} | |
constructor(uint256 id) { | |
myStructs[id] = MyStruct({ owner: msg.sender }); | |
} | |
function getOwner(uint256 id) public view returns (address theOwner) { | |
theOwner = myStructs[id].owner; | |
} | |
function getBlockTimestamp(uint256 id) onlyOwner(id) external view returns (uint256 timestamp) { | |
timestamp = block.timestamp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment