This repository has been archived by the owner on Sep 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
81 lines (78 loc) · 2.51 KB
/
app.js
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
function listSnapshots() {
$.get('/snapshotlist', (snapshotList) => {
let snapshotsHtml = '';
$.each(snapshotList, (index, obj) => {
snapshotsHtml += '<tr><td>';
if (obj.filename.startsWith('snapshot')) {
let time = obj.filename.substring(8, 25);
time = time.replace('T', ' ');
snapshotsHtml += time;
snapshotsHtml += '</td><td>';
const votes = JSON.parse(obj.data);
const voteCount = {
Dewey: 0,
Truman: 0,
};
for (let n = 0; n < votes.length; n += 1) {
if (votes[n].vote === 'Truman') {
voteCount.Truman += 1;
} else if (votes[n].vote === 'Dewey') {
voteCount.Dewey += 1;
}
}
snapshotsHtml += `Dewey: ${voteCount.Dewey}, Truman: ${voteCount.Truman}`;
} else {
snapshotsHtml += 'Voter list</td><td></td>';
}
snapshotsHtml += '</td><td>';
snapshotsHtml += obj.hash;
snapshotsHtml += '</td><td></td></tr>';
});
$('#snapshots').html(snapshotsHtml);
});
}
function verifySnapshots() {
$.get('/verifysnapshots', (snapshotList) => {
let snapshotsHtml = '';
$.each(snapshotList, (index, obj) => {
snapshotsHtml += '<tr><td>';
if (obj.filename.startsWith('snapshot')) {
let time = obj.filename.substring(8, 25);
time = time.replace('T', ' ');
snapshotsHtml += time;
snapshotsHtml += '</td><td>';
const votes = JSON.parse(obj.data);
const voteCount = {
Dewey: 0,
Truman: 0,
};
for (let n = 0; n < votes.length; n += 1) {
if (votes[n].vote === 'Truman') {
voteCount.Truman += 1;
} else if (votes[n].vote === 'Dewey') {
voteCount.Dewey += 1;
}
}
snapshotsHtml += `Dewey: ${voteCount.Dewey}, Truman: ${voteCount.Truman}`;
} else {
snapshotsHtml += 'Voter list</td><td></td>';
}
snapshotsHtml += '</td><td>';
snapshotsHtml += obj.hash;
snapshotsHtml += '</td><td>';
if (obj.verificationEpoch) {
snapshotsHtml += `Bitcoin attests data existed as of ${new Date(obj.verificationEpoch * 1000)}`;
} else {
snapshotsHtml += 'Timestamp cannot be verified';
}
snapshotsHtml += '<td></tr>';
});
$('#snapshots').html(snapshotsHtml);
$( "#verify" ).removeClass( "is-loading" );
});
}
listSnapshots();
$( "#verify" ).click(function() {
$( "#verify" ).addClass( "is-loading" );
verifySnapshots();
});