forked from dluxio/dlux_open_token
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hive.js
33 lines (31 loc) · 1.46 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
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)
})
})
},
getRecentReport: function (account, walletOperationsBitmask){
return new Promise(function (resolve, reject){
hiveClient.api.setOptions({ url: config.startURL });
hiveClient.api.getAccountHistory(account, -1, 100, ...walletOperationsBitmask, function(err, result) {
hiveClient.api.setOptions({ url: config.clientURL });
if(err) reject(err)
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