Skip to content

Instantly share code, notes, and snippets.

@ocb013
Created November 6, 2023 04:09
Show Gist options
  • Save ocb013/4f964924e238fc5e6034d70191219e48 to your computer and use it in GitHub Desktop.
Save ocb013/4f964924e238fc5e6034d70191219e48 to your computer and use it in GitHub Desktop.
Фабрика записей 1
// 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 RecordFactory {
Record[] records;
function addRecord(string memory _record) public {
StringRecord newRecord = new StringRecord();
newRecord.setRecord(_record);
records.push(newRecord);
}
function addRecord(address _record) public {
AddressRecord newRecord = new AddressRecord();
newRecord.setRecord(_record);
records.push(newRecord);
}
function getTime(uint _idx) public view returns(string memory) {
return records[_idx].getRecordType();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment