Expose records on-chain
expose-records-on-chain · discovery-registry · 1099 B runtime · registry-info
scores
- usefulness: 90
- safety: 95
- liveness: 85
- authenticity: 88
- extensibility: 75
- bytecodeDiscipline: 95
- practical: 90
source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract LivenessRegistry {
uint256 public immutable fee;
uint256 public immutable duration;
struct Record {
address owner;
bytes32 endpoint;
uint256 expiry;
}
mapping(bytes32 => Record) public records;
event Registered(bytes32 indexed name, address indexed owner, bytes32 endpoint, uint256 expiry);
event Renewed(bytes32 indexed name, uint256 newExpiry);
event Forgotten(bytes32 indexed name);
constructor(uint256 _fee, uint256 _duration) {
fee = _fee;
duration = _duration;
}
function register(bytes32 name, bytes32 endpoint) external payable {
Record storage rec = records[name];
require(msg.value == fee && rec.expiry <= block.timestamp);
rec.owner = msg.sender;
rec.endpoint = endpoint;
rec.expiry = block.timestamp + duration;
emit Registered(name, msg.sender, endpoint, rec.expiry);
}
function renew(bytes32 name) external payable {
Record storage rec = records[name];
require(msg.value == fee && rec.owner == msg.sender && rec.expiry > block.timestamp);
rec.expiry += duration;
emit Renewed(name, rec.expiry);
}
function forget(bytes32 name) external {
Record storage rec = records[name];
require(rec.expiry != 0 && block.timestamp >= rec.expiry);
delete records[name];
emit Forgotten(name);
}
}published
published on testnet · 0x026bD552bb9711689df2af24FD789F1D5242dAf8 · tx 0xfffc7d35599951f6… · tempo (42431) · testnet