Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
Created July 4, 2022 14:09
Show Gist options
  • Save PaulRBerg/c3a51e1f33255204aa70867ab46e6123 to your computer and use it in GitHub Desktop.
Save PaulRBerg/c3a51e1f33255204aa70867ab46e6123 to your computer and use it in GitHub Desktop.
Dummy contract to access a struct member
// 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