-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfake-news-sol.sol
77 lines (64 loc) · 2.02 KB
/
fake-news-sol.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
pragma solidity ^0.5.0;
contract Fakenews{
uint amount;
struct votes{
uint8 notfake;
uint8 fake;
bool validate;
}
mapping(string => votes) votestatus;
mapping(address => string) voteflag;
mapping(address => uint) voteCount;
function validateVoteStart(string memory text) public view returns(bool){
return votestatus[text].validate;
}
function postQuery(string memory text) public{
require(votestatus[text].validate == false);
votestatus[text].notfake=0;
votestatus[text].fake=0;
votestatus[text].validate = true;
}
function stringsEqual(string storage _a, string memory _b) internal view returns (bool) {
bytes storage a = bytes(_a);
bytes memory b = bytes(_b);
if (a.length != b.length)
return false;
// @todo unroll this loop
for (uint i = 0; i < a.length; i ++)
if (a[i] != b[i])
return false;
return true;
}
function voteFake(string memory text) public{
require(!stringsEqual(voteflag[msg.sender],text));
votestatus[text].fake += 1;
voteflag[msg.sender] = text;
voteCount[msg.sender] += 1;
if(voteCount[msg.sender] >= 5){
getIncentive();
}
}
function voteTrue(string memory text) public{
require(!stringsEqual(voteflag[msg.sender],text));
votestatus[text].notfake += 1;
voteflag[msg.sender] = text;
voteCount[msg.sender] += 1;
if(voteCount[msg.sender] % 5 == 0){
getIncentive();
}
}
function getIncentive() private{
msg.sender.transfer(0.1 ether);
}
function transferAmount() public payable{
amount = msg.value;
}
function viewCountTrue(string memory text) public view returns(uint){
require(amount == 0.3 ether);
return votestatus[text].notfake ;
}
function viewCountFake(string memory text) public view returns(uint){
require(amount == 0.3 ether);
return votestatus[text].fake ;
}
}