-
Notifications
You must be signed in to change notification settings - Fork 115
/
generateChannelPayoutsCommitment.ts
39 lines (35 loc) · 1.37 KB
/
generateChannelPayoutsCommitment.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
import { generateCommitmentFromPayloadFile } from '@joystream/js/content'
import { readBytesFromFile } from '@joystream/js/utils'
import { flags } from '@oclif/command'
import chalk from 'chalk'
import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
export default class GenerateChannelPayoutsCommitment extends ContentDirectoryCommandBase {
static description = 'Generate merkle root (commitment) from channel payouts payload.'
static flags = {
path: flags.string({
required: false,
description: 'Path to the serialized payload file',
exclusive: ['url'],
}),
url: flags.string({
required: false,
description: 'URL to the serialized payload file',
exclusive: ['path'],
}),
...ContentDirectoryCommandBase.flags,
}
async run(): Promise<void> {
const { path, url } = this.parse(GenerateChannelPayoutsCommitment).flags
if (!(path || url)) {
this.error('One of path or url should be provided')
}
try {
const commitment = path
? await generateCommitmentFromPayloadFile(readBytesFromFile('PATH', path))
: await generateCommitmentFromPayloadFile(readBytesFromFile('URL', url!))
this.log(chalk.green(`Channel Payout payload merkle root is ${chalk.cyanBright(commitment)}!`))
} catch (error) {
this.error(`Invalid serialized payload input ${error}`)
}
}
}