all files / contracts/ UploadEvidence.sol

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 5/5
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                                      1×                       11× 7× 3× 3×        
// SPDX-License-Identifier: GPL-3.0-or-later
 
pragma solidity ^0.8.6;
 
import "./Evidencable.sol";
 
/// @title Contract to register evidence based on uploading content to IPFS
/// @author Roberto García (http://rhizomik.net/~roberto/)
contract UploadEvidence {
 
    /// @notice Allows checking if some content has already been used as evidence.
    mapping(string => bool) private existingEvidence;
 
    event UploadEvidenceEvent(address indexed registry, bytes32 indexed evidencedIdHash,
        string evidencedHash, string evidenceHash, address indexed evidencer);
 
    /// @notice Get if the evidence with content hash `evidenceHash` is already registered.
    /// @param evidenceHash Hash of the evidence content, for instance IPFS Base58 Hash
    function getEvidenceExistence(string memory evidenceHash) public view returns (bool) {
        return existingEvidence[evidenceHash];
    }
 
    /// @notice Add evidence for item in `registry` identified by `evidencedHash`. The evidence
    /// has `evidenceHash` and is registered by `msg.sender`.
    /// @dev The address of the registry containing the evidenced item is required to update
    /// its evidence count. Evidence is stored just in the log as UploadEvidenceEvent events.
    /// Note: the evidenceHash is hashed using keccak256 before emitting the event so it can be indexed.
    /// @param registry The address of the contract holding the items evidenced
    /// @param evidencedHash Hash used by the registry contract to identify the item receiving evidence
    /// @param evidenceHash Hash of the uploaded content to be used as evidence, for instance IPFS Base58 Hash
    function addEvidence(address registry, string memory evidencedHash, string memory evidenceHash) public {
        require(!existingEvidence[evidenceHash], "The evidence has been already registered");
        Evidencable(registry).addEvidence(evidencedHash);
        existingEvidence[evidenceHash] = true;
        emit UploadEvidenceEvent(registry, keccak256(abi.encodePacked(evidencedHash)),
            evidencedHash, evidenceHash, msg.sender);
    }
}