This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
hive.js
61 lines (59 loc) · 1.96 KB
/
hive.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
const config = require('./config.js');
const { hiveClient } = require('./index');
const Hive = {
getOwners: function (account) {
return new Promise(function (resolve, reject) {
hiveClient.api.setOptions({ url: config.startURL });
hiveClient.api.getAccounts([account], function (err, result) {
hiveClient.api.setOptions({ url: config.clientURL });
if (err) reject(err);
else resolve(result[0].active.account_auths);
});
});
},
getAccounts: function (accounts) {
return new Promise(function (resolve, reject) {
hiveClient.api.setOptions({ url: config.startURL });
hiveClient.api.getAccounts(accounts, function (err, result) {
hiveClient.api.setOptions({ url: config.clientURL });
if (err) reject(err);
else resolve(result);
});
});
},
getRecentReport: function (account, walletOperationsBitmask) {
return new Promise(function (resolve, reject) {
hiveClient.api.setOptions({ url: "https://api.deathwing.me/" });
hiveClient.api.getAccountHistory(
account,
-1,
100,
...walletOperationsBitmask,
function (err, result) {
hiveClient.api.setOptions({ url: config.clientURL });
if (err) reject(err);
for(var i = 0; i < result.length;i++){
}
let ebus = result.filter(
(tx) => tx[1].op[1].id === `${config.prefix}report`
),
recents = [];
for (i = ebus.length - 1; i >= 0; i--) {
if (
JSON.parse(ebus[i][1].op[1].json).hash &&
parseInt(JSON.parse(ebus[i][1].op[1].json).block) >
parseInt(config.override)
) {
recents.push([
JSON.parse(ebus[i][1].op[1].json).hash,
JSON.parse(ebus[i][1].op[1].json).block,
]);
}
}
resolve(recents.shift());
}
);
});
},
};
exports.Hive = Hive