// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./e2XUsernames.sol"; contract EmailRegistry { e2XUsernames public userDataContract; string public contractVersion; struct Member { string email; address walletAddress; bool registered; } mapping(bytes32 => Member) public members; // Mapping from member ID to member details mapping(string => bool) public emailRegistered; // Mapping to check if email is already registered event EmailRegistered(bytes32 indexed memberId, string email, address indexed walletAddress); event EmailUpdated(bytes32 indexed memberId, string newEmail); constructor(address _userDataContract) { userDataContract = e2XUsernames(_userDataContract); contractVersion = "0.16"; } // Register email against the e2XUsername reference function registerEmail(bytes32 memberId) external { require(!members[memberId].registered, "Email already registered"); address walletAddress = msg.sender; string memory email = ""; // You should fetch the email from your frontend or MetaMask require(bytes(email).length > 0, "Invalid email address"); members[memberId] = Member(email, walletAddress, true); emailRegistered[email] = true; emit EmailRegistered(memberId, email, walletAddress); } // Update email against the e2XUsername reference function updateEmail(bytes32 memberId, string calldata newEmail) external { require(members[memberId].registered, "Email not registered"); require(!emailRegistered[newEmail], "Email already registered"); members[memberId].email = newEmail; emailRegistered[newEmail] = true; emit EmailUpdated(memberId, newEmail); } // Get email address by member ID and wallet address function getEmail(bytes32 memberId, address walletAddress) external view returns (string memory) { require(members[memberId].walletAddress == walletAddress, "Invalid member ID or wallet address"); return members[memberId].email; } }