Verified contractPartialMIT
Ciphered
Address0x89902a20f79b9b2a7082c8a103e809a8cd32b1b1
- Balance
0 ETH
- Transactions
3
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 1 runs
- EVM version
- cancun
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 20,865,607
- Creation transaction
- 0x6b2770176c…91d1903ad3
Ciphered.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Ciphered {
struct Message {
address from;
string message;
string img;
uint256 timestamp;
bool moderated;
uint256 localId;
}
struct Group{
string name;
string description;
string logo;
uint256 creationDate;
uint256 localId;
address owner;
bool paused;
}
struct User {
string username;
uint256[] createdGroups;
}
uint256 id = 0;
uint256[] public groups;
string[] public groupNames;
mapping(address => User) public users;
mapping(string => bool) public groupName;
mapping(string => bool) public usernames;
mapping(string => uint256) public groupid;
mapping(uint256 => Group) public allGroups;
mapping(uint256 => mapping(address => bool)) public mods;
mapping(uint256 => Message[]) public messages;
mapping(uint256 => mapping(address => bool)) public banList;
event GroupCreated(uint256 id);
function changeUsername(string memory _username) public {
require(usernames[_username] == false, 'already in use');
bytes memory tempEmptyStringTest = bytes(_username); // Uses memory
require(tempEmptyStringTest.length >= 3 && tempEmptyStringTest.length <= 20, 'must type in some characters, min 3 max 20');
string memory oldUsername = users[msg.sender].username;
users[msg.sender].username = _username;
usernames[oldUsername] = false;
usernames[_username] = true;
}
function getUsersCreatedGroupsLength(address _who) public view returns(uint256){
return users[_who].createdGroups.length;
}
function createGroup(string memory _name, string memory description, string memory logo, bool isPaused) public returns(uint256 groupID) {
require(groupName[_name] == false, 'already exists');
groups.push(id);
groupName[_name] = true;
groupid[_name] = id;
groupNames.push(_name);
users[msg.sender].createdGroups.push(id);
Group memory localGroup = Group(_name, description, logo, block.timestamp, id, msg.sender, isPaused);
allGroups[id] = localGroup;
mods[id][msg.sender] = true;
id = id+1;
emit GroupCreated(id-1);
return id-1;
}
function fetchMultipleGroupsIDs(string[] memory localgroups) public view returns(uint256[] memory gids){
uint256[] memory localIDS = new uint256[](localgroups.length);
for(uint256 i=0; i<localgroups.length;i++){
uint256 theID = groupid[localgroups[i]];
localIDS[i] = theID;
// localIDS.push(theID);
}
return localIDS;
}
function addModerator(address _who, bool _status, uint256 _id) public {
require(allGroups[_id].owner == msg.sender, 'not owner');
mods[_id][_who] = _status;
}
function banSomeone(address _who, bool _status, uint256 _id) public {
require(mods[_id][msg.sender] == true, 'not an admin');
require(allGroups[_id].owner != _who, 'cannot ban owner');
banList[_id][_who] = _status;
}
function moderateMessage (uint256 _gid, uint256 _mid) public {
require(mods[_gid][msg.sender] == true, 'not an admin');
messages[_gid][_mid].moderated = true;
messages[_gid][_mid].message = '';
}
function moderateMessages (uint256 _gid, uint256[] memory _mid) public {
require(mods[_gid][msg.sender] == true, 'not an admin');
for(uint256 i=0; i<_mid.length; i++){
messages[_gid][_mid[i]].moderated = true;
messages[_gid][_mid[i]].message = '';
}
}
function moderateMessageAndbanSomeone(address _who, uint256 _gid, uint256 _mid) public {
require(mods[_gid][msg.sender] == true, 'not an admin');
require(allGroups[_gid].owner != _who, 'cannot ban owner');
messages[_gid][_mid].moderated = true;
messages[_gid][_mid].message = '';
banList[_gid][_who] = true;
}
function transferGroupOwnership(address _who, uint256 _id) public {
require(allGroups[_id].owner == msg.sender, 'not owner');
allGroups[_id].owner = _who;
}
function sendMessage(string memory _msg, string memory _image, uint256 _id) public {
require(allGroups[_id].paused == false || mods[_id][msg.sender] == true, 'cannot send messages here');
require(banList[_id][msg.sender] == false, 'you are banned');
require(_id <= id, 'group does not exist');
uint256 messagesLength = messages[_id].length;
Message memory localMessage = Message(msg.sender, _msg, _image, block.timestamp, false, messagesLength);
messages[_id].push(localMessage);
}
function getGroupMessagesLength(uint256 _gid) public view returns(uint256){
return messages[_gid].length;
}
function getGroupNamesLength() public view returns(uint256){
return groupNames.length;
}
function fetchUsernames(address[] memory _users) public view returns(string[] memory){
string[] memory localUSERS = new string[](_users.length);
for(uint256 i=0; i<_users.length; i++){
localUSERS[i] = users[_users[i]].username;
}
return localUSERS;
}
function fetchComments(uint256 cursor, uint256 howMany, uint256 _gid)
public
view
returns (Message[] memory values, uint256 newCursor)
{
uint256 length = howMany;
if (length > messages[_gid].length - cursor) {
length = messages[_gid].length - cursor;
}
values = new Message[](length);
for (uint256 i = 0; i < length; i++) {
values[i] = messages[_gid][cursor + i];
}
return (values, cursor + length);
}
function fetchGroupNames(uint256 cursor, uint256 howMany)
public
view
returns (string[] memory values, uint256 newCursor)
{
uint256 length = howMany;
if (length > groupNames.length - cursor) {
length = groupNames.length - cursor;
}
values = new string[](length);
for (uint256 i = 0; i < length; i++) {
values[i] = groupNames[cursor + i];
}
return (values, cursor + length);
}
function fetchCreatedGroups(uint256 cursor, uint256 howMany, address _who)
public
view
returns (uint256[] memory values, uint256 newCursor)
{
uint256 length = howMany;
if (length > users[_who].createdGroups.length - cursor) {
length = users[_who].createdGroups.length - cursor;
}
values = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
values[i] = users[_who].createdGroups[cursor + i];
}
return (values, cursor + length);
}
}Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 1,
"enabled": true
},
"evmVersion": "cancun",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.