forked from status-im/topic-democracy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
topicPoll.js
54 lines (44 loc) · 1.22 KB
/
topicPoll.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
const web3 = require('web3');
const StatusJSApp = require('status-js-api');
/**
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
*/
const modes = ["free answer", "multi option", "single option"]
export default class TopicPoll extends StatusJSApp {
joined = [];
constructor(statusdUrl, privKey){
this.topics = {};
this.connect(statusdUrl, privKey);
}
async create(topic, data) {
await this.checkTopic(topic);
const data = {
pollId,
vote
}
this.topicSend(topic, JSON.stringify(data));
}
async vote(topic, pollId, vote) {
await this.checkTopic(topic);
const data = {
pollId,
vote
}
this.topicSend(topic, JSON.stringify(data));
}
getDataHash(pollData) {
web3.utils.soliditySha3(...pollData)
}
getPollId(timestamp, dataHash) {
web3.utils.soliditySha3(timestamp, dataHash)
}
async checkTopic(topic) {
if(!this.topics[topic]) {
await this.joinChat(topic);
topics[topic]=true;
}
}
async topicSend(topic, text) {
await this.sendGroupMessage(topic, text);
}
};