// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract DataStorage is Ownable { mapping(address => string) public storedData; mapping(address => bool) public hasPaid; mapping(string => bool) private dataExists; IERC20 public token; uint256 public tokenPrice; event DataStored(address indexed _from, string _data); event TokenPriceUpdated(uint256 _newPrice); constructor(address _tokenAddress, uint256 _tokenPrice) { token = IERC20(_tokenAddress); tokenPrice = _tokenPrice; } function setData(string memory _data) external { require(bytes(_data).length <= 9, "Data length exceeds 9 characters"); require(!dataExists[_data], "Data already exists"); require(!hasPaid[msg.sender], "Token already paid for data storage"); require(token.transferFrom(msg.sender, address(this), tokenPrice), "Token transfer failed"); storedData[msg.sender] = _data; dataExists[_data] = true; hasPaid[msg.sender] = true; emit DataStored(msg.sender, _data); } function getData(address _address) external view returns (string memory) { return storedData[_address]; } function updateTokenPrice(uint256 _newPrice) external onlyOwner { tokenPrice = _newPrice; emit TokenPriceUpdated(_newPrice); } function withdrawTokens(uint256 _amount) external onlyOwner { require(token.balanceOf(address(this)) >= _amount, "Insufficient balance"); require(token.transfer(owner(), _amount), "Token transfer failed"); } function transferOwnershipTo(address _newOwner) external onlyOwner { transferOwnership(_newOwner); } // Function to transfer user data to a new contract function transferToNewContract(address _newContract) external onlyOwner { // Implement logic to transfer data to the new contract } }