Last active
September 25, 2024 14:14
-
-
Save AntonVoronezh/8aa4ce017ddb6ac0a3e3c4a60fe4ac85 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.22+commit.4fc1097e.js&optimize=false&runs=200&gist=
This file contains 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: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract Record { | |
uint256 public timeOfCreation; | |
constructor() { | |
timeOfCreation = block.timestamp; | |
} | |
} | |
contract StringRecord is Record { | |
string public record; | |
function getRecordType() public pure returns(string memory) { | |
return "string"; | |
} | |
function setRecord(string memory _record) public { | |
record = _record; | |
} | |
} | |
contract AddressRecord is Record { | |
address public record; | |
function getRecordType() public pure returns(string memory) { | |
return "address"; | |
} | |
function setRecord(address _record) public { | |
record = _record; | |
} | |
} | |
contract EnsRecord is Record { | |
string public domain; | |
address public ownner; | |
function getRecordType() public pure returns(string memory) { | |
return "ens"; | |
} | |
function setOwner(address _ownner) public { | |
ownner = _ownner; | |
} | |
} | |
contract RecordsStorage is Ownable { | |
constructor() Ownable(msg.sender) {} | |
Record[] public records; | |
mapping(address => bool) private factories; | |
function addRecord(Record _record) public { | |
require(factories[msg.sender] == true, "not"); | |
records.push(_record); | |
} | |
function addFactory(address _address) public onlyOwner { | |
factories[_address] = true; | |
} | |
} | |
abstract contract Factory { | |
RecordsStorage public addedRecord; | |
constructor(RecordsStorage _addedRecord) { | |
addedRecord = _addedRecord; | |
} | |
function onRecordAdding(Record _record) internal { | |
addedRecord.addRecord(_record); | |
} | |
} | |
contract StringRecordFactory is Factory { | |
constructor(RecordsStorage _address) Factory(_address) {} | |
function onRecordAdding() public { | |
StringRecord newRecord = new StringRecord(); | |
onRecordAdding(newRecord); | |
} | |
} | |
contract AddressRecordFactory is Factory { | |
constructor(RecordsStorage _address) Factory(_address) {} | |
function onRecordAdding() internal { | |
AddressRecord newRecord = new AddressRecord(); | |
onRecordAdding(newRecord); | |
} | |
} | |
contract EnsRecordFactory is Factory { | |
constructor(RecordsStorage _address) Factory(_address) {} | |
function onRecordAdding() internal { | |
EnsRecord newRecord = new EnsRecord(); | |
onRecordAdding(newRecord); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment