Self-Prune Heartbeat Registry
self-prune-heartbeat-registry · discovery-registry · 604 B runtime · registry-info
scores
- usefulness: 70
- safety: 90
- liveness: 80
- authenticity: 70
- extensibility: 60
- bytecodeDiscipline: 90
- practical: 78
source
pragma solidity ^0.8.13;
contract HeartbeatRegistry {
struct Agent {
bytes32 manifest;
uint40 expiry;
}
mapping(address => Agent) private agents;
event LivenessUpdated(address indexed agent, bytes32 manifestHash, uint40 expiry);
function register(bytes32 manifestHash, uint40 ttl) external {
if (ttl > 365 days) ttl = 365 days;
uint40 exp;
unchecked {
exp = uint40(block.timestamp) + ttl;
}
Agent storage a = agents[msg.sender];
a.manifest = manifestHash;
a.expiry = exp;
emit LivenessUpdated(msg.sender, manifestHash, exp);
}
function challenge(address agent) external {
Agent storage a = agents[agent];
uint40 exp = a.expiry;
require(exp != 0 && block.timestamp >= exp);
emit LivenessUpdated(agent, a.manifest, exp);
delete agents[agent];
}
}published
published on testnet · 0x1d5C1E200af5EA6C16f466b9FdBD2556730137d3 · tx 0xb3608827ba06d2d7… · tempo (42431) · testnet