-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproposal.html
264 lines (212 loc) · 11.7 KB
/
proposal.html
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="./node_modules/web3/dist/web3.min.js"></script>
</head>
<body>
<div class="container">
<h1>Smart Share</h1>
<h2>Proposal 1</h2>
<label for="name" class="col-lg-2 control-label">Creator Address</label>
<h4 id="creator"></h4>
<label for="name" class="col-lg-2 control-label">Recipient Address</label>
<h4 id="recipient"></h4>
<label for="name" class="col-lg-2 control-label">Description</label>
<h4 id="description"></h4>
<label for="name" class="col-lg-2 control-label">Item Price</label>
<h4 id="price"></h4>
<label for="name" class="col-lg-2 control-label">Deposit Amount</label>
<h4 id="amount"></h4>
<label for="name" class="col-lg-2 control-label">Begin Day</label>
<h4 id="bday"></h4>
<label for="name" class="col-lg-2 control-label">End Day</label>
<h4 id="eday"></h4>
<label for="name" class="col-lg-2 control-label">Voting Deadline</label>
<h4 id="vdeadline"></h4>
<label for="name" class="col-lg-2 control-label">Proposal Voting Status</label>
<h4 id="open"></h4>
<label for="name" class="col-lg-2 control-label">Proposal Verification Status</label>
<h4 id="status"></h4>
<label for="name" class="col-lg-2 control-label">Proposal Hash</label>
<h4 id="hash"></h4>
<label for="name" class="col-lg-2 control-label">Proposal Verification Status</label>
<h4 id="status"></h4>
<label for="name" class="col-lg-2 control-label"># of votes for approval</label>
<h4 id="yescount"></h4>
<label for="name" class="col-lg-2 control-label"># of votes for denial</label>
<h4 id="nocount"></h4>
</div>
<div class="container">
<h1>Vote</h1>
<label for="name" class="col-lg-2 control-label">Yes or No</label>
<input id="opt" type="text">
<button id="button">Vote Proposal</button>
<button id="button2">Verify Proposal</button>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script>
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
var proposalmanagerContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"executeProposal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getNocount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getPassed","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"}],"name":"verifyProposal","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getBeginDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"minVoteCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getYescount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getDescription","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"allowedRecipients","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getRecipient","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getOpen","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maxVoteNoCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getDeadline","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposalDeposit","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"_recipient","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_transactionData","type":"uint256"}],"name":"vote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getAmount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"yesorno","type":"bool"}],"name":"simpleVote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getDeposit","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getCreator","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_recipient","type":"address"}],"name":"add2whitelist","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_recipient","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_description","type":"string"},{"name":"_transactionData","type":"uint256"},{"name":"_debatingPeriod","type":"uint64"},{"name":"_beginDay","type":"uint256"},{"name":"_endDay","type":"uint256"}],"name":"newProposal","outputs":[{"name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getEndDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"gethash","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"}]);
// Account in 'Run' tab in the Remix IDE
//web3.eth.defaultAccount = '0x182cf9eeb6c0bab3f1156a7e51a95df436c0f13c';
web3.eth.defaultAccount = web3.eth.accounts[1];
// get smart contract account/address from remix
var proposalMgr = proposalmanagerContract.at('0xcc56b384c73ff1f3162401ee216dc6de466ff7e1');
console.log(proposalMgr);
// creator
proposalMgr.getCreator(0, function(error, result){
if(!error) {
$("#creator").html(result);
console.log(result);
}
else
console.error(error);
});
// recipient
proposalMgr.getRecipient(0, function(error, result){
if(!error) {
$("#recipient").html(result);
console.log(result);
}
else
console.error(error);
});
// description
proposalMgr.getDescription(0, function(error, result){
if(!error) {
$("#description").html(result);
console.log(result);
}
else
console.error(error);
});
// item price
proposalMgr.getAmount(0, function(error, result){
if(!error) {
$("#price").html(result.c[0]);
console.log(JSON.stringify(result));
}
else
console.error(error);
});
// deposit amount
proposalMgr.getDeposit(0, function(error, result){
if(!error) {
$("#amount").html(result.c[0]);
console.log(result);
}
else
console.error(error);
});
// begin day
proposalMgr.getBeginDay(0, function(error, result){
if(!error) {
$("#bday").html(result.c[0]);
console.log(result);
}
else
console.error(error);
});
// end day
proposalMgr.getEndDay(0, function(error, result){
if(!error) {
$("#eday").html(result.c[0]);
console.log(result);
}
else
console.error(error);
});
// voting deadline
proposalMgr.getDeadline(0, function(error, result){
if(!error) {
$("#vdeadline").html(result.c[0]);
console.log(result[0]);
}
else
console.error(error);
});
// voting status
proposalMgr.getOpen(0, function(error, result){
if(!error) {
if(result == true) {
$("#open").html("Proposal is open for voting");
}
else {
$("#open").html("Proposal is closed for voting");
}
console.log(result);
}
else
console.error(error);
});
// verification status
proposalMgr.getPassed(0, function(error, result){
if(!error) {
if(result == true) {
$("#status").html("Proposal has been approved");
}
else {
$("#status").html("Proposal has not yet been approved");
}
console.log(result);
}
else
console.error(error);
});
// proposal hash
proposalMgr.gethash(0, function(error, result){
if(!error) {
$("#hash").html(result);
console.log(result);
}
else
console.error(error);
});
// yes count
proposalMgr.getYescount(0, function(error, result){
if(!error) {
$("#yescount").html(result.c[0]);
console.log(result);
}
else
console.error(error);
});
// no count
proposalMgr.getNocount(0, function(error, result){
if(!error) {
$("#nocount").html(result.c[0]);
console.log(result);
}
else
console.error(error);
});
// process vote button
$("#button").click(function() {
console.log($("#opt").val().toLowerCase());
if($("#opt").val().toLowerCase() == 'yes') {
console.log("vote yes");
proposalMgr.simpleVote(0, true);
}
else {
console.log("vote no");
proposalMgr.simpleVote(0, false);
}
});
// process verify button
$("#button2").click(function() {
proposalMgr.verifyProposal(0);
});
//function(){window.location.reload();}
</script>
</body>
</html>