Created
November 6, 2023 05:22
-
-
Save ocb013/64792dddebfff61990394ff712376f1e to your computer and use it in GitHub Desktop.
Фабрика записей 2
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: GPL-3.0 | |
pragma solidity ^0.8.0; | |
abstract contract Record { | |
uint public timeOfCreation; | |
function getRecordType() public virtual pure returns(string memory); | |
constructor() { | |
timeOfCreation = block.timestamp; | |
} | |
} | |
contract AddressRecord is Record{ | |
address public record; | |
function getRecordType() public pure override returns(string memory) { | |
return "address"; | |
} | |
function setRecord(address _record) public { | |
record = _record; | |
} | |
} | |
contract StringRecord is Record{ | |
string public record; | |
function getRecordType() public pure override returns(string memory) { | |
return "string"; | |
} | |
function setRecord(string memory _record) public { | |
record = _record; | |
} | |
} | |
contract EnsRecord is Record{ | |
string public domain; | |
address public owner; | |
function getRecordType() public pure override returns(string memory) { | |
return "ens"; | |
} | |
function setOwner(address _owner) public { | |
owner = _owner; | |
} | |
} | |
contract EnsFactory { | |
RecordStorage internal recordStorage; | |
constructor(address _recordStorage) { | |
recordStorage = RecordStorage(_recordStorage); | |
} | |
function addRecord(address _owner) public { | |
EnsRecord newRecord = new EnsRecord(); | |
newRecord.setOwner(_owner); | |
recordStorage.addRecord(newRecord); | |
} | |
} | |
contract AddressFactory { | |
RecordStorage internal recordStorage; | |
constructor(address _recordStorage) { | |
recordStorage = RecordStorage(_recordStorage); | |
} | |
function addRecord(address _record) public { | |
AddressRecord newRecord = new AddressRecord(); | |
newRecord.setRecord(_record); | |
recordStorage.addRecord(newRecord); | |
} | |
} | |
contract StringFactory { | |
RecordStorage internal recordStorage; | |
constructor(address _recordStorage) { | |
recordStorage = RecordStorage(_recordStorage); | |
} | |
function addRecord(string memory _record) public { | |
StringRecord newRecord = new StringRecord(); | |
newRecord.setRecord(_record); | |
recordStorage.addRecord(newRecord); | |
} | |
} | |
contract RecordStorage { | |
address internal owner; | |
constructor() { | |
owner = msg.sender; | |
} | |
modifier onlyOnwer() { | |
require(owner == msg.sender, "Not an owner!"); | |
_; | |
} | |
Record[] records; | |
mapping(address => bool) factories; | |
function addFactory(address _addr) public onlyOnwer { | |
factories[_addr] = true; | |
} | |
function addRecord(Record record) external { | |
require(factories[msg.sender], "Not allowed!"); | |
records.push(record); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment