This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
executable file
·74 lines (64 loc) · 2.06 KB
/
index.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
const request = require('request');
function fromAscii(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var code = str.charCodeAt(i);
var n = code.toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return "0x" + hex;
};
var StatusDev = function(options) {
this.url = "http://" + options.ip + ":5561";
};
function requestOptions(url, body) {
return {
url: url,
method: "POST",
timeout: 3000,
json: true,
body: body};
}
StatusDev.prototype.addContact = function(contactData, cb) {
request(requestOptions(this.url + "/add-dapp", { encoded: fromAscii(contactData) })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.removeContact = function(contactData, cb) {
request(requestOptions(this.url + "/remove-dapp", { encoded: fromAscii(contactData) })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.refreshContact = function(contactData, cb) {
request(requestOptions(this.url + "/dapp-changed", { encoded: fromAscii(contactData) })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.switchNode = function(rpcUrl, cb) {
request(requestOptions(this.url + "/switch-node", {encoded: fromAscii(JSON.stringify({"url": rpcUrl}))})
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.listDApps = function(cb) {
request(requestOptions(this.url + "/list", {})
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.getLog = function(identity, cb) {
request(requestOptions(this.url + "/log", { identity: identity })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
module.exports = StatusDev;