forked from sagnik/Project_Astral
58 lines
1.6 KiB
Solidity
58 lines
1.6 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.24;
|
|
|
|
contract AstralAccess {
|
|
struct Log {
|
|
address user;
|
|
string lora_hash;
|
|
string output_hash;
|
|
uint256 timestamp;
|
|
}
|
|
|
|
address public admin;
|
|
mapping(address => mapping(string => uint256)) public accessRegistry;
|
|
Log[] public generationLog;
|
|
|
|
event GenerationCreated(address indexed user, string lora_hash, uint256 timestamp);
|
|
|
|
modifier onlyAdmin() {
|
|
require(msg.sender == admin, "Admin only");
|
|
_;
|
|
}
|
|
|
|
constructor() {
|
|
admin = msg.sender;
|
|
}
|
|
|
|
function grantAccess(address user, string calldata lora_hash, uint256 durationInSeconds) external onlyAdmin {
|
|
accessRegistry[user][lora_hash] = block.timestamp + durationInSeconds;
|
|
}
|
|
|
|
function revokeAccess(address user, string calldata lora_hash) external onlyAdmin {
|
|
accessRegistry[user][lora_hash] = 0;
|
|
}
|
|
|
|
function checkAccess(address user, string calldata lora_hash) public view returns (bool) {
|
|
return block.timestamp < accessRegistry[user][lora_hash];
|
|
}
|
|
|
|
function logGeneration(string calldata lora_hash, string calldata output_hash) external {
|
|
require(checkAccess(msg.sender, lora_hash), "Access denied");
|
|
|
|
generationLog.push(
|
|
Log({
|
|
user: msg.sender,
|
|
lora_hash: lora_hash,
|
|
output_hash: output_hash,
|
|
timestamp: block.timestamp
|
|
})
|
|
);
|
|
|
|
emit GenerationCreated(msg.sender, lora_hash, block.timestamp);
|
|
}
|
|
|
|
function generationLogCount() external view returns (uint256) {
|
|
return generationLog.length;
|
|
}
|
|
}
|