all files / contracts/ Evidencable.sol

100% Statements 5/5
100% Branches 2/2
100% Functions 5/5
100% Lines 6/6
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                                    8× 6×           12×           6×             11×             10×      
// SPDX-License-Identifier: GPL-3.0-or-later
 
pragma solidity ^0.8.6;
 
import "openzeppelin-solidity/contracts/utils/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/access/Ownable.sol";
 
 
/// @title Library to implement items that can accumulate evidence
/// @author Roberto García (http://rhizomik.net/~roberto/)
contract Evidencable is Ownable {
    using SafeMath for uint8;
 
    mapping(address => bool) private evidenceProviders;
    mapping(string => uint8) private evidenceCounts;
 
    /// @dev Modifier controlling that only registered evidence providers are allowed
    modifier onlyEvidenceProvider() {
        require(evidenceProviders[msg.sender], "Only registered evidence providers allowed");
        _;
    }
 
    /// @notice Get the evidence count for the manifestation with `hash`.
    /// @param hash Hash of the manifestation content, for instance IPFS Base58 Hash
    function getEvidenceCount(string memory hash) public view returns (uint8) {
        return evidenceCounts[hash];
    }
 
    /// @notice Adds one to the evidence count for the manifestation with `hash`.
    /// @param hash Hash of the manifestation content, for instance IPFS Base58 Hash
    function addEvidence(string memory hash) virtual public onlyEvidenceProvider {
        evidenceCounts[hash] = uint8(evidenceCounts[hash].add(1));
    }
 
    /// @notice Adds an evidence provider `provider` contract that can then call addEvidence(...)
    /// to add evidence.
    /// @param provider The address of a contract providing evidence
    function addEvidenceProvider(address provider) public onlyOwner {
        evidenceProviders[provider] = true;
    }
 
    /// @notice Check if the evidencable `hash` has no evidence yet.
    /// @dev Used to check if the corresponding item evidence count is 0.
    /// @param hash Hash of the manifestation content, for instance IPFS Base58 Hash
    function isUnevidenced(string memory hash) public view returns(bool) {
        return (evidenceCounts[hash] == 0);
    }
}