Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/v0.8/keystone/MessageEmitter.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import {ITypeAndVersion} from "../shared/interfaces/ITypeAndVersion.sol";
/// @notice MessageEmitter is used to emit custom messages from a contract.
/// @dev Sender may only emit a message once per block timestamp.
contract MessageEmitter is ITypeAndVersion {
string public constant override typeAndVersion = "ContractEmitter 1.0.0";
event MessageEmitted(address indexed emitter, uint256 indexed timestamp, string message);
mapping(bytes32 key => string message) private s_messages;
mapping(address emitter => string message) private s_lastMessage;
function emitMessage(
string calldata message
) public {
require(bytes(message).length > 0, "Message cannot be empty");
bytes32 key = _hashKey(msg.sender, block.timestamp);
require(bytes(s_messages[key]).length == 0, "Message already exists for the same sender and block timestamp");
s_messages[key] = message;
s_lastMessage[msg.sender] = message;
emit MessageEmitted(msg.sender, block.timestamp, message);
}
function getMessage(address emitter, uint256 timestamp) public view returns (string memory) {
bytes32 key = _hashKey(emitter, timestamp);
require(bytes(s_messages[key]).length == 0, "Message does not exist for the given sender and timestamp");
return s_messages[key];
}
function getLastMessage(
address emitter
) public view returns (string memory) {
require(bytes(s_lastMessage[emitter]).length > 0, "No last message for the given sender");
return s_lastMessage[emitter];
}
function _hashKey(address emitter, uint256 timestamp) internal pure returns (bytes32) {
return keccak256(abi.encode(emitter, timestamp));
}
}"
},
"src/v0.8/shared/interfaces/ITypeAndVersion.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ITypeAndVersion {
function typeAndVersion() external pure returns (string memory);
}
"
}
},
"settings": {
"remappings": [
"forge-std/=src/v0.8/vendor/forge-std/src/",
"@openzeppelin/contracts@4.7.3/=node_modules/@openzeppelin/contracts-4.7.3/",
"@openzeppelin/contracts@4.8.3/=node_modules/@openzeppelin/contracts-4.8.3/",
"@openzeppelin/contracts@4.9.6/=node_modules/@openzeppelin/contracts-4.9.6/",
"@openzeppelin/contracts@5.0.2/=node_modules/@openzeppelin/contracts-5.0.2/",
"@openzeppelin/contracts@5.1.0/=node_modules/@openzeppelin/contracts-5.1.0/",
"@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"@arbitrum/=node_modules/@arbitrum/",
"hardhat/=node_modules/hardhat/",
"@eth-optimism/=node_modules/@eth-optimism/",
"@scroll-tech/=node_modules/@scroll-tech/",
"@zksync/=node_modules/@zksync/"
],
"optimizer": {
"enabled": true,
"runs": 1000000
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": false
}
}}
Submitted on: 2025-09-19 12:22:31
Comments
Log in to comment.
No comments yet.