-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDwitter_main.sol
186 lines (149 loc) · 5.84 KB
/
Dwitter_main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
pragma solidity >=0.5.1;
contract DweetSent {
uint public DweetCount;
uint256 id;
//uint public lCount = 0;
//uint public rCount = 0 ;
const Dweet_id;
struct Dweet
{
uint256 id;
string dweetString;
//address dweetAuthor;
//string dweet_tags;
//uint lCount;
}
struct User {
uint age;
string EthAddress;
string email;
uint index;
uint DweetCount;
//mapping (uint => _dweets) MyDweets;
Dweet[] DweetsArray;
}
mapping (uint => Dweet) public MyDweets;
mapping (address => User) user;
mapping (address => _user) public _user;
mapping (address => mapping (uint => bool)) public reported;
mapping(uint => uint) public reportCount;
mapping (address => mapping (uint => bool)) public liked;
mapping (address => uint[]) public dweets_via_author;
address [] userindex;
address owner ;
bool action = false;
uint private totalDweetsCount;
Dweet[] public RepoDweets;
constructor() public {
createDweet("Hello World");
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
event LogNewUser (address indexed Address, uint index, string EthAddress, uint age);
event LogUpdateUser (address indexed Address, uint index, string EthAddress, uint age);
event NewDweet (address indexed Address, uint );
function isUser(address Address) public view returns (bool yesIsUser){
if(userindex.length == 0) return false;
return (userindex[users[Address].index] == Address);
}
function addUser (string memory _EthAddress, uint _age) public returns (bool success) {
address Address = msg.sender;
require(isUser(Address) == false);
users[Address].age = _age;
users[Address].EthAddress = _EthAddress;
users[Address].index = userindex.push(Address) - 1;
emit LogNewUser(Address, users[Address].index, _EthAddress, _age);
return true;
}
//function HashtagDweet(uint id, string memory _searchHashtag) view public dweetundelete
//{
// Dweet memory dweets = dweets[id];
//if (keccak256(abi.encodePacked(dweets.hashtag)) == keccak256(abi.encodePacked(_searchHashtag)))
//{
// return (dweets.content, dweets.author, dw.timestamp, dweets.upvotes, dweets.report, dweets.hashtag);
//}
//}
function getUser(address Address) public view returns(string memory EthAddress, uint age, uint index) {
require(isUser(Address) == true);
return (users[Address].EthAddress, users[Address].age, users[Address].index);
}
function createDweet(string memory _text) public returns (bool) {
require (isUser(msg.sender) == true);
uint dweet_index;
dweet_index = RepoDweets.push(Dweet(_text, msg.sender))-1;
uint _count = users[msg.sender].DweetCount;
users[msg.sender].MyDweets[_count] = Dweet(_text, msg.sender);
users[msg.sender].DweetCount ++;
users[msg.sender].DweetsArray.push(Dweet(_text, msg.sender));
return true;
}
function dweetsByUser(address Address) public view returns (Dweet[] memory) {
require (isUser(Address) == true);
//require(Dweet.deleted != true);
Dweet[] memory _dweets = new Dweet[](users[Address].dweet_count);
return users[Address].DweetsArray;
}
function totalDweetsByUser (address Address) public view returns (uint) {
return users[Address].dweet_count;
}
function dweetByIndex(uint _id) public view returns (string memory _dweet, address _author) {
_dweet = RepoDweets[_id].dweet_text;
_author = RepoDweets[_id].dweet_author;
return (_dweet, _author);
}
event DweetCreated(
uint id,
string dweetString);
function createDweet(string memory _dweetString) public onlyOwner{
DweetCount+=1;
//id +=1;
MyDweets[DweetCount] = Dweet(DweetCount,_dweetString,0,false);
emit DweetCreated(id,_dweetString);
}
event Reported(
uint id,
string dweetString);
function reportOnce(uint _id, address _ethaddress) external {
if (reported[_ethaddress][_id] != true ){
reportDweet(_id,_ethaddress);
}
}
function reportDweet(uint _id,address _ethaddress) internal {
reportCount[_id]++;
reported[_ethaddress][_id] = true;
if ((reportCount[_id])>=10) {
MyDweets[_id].dweetString = "";
}
emit Reported(id, MyDweets[_id].dweetString);
}
event profileUpdate (
uint age,
string email);
function editprofile(address _address, uint _age, string memory _email) public onlyOwner{
require(_address == msg.sender);
user[_address].age = _age;
user[_address].email = _email;
emit profileUpdate(user[_address].age ,user[_address].email);
}
event like(
uint id,
uint likeCount
);
function likeOnce(uint _id, address _ethaddress) external {
if (liked[_ethaddress][_id] != true){
likeDweet(_id,_ethaddress);
}
}
function likeDweet(uint _id , address _ethaddress) internal {
liked[_ethaddress][_id] = true;
MyDweets[_id].lCount += 1;
emit like(_id,MyDweets[_id].lCount);
}
function DeleteDweet(uint _id) public onlyOwner{
MyDweets[_id].dweetString = "";
MyDweets[_id].deleted = true;
}
}