-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProposals.sol
98 lines (76 loc) · 2.8 KB
/
Proposals.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
pragma solidity 0.8.10;
contract DAOtoken {
function getAddressBalance(address myAddress) external view returns (uint256) {}
}
// SPDX-License-Identifier: MIT
contract Proposals {
uint256 private id;
address private dev;
DAOtoken public daoToken;
struct Proposal {
address author;
string title;
string description;
mapping(address => bool) upvotedAddresses;
uint256 upvotes;
bool active;
}
Proposal[] proposals;
constructor(address DAOtokenAddress) {
id = 0;
dev = address(msg.sender);
daoToken = DAOtoken(DAOtokenAddress);
}
function proposalAmount() external view returns(uint256) {
return id;
}
function developerAddress() external view returns(address) {
return address(dev);
}
function newProposal(string memory title, string memory description) external returns(uint256) {
proposals.push();
Proposal storage proposal = proposals[id];
proposal.author = address(msg.sender);
proposal.title = title;
proposal.description = description;
proposal.upvotedAddresses[msg.sender] = true;
proposal.upvotes = 1;
proposal.active = true;
id++;
return id;
}
function getProposalAuthor(uint256 _id) exterbal view returns(address) {
require(proposals.length > _id, "404");
return proposals[_id].author;
}
function getProposalTitle(uint256 _id) external view returns(string memory) {
return proposals[_id].title;
}
function getProposalDescription(uint256 _id) external view returns(string memory) {
return proposals[_id].description;
}
function getProposalUpvotes(uint256 _id) external view returns (uint256) {
return proposals[_id].upvotes;
}
function getProposalStatus(uint256 _id) external view returns (bool active) {
return proposals[_id].active;
}
function upvoteProposal(uint256 _id) external returns (uint256 newUpvoteCount) {
require(daoToken.getAddressBalance(address(msg.sender)) > 0, "You need to hold DAO tokens for governance");
if (!proposals[_id].upvotedAddresses[address(msg.sender)]) {
proposals[_id].upvotes++;
proposals[_id].upvotedAddresses[address(msg.sender)] = true;
}
return proposals[_id].upvotes;
}
function reOpenProposalStatus(uint256 _id) external returns (bool newActiveStatus) {
require(dev == address(msg.sender));
proposals[_id].active = true;
return proposals[_id].active;
}
function closeProposal(uint256 _id) external returns (bool newActiveStatus) {
require(dev == address(msg.sender));
proposals[_id].active = false;
return proposals[_id].active;
}
}