-
Notifications
You must be signed in to change notification settings - Fork 115
/
updateRewardAccount.ts
46 lines (38 loc) · 1.52 KB
/
updateRewardAccount.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
import WorkingGroupsCommandBase from '../../base/WorkingGroupsCommandBase'
import { apiModuleByGroup } from '../../Api'
import { validateAddress } from '../../helpers/validation'
import chalk from 'chalk'
import ExitCodes from '../../ExitCodes'
export default class WorkingGroupsUpdateRewardAccount extends WorkingGroupsCommandBase {
static description = 'Updates the worker/lead reward account (requires current role account to be selected)'
static args = [
{
name: 'address',
required: false,
description: 'New reward account address (if omitted, can be provided interactivel)',
},
]
static flags = {
...WorkingGroupsCommandBase.flags,
}
async run(): Promise<void> {
let { address } = this.parse(WorkingGroupsUpdateRewardAccount).args
// Worker-only gate
const worker = await this.getRequiredWorkerContext()
if (!worker.reward.valuePerBlock) {
this.error('There is no reward relationship associated with this role!', { exit: ExitCodes.InvalidInput })
}
if (!address) {
address = await this.promptForAnyAddress('Select new reward account')
} else if (validateAddress(address) !== true) {
this.error('Invalid address', { exit: ExitCodes.InvalidInput })
}
await this.sendAndFollowNamedTx(
await this.getDecodedPair(worker.roleAccount),
apiModuleByGroup[this.group],
'updateRewardAccount',
[worker.workerId, address]
)
this.log(chalk.green(`Successfully updated the reward account to: ${chalk.magentaBright(address)})`))
}
}