// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract VoucherRegistry { struct Voucher { address contractAddress; string e2xDataId; bool isUsed; string tokenName; uint256 tokenAmount; uint256 timestamp; } mapping(string => Voucher) public vouchers; string[] public voucherIds; mapping(address => bool) public permittedContracts; event VoucherStatusUpdated(string indexed voucherId, bool used); event PermittedContractSet(address indexed contractAddress, bool status); modifier onlyOwner() { require(msg.sender == owner, "Only contract owner can call this function"); _; } modifier onlyPermittedContracts() { require(permittedContracts[msg.sender], "Contract address not permitted"); _; } address public owner; constructor() { owner = msg.sender; } function registerVoucher( string memory voucherId, address contractAddress, string memory e2xDataId, string memory tokenName, uint256 tokenAmount, uint256 timestamp ) external onlyOwner { require(vouchers[voucherId].contractAddress == address(0), "Voucher ID already exists"); // Register voucher details vouchers[voucherId] = Voucher({ contractAddress: contractAddress, e2xDataId: e2xDataId, isUsed: false, tokenName: tokenName, tokenAmount: tokenAmount, timestamp: timestamp }); voucherIds.push(voucherId); } function getVoucherStatus(string memory voucherId) external view returns (bool) { return vouchers[voucherId].isUsed; } function getVoucherStatusByE2xData(string memory e2xDataId) external view returns (bool) { // Iterate through vouchers to find the status of vouchers associated with the given e2xData ID for (uint256 i = 0; i < voucherIds.length; i++) { if (keccak256(abi.encodePacked(vouchers[voucherIds[i]].e2xDataId)) == keccak256(abi.encodePacked(e2xDataId))) { return vouchers[voucherIds[i]].isUsed; } } return false; // Return false if no vouchers found for the given e2xData ID } function updateVoucherStatus(string memory voucherId, bool used) external onlyPermittedContracts { vouchers[voucherId].isUsed = used; emit VoucherStatusUpdated(voucherId, used); } function setPermittedContract(address contractAddress, bool status) external onlyOwner { permittedContracts[contractAddress] = status; emit PermittedContractSet(contractAddress, status); } }