-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter.js
More file actions
93 lines (75 loc) · 2.59 KB
/
adapter.js
File metadata and controls
93 lines (75 loc) · 2.59 KB
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
let sprintf = require(`sprintf-js`).sprintf
, instance = null
;
class Adapter {
constructor() {
this.name = `weku`;
this.connection = require(`@steemit/steem-js`);
this.reconnect();
}
static instance() {
if (null === instance) {
instance = new Adapter();
}
return instance;
}
reconnect() {
this.connection.api.setOptions({ url: `wss://news.weku.io:8190` });
this.connection.config.set(`address_prefix`, `WKA`);
this.connection.config.set(`chain_id`, `b24e09256ee14bab6d58bfa3a4e47b0474a73ef4d6c47eeea007848195fa085e`);
}
async processAccountInfo(username, callback) {
this.reconnect();
this.connection.api.getAccounts([username], function (err, result) {
if (err) {
console.error(sprintf(`Adapter: Failed to load account info: "%s"`, username));
console.error(err);
return;
}
if (result.length < 1) {
console.error(sprintf(`Adapter: Account "%s" not found.`, username));
return;
}
callback(result[0]);
});
}
async processGetContent(author, permlink, successCallback, failCallback) {
this.reconnect();
this.connection.api.getContent(author, permlink, function (err, result) {
if (err) {
console.info(author, permlink);
console.error(`Error during getContent appeared.`);
console.error(err);
if (failCallback) {
failCallback()
}
return;
}
if (result.id === 0) {
console.info(author, permlink);
console.error(`Post not found.`);
if (failCallback) {
failCallback(result);
}
return;
}
successCallback(result);
});
}
async processVote(wif, voter, author, permlink, weight, successCallback, failCallback) {
this.reconnect();
this.connection.broadcast.vote(wif, voter, author, permlink, weight, function(err, result) {
if (err) {
console.info(voter, author, permlink, weight);
console.error(`Error during vote appeared.`);
console.error(err);
if (failCallback) {
failCallback(result);
}
return;
}
successCallback(result);
});
}
}
module.exports.Adapter = Adapter;