all files / contracts/ Complaints.sol

100% Statements 14/14
100% Branches 8/8
100% Functions 5/5
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                                            3× 3×         3× 1×         2× 1×             3× 1× 1× 1× 1×           3× 1× 1×        
// SPDX-License-Identifier: GPL-3.0-or-later
 
pragma solidity ^0.8.6;
 
/// @title Contract for copyright authorship complaints registration
/// @author Roberto García (http://rhizomik.net/~roberto/)
contract Complaints {
 
    struct Complaint {
        address complainer;
        string complaintHash;
        bool active;
    }
 
    address private owner;
    address private manifestations;
    mapping(string => Complaint) private complaints;
 
    event ComplaintEvent(address indexed complainer, string complaintHash, string indexed manifestationHashed);
    event RevokeComplaintEvent(address indexed complainer, string complaintHash, string indexed manifestationHashed);
 
    constructor(address _manifestations) {
        owner = msg.sender;
        manifestations = _manifestations;
    }
 
    /// @notice Retrieve the IPFS hash of the complaint content for the input manifestation
    function getComplaintHash(string memory manifestationHash) public view returns (string memory) {
        require(complaints[manifestationHash].active, "No active complaint for manifestation hash");
        return (complaints[manifestationHash].complaintHash);
    }
 
    /// @notice Retrieve the account that made the complaint for the input manifestation hash
    function getComplainer(string memory manifestationHash) public view returns (address) {
        require(complaints[manifestationHash].active, "No active complaint for manifestation hash");
        return (complaints[manifestationHash].complainer);
    }
 
    /// @notice Register a complaint using the IPFS hash of the complaint content and the hash
    /// identifying the manifestation complainted. Just one unexpired complaint for the same
    /// manifestation hash allowed
    function makeComplaint(string memory complaintHash, string memory manifestationHash) public {
        require(!complaints[manifestationHash].active, "Complaint for manifestation hash already registered");
        complaints[manifestationHash].complainer = msg.sender;
        complaints[manifestationHash].complaintHash = complaintHash;
        complaints[manifestationHash].active = true;
        emit ComplaintEvent(msg.sender, complaintHash, manifestationHash);
    }
 
    /// @notice Remove the complaint for the input manifestation
    /// @dev Just the contract owner can remove complaints
    function revokeComplaint(string memory manifestationHash) public {
        require(owner == msg.sender, "Just contract owner can revoke complaints");
        complaints[manifestationHash].active = false;
        emit RevokeComplaintEvent(complaints[manifestationHash].complainer,
            complaints[manifestationHash].complaintHash, manifestationHash);
    }
}