-
Notifications
You must be signed in to change notification settings - Fork 115
/
updateChannelPayoutsProposal.ts
124 lines (116 loc) · 3.98 KB
/
updateChannelPayoutsProposal.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
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
122
123
124
import { generateCommitmentFromPayloadFile } from '@joystream/js/content'
import { flags } from '@oclif/command'
import chalk from 'chalk'
import UploadCommandBase from '../../base/UploadCommandBase'
import fs from 'fs'
import { createType } from '@joystream/types'
import { readBytesFromFile } from '@joystream/js/utils'
export default class UpdateChannelPayoutsProposal extends UploadCommandBase {
static description = 'Create channel payouts proposal.'
static flags = {
title: flags.string({
char: 't',
required: true,
description: 'Title of the proposal',
}),
description: flags.string({
char: 'd',
required: true,
description: 'Description of the proposal',
}),
exactExecutionBlock: flags.integer({
char: 'b',
required: false,
description: 'The Block at which the proposal should be automatically executed',
}),
stakingAccountId: flags.string({
char: 's',
required: true,
description: 'Proposer staking account Id',
}),
min: flags.integer({
required: false,
description: 'Minimum cashout amount allowed to a channel',
}),
max: flags.integer({
required: false,
description: 'Maximum cashout amount allowed to a channel',
}),
channelCashoutsEnabled: flags.boolean({
char: 'e',
required: false,
description: 'Whether cashouts be enabled/disabled',
}),
payloadFilePath: flags.string({
char: 'p',
required: false,
description: 'Path to protobuf serialized file containing channel payouts payload',
}),
...UploadCommandBase.flags,
}
async run(): Promise<void> {
const {
title,
description,
exactExecutionBlock,
stakingAccountId,
min,
max,
channelCashoutsEnabled,
payloadFilePath,
} = this.parse(UpdateChannelPayoutsProposal).flags
// Context
const member = await this.getRequiredMemberContext()
const keypair = await this.getDecodedPair(member.membership.controllerAccount)
const expectedDataSizeFee = await this.getApi().dataObjectPerMegabyteFee()
const expectedDataObjectStateBloatBond = await this.getApi().dataObjectStateBloatBond()
const minCashoutAllowed = min || (await this.getOriginalApi().query.content.minCashoutAllowed())
const maxCashoutAllowed = max || (await this.getOriginalApi().query.content.maxCashoutAllowed())
this.jsonPrettyPrint(
JSON.stringify({
title,
description,
exactExecutionBlock,
stakingAccountId,
minCashoutAllowed,
maxCashoutAllowed,
channelCashoutsEnabled,
})
)
await this.requireConfirmation('Do you confirm the provided input?', true)
const result = await this.sendAndFollowNamedTx(keypair, 'proposalsCodex', 'createProposal', [
{
memberId: member.id,
title,
description,
exactExecutionBlock,
stakingAccountId,
},
{
UpdateChannelPayouts: createType('PalletContentUpdateChannelPayoutsParametersRecord', {
commitment: payloadFilePath
? await generateCommitmentFromPayloadFile(readBytesFromFile('PATH', payloadFilePath))
: null,
payload: payloadFilePath
? {
objectCreationParams: {
size_: fs.statSync(payloadFilePath).size,
ipfsContentId: await this.calculateFileHash(payloadFilePath),
},
expectedDataSizeFee,
expectedDataObjectStateBloatBond,
}
: null,
minCashoutAllowed,
maxCashoutAllowed,
channelCashoutsEnabled: channelCashoutsEnabled ?? true,
}),
},
])
const proposalCreatedEvent = this.findEvent(result, 'proposalsCodex', 'ProposalCreated')
if (proposalCreatedEvent) {
const [proposalId] = proposalCreatedEvent.data
this.log(chalk.green(`Channel Payouts proposal with ID ${chalk.cyanBright(proposalId.toString())} created!`))
}
}
}