// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title RastakhState - هستهی همگامسازی وضعیت
/// @notice فقط اپراتور میتواند state hash را ثبت کند
contract RastakhState {
address public immutable operator;
mapping(bytes32 => bool) public synchronizedStates;
event StateSynced(bytes32 indexed stateHash, address indexed caller, uint256 timestamp);
error NotOperator();
error AlreadySynced();
error ZeroHash();
constructor(address \_operator) {
require(\_operator != address(0), "Zero operator");
operator = \_operator;
}
/// @notice ثبت یک state hash روی زنجیره
function syncState(bytes32 \_stateHash) external {
if (msg.sender != operator) revert NotOperator();
if (\_stateHash == bytes32(0)) revert ZeroHash();
if (synchronizedStates\[\_stateHash\]) revert AlreadySynced();
synchronizedStates\[\_stateHash\] = true;
emit StateSynced(\_stateHash, msg.sender, block.timestamp);
}
/// @notice بررسی اینکه آیا یک hash قبلاً سینک شده
function isSynced(bytes32 \_stateHash) external view returns (bool) {
return synchronizedStates\[\_stateHash\];
}
}