forked from pointer-gg/comments-with-polygon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comments.sol
36 lines (30 loc) · 946 Bytes
/
Comments.sol
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
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract Comments {
struct Comment {
uint32 id;
string topic;
address creator_address;
string message;
uint created_at;
}
uint32 private idCounter;
mapping(string => Comment[]) private commentsByTopic;
event CommentAdded(Comment comment);
function getComments(string calldata topic) public view returns(Comment[] memory) {
return commentsByTopic[topic];
}
function addComment(string calldata topic, string calldata message) public {
Comment memory comment = Comment({
id: idCounter,
topic: topic,
creator_address: msg.sender,
message: message,
created_at: block.timestamp
});
commentsByTopic[topic].push(comment);
idCounter++;
emit CommentAdded(comment);
}
}