-
Notifications
You must be signed in to change notification settings - Fork 115
/
verifyValidator.ts
59 lines (50 loc) · 2.04 KB
/
verifyValidator.ts
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
import { flags } from '@oclif/command'
import WorkingGroupsCommandBase from '../../base/WorkingGroupsCommandBase'
import { WorkingGroups } from '../../Types'
import { VerifyValidator, RemarkMetadataAction } from '@joystream/metadata-protobuf'
import { metadataToString } from '../../helpers/serialization'
import Long from 'long'
import chalk from 'chalk'
export default class VerifyValidatorCommand extends WorkingGroupsCommandBase {
static description =
'Verify or un-verify the membership profile bound to a validator account. Available to membership workers only.'
static args = [
{
name: 'memberId',
required: true,
description: 'ID of the membership bound to the validator account.',
},
]
static flags = {
unverify: flags.boolean({
default: false,
description: 'Whether the profile should be un-verified.',
}),
...WorkingGroupsCommandBase.flags,
}
async run(): Promise<void> {
const worker = await this.getRequiredWorkerContext()
if (!worker || this.group !== WorkingGroups.Membership) {
return this.error('Only membership workers can perform this command')
}
const { args, flags } = this.parse(VerifyValidatorCommand)
const memberId = Long.fromNumber(args.memberId)
const verifyValidator = !flags.unverify
const meta = new RemarkMetadataAction({
verifyValidator: new VerifyValidator({
memberId,
isVerified: verifyValidator,
}),
})
const message = metadataToString(RemarkMetadataAction, meta)
const keyPair = await this.getDecodedPair(worker.roleAccount)
const result = await this.sendAndFollowNamedTx(keyPair, 'membershipWorkingGroup', 'workerRemark', [
worker.workerId,
message,
])
const block = result.status.isInBlock ? result.status.asInBlock : undefined
const successMessage = `The validator profile ${args.memberId} was set to${verifyValidator ? '' : ' not'} verified.`
const inBlockMessage = block ? `(In block ${block})` : ''
this.log(chalk.green(`${successMessage} ${inBlockMessage}`))
}
}