File size: 1,229 Bytes
c1f778a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | ```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MessageStorage {
string private currentMessage;
address public owner;
uint256 public updateCount;
// Events
event MessageUpdated(string newMessage, address updater, uint256 timestamp);
// Modifier to restrict access to owner only
modifier onlyOwner() {
require(msg.sender == owner, "Only contract owner can perform this action");
_;
}
constructor(string memory initialMessage) {
owner = msg.sender;
currentMessage = initialMessage;
updateCount = 1; // Initial message is considered first update
}
// Function to update the message (only owner)
function updateMessage(string memory newMessage) public onlyOwner {
currentMessage = newMessage;
updateCount++;
emit MessageUpdated(newMessage, msg.sender, block.timestamp);
}
// Function to read the current message (public)
function getMessage() public view returns (string memory) {
return currentMessage;
}
// Function to get the number of updates (public)
function getUpdateCount() public view returns (uint256) {
return updateCount;
}
}
``` |