// 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 mapping(address => bytes32) public addressToMemberId; // Mapping to store the association between addresses and member IDs 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(string calldata email) external { bytes32 memberId = addressToMemberId[msg.sender]; require(memberId != bytes32(0), "Member ID not found for sender"); require(!members[memberId].registered, "Email already registered"); require(!emailRegistered[email], "Email already registered"); members[memberId] = Member(email, msg.sender, true); emailRegistered[email] = true; emit EmailRegistered(memberId, email, msg.sender); } // Update email against the e2XUsername reference function updateEmail(string calldata newEmail) external { bytes32 memberId = addressToMemberId[msg.sender]; require(memberId != bytes32(0), "Member ID not found for sender"); 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(address walletAddress) external view returns (string memory) { bytes32 memberId = addressToMemberId[walletAddress]; require(members[memberId].walletAddress == walletAddress, "Invalid member ID or wallet address"); return members[memberId].email; } // Get Member ID by address function getMemberIdByAddress(address _address) public view returns (bytes32) { return addressToMemberId[_address]; } }