// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract e2XUsernames { address public owner; mapping(address => string) public storedData; mapping(string => address) public addressByUser; mapping(address => bool) private isAdmin; event DataStored(address indexed _from, string _data); event AdminChanged(address indexed _previousAdmin, address indexed _newAdmin); event DataTransferred(address indexed _from, address indexed _to, string _data); modifier onlyAdmin() { require(isAdmin[msg.sender], "Only admin can call this function"); _; } modifier onlyOwner() { require(msg.sender == owner, "Only owner can call this function"); _; } constructor() { owner = msg.sender; isAdmin[msg.sender] = true; } function e2xData(string memory _data) public { require(bytes(_data).length <= 9, "Data length exceeds 9 characters"); require(addressByUser[_data] == address(0), "User ID already exists"); storedData[msg.sender] = _data; addressByUser[_data] = msg.sender; emit DataStored(msg.sender, _data); } function getData(address _address) public view returns (string memory) { return storedData[_address]; } function getAddressByUser(string memory _user) public view returns (address) { return addressByUser[_user]; } function transferToNewContract(address _newContract) external onlyOwner { require(_newContract != address(0), "Invalid new contract address"); // Implement logic to transfer data to the new contract // For demonstration purposes, emitting an event here emit DataTransferred(address(this), _newContract, storedData[msg.sender]); } function changeAdmin(address _newAdmin) public onlyOwner { require(_newAdmin != address(0), "Invalid admin address"); require(!isAdmin[_newAdmin], "Address is already an admin"); isAdmin[_newAdmin] = true; isAdmin[owner] = false; owner = _newAdmin; emit AdminChanged(msg.sender, _newAdmin); } }