-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexplorer.service.js
75 lines (67 loc) · 1.89 KB
/
explorer.service.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
75
/**
* Node Trinity source code
* See LICENCE file at the top of the source tree
*
* ******************************************
*
* explorer.service.js
* Explorer service business logic
*
* ******************************************
*
* Authors: K. Zhidanov, A. Prudanov, M. Vasil'ev
*/
const Utils = require('./Utils');
class ExplorerService {
constructor(db) {
this.db = db;
}
async get_csup(){
let res = (await this.get_stats(['csup']));
return res.csup;
}
async get_tsup(){
let tsup = BigInt((await this.db.get_tokens([Utils.ENQ_TOKEN_NAME]))[0].total_supply);
return tsup.toString();
}
async get_msup(){
let msup = BigInt((await this.db.get_tokens([Utils.ENQ_TOKEN_NAME]))[0].max_supply);
return msup.toString();
}
async get_network_hashrate(){
let res = (await this.get_stats(['network_hashrate']));
return (res.network_hashrate).toString();
}
async get_stats(keys){
let stats = await this.db.get_stats(keys);
stats = stats.reduce((a,c) => {
a[c.key] = c.value;
return a;
}, {});
return stats;
}
}
// This service provides data as a plain text values such as 338349685.9920000000
class ExplorerServicePlain extends ExplorerService {
constructor(db) {
super(db);
}
async get_csup(){
let amount = await super.get_csup();
return Utils.strToFloat(amount);
}
async get_tsup(){
let tsup = await super.get_tsup();
return Utils.strToFloat(tsup);
}
async get_msup(){
let msup = await super.get_msup();
return Utils.strToFloat(msup);
}
async get_network_hashrate(){
let res = await super.get_network_hashrate();
return res;
}
}
module.exports.ExplorerService = ExplorerService;
module.exports.ExplorerServicePlain = ExplorerServicePlain;