// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; /// @notice OPTIONAL, UNCOMPILED AND UNAUDITED REFERENCE. Do not deploy as-is. /// This is a centrally administered entitlement registry, NOT a payment or rent-collection contract. /// Store only non-personal hashes. Actual billing, refunds, legal execution and portal access remain off-chain. // protectionsHash binds the separately versioned NDA/non-compete annex; legal enforcement stays off-chain. contract ParticleLicenseRegistry { address public operator; address public pendingOperator; struct License { address tenant; bytes32 agreementHash; bytes32 protectionsHash; uint64 start; uint64 end; bool accepted; bool paymentAttested; bool revoked; bool renewalStopped; } mapping(bytes32 => License) public licenses; event Offered(bytes32 indexed particle, address indexed tenant, bytes32 agreementHash, bytes32 protectionsHash, uint64 start, uint64 end); event Accepted(bytes32 indexed particle, address indexed tenant, bytes32 protectionsHash); event PaymentAttested(bytes32 indexed particle, bytes32 paymentReferenceHash); event RenewalStopped(bytes32 indexed particle); event Revoked(bytes32 indexed particle, bytes32 reasonHash); event OperatorTransferStarted(address indexed candidate); event OperatorTransferred(address indexed operator); modifier onlyOperator(){ require(msg.sender == operator, "operator only"); _; } constructor(address operator_){ require(operator_ != address(0), "zero operator"); operator = operator_; } function offer(bytes32 particle, address tenant, bytes32 terms, bytes32 protections, uint64 start, uint64 end) external onlyOperator { require(particle != bytes32(0) && tenant != address(0) && terms != bytes32(0) && protections != bytes32(0), "missing fields"); require(start >= block.timestamp && end > start, "bad dates"); License storage prior = licenses[particle]; require(prior.tenant == address(0) || prior.revoked || prior.end <= block.timestamp, "occupied or offered"); licenses[particle] = License(tenant, terms, protections, start, end, false, false, false, false); emit Offered(particle, tenant, terms, protections, start, end); } function accept(bytes32 particle, bytes32 exactTerms, bytes32 exactProtections) external { License storage item = licenses[particle]; require(msg.sender == item.tenant && !item.revoked && block.timestamp < item.end, "not current tenant"); require(!item.accepted && exactTerms == item.agreementHash && exactProtections == item.protectionsHash, "wrong or accepted terms"); item.accepted = true; emit Accepted(particle, msg.sender, exactProtections); } function attestPayment(bytes32 particle, bytes32 referenceHash) external onlyOperator { License storage item = licenses[particle]; require(item.accepted && !item.revoked && block.timestamp < item.end && referenceHash != bytes32(0), "not activatable"); require(!item.paymentAttested, "already attested"); item.paymentAttested = true; emit PaymentAttested(particle, referenceHash); } function stopRenewal(bytes32 particle) external { License storage item = licenses[particle]; require(msg.sender == operator || msg.sender == item.tenant, "not a party"); item.renewalStopped = true; emit RenewalStopped(particle); // The billing adapter MUST also stop off-chain renewal. This function cannot cancel a provider subscription. } function revoke(bytes32 particle, bytes32 reasonHash) external onlyOperator { require(licenses[particle].tenant != address(0) && reasonHash != bytes32(0), "missing license or reason"); licenses[particle].revoked = true; emit Revoked(particle, reasonHash); } function active(bytes32 particle) external view returns(bool){ License storage item = licenses[particle]; return item.accepted && item.paymentAttested && !item.revoked && block.timestamp >= item.start && block.timestamp < item.end; } function transferOperator(address candidate) external onlyOperator { require(candidate != address(0), "zero operator"); pendingOperator = candidate; emit OperatorTransferStarted(candidate); } function acceptOperator() external { require(msg.sender == pendingOperator, "not candidate"); operator = pendingOperator; pendingOperator = address(0); emit OperatorTransferred(operator); } }