-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo6_wotb_sentries.js
59 lines (46 loc) · 1.75 KB
/
demo6_wotb_sentries.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
#!/usr/bin/env node
"use strict";
const co = require('co');
const duniter = require('duniter');
const constants = require('duniter/app/lib/constants');
const HOME_DUNITER_DATA_FOLDER = 'rml8';
// Use netobs data folder
if (!process.argv.includes('--mdb')) {
process.argv.push('--mdb');
process.argv.push(HOME_DUNITER_DATA_FOLDER);
}
// Default action = start
if (process.argv.length === 4) process.argv.push('start');
// Disable Duniter logs
duniter.statics.logger.mute();
duniter.statics.cli((duniterServer) => co(function*() {
try {
/****************************************
* SPECIALISATION
***************************************/
// Trouve les points de contrôle efficacement grâce au module C (nommé "wotb")
const head = yield duniterServer.dal.getCurrentBlockOrNull();
const membersCount = head ? head.membersCount : 0;
let dSen;
if (head.version <= 3) {
dSen = Math.ceil(constants.CONTRACT.DSEN_P * Math.exp(Math.log(membersCount) / duniterServer.conf.stepMax));
} else {
dSen = Math.ceil(Math.pow(membersCount, 1 / duniterServer.conf.stepMax));
}
const pointsDeControle = duniterServer.dal.wotb.getSentries(dSen);
// Récupère les identités complètes
const identitesDeControle = yield pointsDeControle.map((sentryWotID) => {
// Va chercher en base de données l'identité par son identifiant wotb
return duniterServer.dal.idtyDAL.query('SELECT * FROM idty WHERE wotb_id = ?', [sentryWotID]);
});
// Affichage
for (const identite of identitesDeControle) {
console.log('Point de contrôle : %s', identite[0].uid);
}
process.exit(0);
/****************************************/
} catch (e) {
console.error(e);
process.exit(1);
}
}));