This repository has been archived by the owner on May 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd.js
121 lines (113 loc) · 4.17 KB
/
cmd.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict'
const commander = require('commander')
const db = require('./models/mongodb')
const _ = require('lodash')
const cmdValidator = require('./commands/validator')
const { updatePenalty } = require('./commands/penalty')
const { updateStatus } = require('./commands/status')
const web3Rpc = require('./models/blockchain/web3rpc')
commander
.version('0.1.0')
.description('Candidate Management Commands')
commander
.command('validator blockNumber')
.alias('v')
.description('Re-crawl tx vote/unvote/resign/propose/withdraw')
.action(async (blockNumber) => {
return cmdValidator.run(parseInt(blockNumber))
})
commander
.command('list')
.alias('l')
.description('List candidates')
.action(() => {
return db.Candidate.find()
.then(candidates => {
candidates.forEach(c => {
console.log('ID:', c.candidate, '\n',
'name:', c.name || 'null', '\n',
'nodeId:', c.nodeId || 'null', '\n',
'hardware:', c.hardware || 'null', '\n',
'dc-name:', (c.dataCenter || {}).name || 'null', '\n',
'dc-location:', (c.dataCenter || {}).location || 'null', '\n',
'github:', (c.socials || {}).github || 'null', '\n',
'linkedin:', (c.socials || {}).linkedin || 'null', '\n',
'email:', (c.socials || {}).email || 'null', '\n'
)
console.log('===')
})
process.exit()
})
})
commander
.command('update <id>')
.alias('u')
.description('Update candidate information')
.option('-n, --name <name>', 'Name of Candidate')
.option('-i, --nodeId <nodeId>', 'nodeId of Candidate')
.option('-dcn, --dc-name <dcName>', 'Name of Datacenter')
.option('-dcl, --dc-location <dcLocation>', 'Location of Datacenter')
.option('-hw, --hardware <hardware>', 'Harware Information')
.option('-gh, --scGithub <github>', 'Github Information')
.option('-lkn, --scLinkedin <linkedin>', 'Linkedin Information')
.option('-em, --scEmail <email>', 'Email Information')
.action(async (id, options) => {
let set = _.pick(options, ['nodeId', 'hardware'])
if (typeof options.name === 'string') {
set['name'] = options.name
}
if (options.dcName) {
set['dataCenter.name'] = options.dcName
}
if (options.dcLocation) {
set['dataCenter.location'] = options.dcLocation
}
if (options.scGithub) {
set['socials.github'] = options.scGithub
}
if (options.scLinkedin) {
set['socials.linkedin'] = options.scLinkedin
}
if (options.scEmail) {
set['socials.email'] = options.scEmail
}
let u = await db.Candidate.updateOne({
candidate: id
}, {
$set: set
})
console.log(u)
process.exit()
})
commander
.command('update-penalty')
.alias('up')
.description('Update penalty table')
.action(async () => {
let latestBlockNumber = await web3Rpc.eth.getBlockNumber()
const num1To = parseInt(latestBlockNumber / 3) - 1
const num2From = latestBlockNumber + 1
const num2To = parseInt(latestBlockNumber / 3) * 2
const num3From = (parseInt(latestBlockNumber / 3) * 2) + 1
await Promise.all([
updatePenalty(0, num1To),
updatePenalty(num2From, num2To),
updatePenalty(num3From, latestBlockNumber)
])
process.exit()
})
commander
.command('update-status')
.alias('up')
.description('Update status table')
.description('WARNING')
.description('From epoch should exist in the status table first')
.option('-f, --fromEpoch <fromEpoch>', 'To epoch')
.option('-t, --toEpoch <toEpoch>', 'To epoch')
.action(async (input) => {
const fromEpoch = input.fromEpoch || null
const toEpoch = input.toEpoch || null
await updateStatus(fromEpoch, toEpoch)
process.exit()
})
commander.parse(process.argv)