APE Price: $1.47 (-4.35%)

Contract Diff Checker

Contract Name:
PodcastGuidMapper

Contract Source Code:

File 1 of 1 : PodcastGuidMapper

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IPodcastMetadata {
    function getEpisodeContent(uint256 _episodeId) external view returns (
        string memory ipfsHash,
        string memory filename,
        string memory title,
        string memory description,
        string memory keywords
    );
}

interface IEngagement {
    function submitFeedback(uint256 episodeId, string calldata feedback) external;
    function submitRating(uint256 episodeId, uint8 rating) external;
}

contract PodcastGuidMapper {
    address public owner;
    address public podcastMetadata;
    address public engagementContract;
    
    mapping(string => uint256) public guidToEpisodeId;
    mapping(uint256 => string) public episodeIdToGuid;
    
    event EpisodeMapped(string guid, uint256 episodeId);
    event ContractAddressUpdated(string contractType, address newAddress);
    
    constructor(address _podcastMetadata, address _engagementContract) {
        owner = msg.sender;
        podcastMetadata = _podcastMetadata;
        engagementContract = _engagementContract;
    }
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }
    
    modifier episodeExists(uint256 episodeId) {
        // Verify episode exists by trying to get its content
        try IPodcastMetadata(podcastMetadata).getEpisodeContent(episodeId) returns (
            string memory, string memory, string memory, string memory, string memory
        ) {
            _;
        } catch {
            revert("Episode does not exist");
        }
    }
    
    function mapEpisode(string calldata guid, uint256 episodeId) external onlyOwner episodeExists(episodeId) {
        require(bytes(guid).length > 0, "Empty GUID");
        require(guidToEpisodeId[guid] == 0, "GUID already mapped");
        require(bytes(episodeIdToGuid[episodeId]).length == 0, "ID already mapped");
        
        guidToEpisodeId[guid] = episodeId;
        episodeIdToGuid[episodeId] = guid;
        
        emit EpisodeMapped(guid, episodeId);
    }
    
    function submitFeedback(string calldata guid, string calldata feedback) external {
        uint256 episodeId = guidToEpisodeId[guid];
        require(episodeId > 0, "GUID not found");
        
        IEngagement(engagementContract).submitFeedback(episodeId, feedback);
    }
    
    function submitRating(string calldata guid, uint8 rating) external {
        uint256 episodeId = guidToEpisodeId[guid];
        require(episodeId > 0, "GUID not found");
        
        IEngagement(engagementContract).submitRating(episodeId, rating);
    }
    
    function updateContractAddresses(
        address _podcastMetadata,
        address _engagementContract
    ) external onlyOwner {
        if (_podcastMetadata != address(0)) {
            podcastMetadata = _podcastMetadata;
            emit ContractAddressUpdated("PodcastMetadata", _podcastMetadata);
        }
        if (_engagementContract != address(0)) {
            engagementContract = _engagementContract;
            emit ContractAddressUpdated("Engagement", _engagementContract);
        }
    }
    
    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "Invalid address");
        owner = newOwner;
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):