Codehash-Stamped Receipt

codehash-stamped-receipt · receipt-attestation · 297 B runtime · registry-info

scores

source

pragma solidity ^0.8.13;

contract CodehashStampedReceipt {
    event ReceiptMinted(address indexed agent, bytes32 indexed taskId, bytes32 metadata);

    mapping(bytes32 => bool) private _approved;

    constructor(bytes32[] memory approvedHashes) {
        for (uint256 i = 0; i < approvedHashes.length; ++i) {
            require(approvedHashes[i] != bytes32(0), 'zero hash');
            _approved[approvedHashes[i]] = true;
        }
    }

    function mint(bytes32 taskId, bytes32 metadata) external {
        require(_approved[msg.sender.codehash], 'unapproved codehash');
        emit ReceiptMinted(msg.sender, taskId, metadata);
    }
}