-
Notifications
You must be signed in to change notification settings - Fork 115
/
channelPayoutsPayloadHeader.ts
54 lines (49 loc) · 1.94 KB
/
channelPayoutsPayloadHeader.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
import { ChannelPayoutsMetadata } from '@joystream/metadata-protobuf'
import { serializedPayloadHeader } from '@joystream/js/content'
import { readBytesFromFile } from '@joystream/js/utils'
import { Command, flags } from '@oclif/command'
import chalk from 'chalk'
import { displayCollapsedRow, displayTable } from '../../helpers/display'
export default class ChannelPayoutPayloadHeader extends Command {
static description = 'Get header from serialized payload file.'
static flags = {
path: flags.string({
required: false,
description: 'Path to the protobuf serialized payload file',
exclusive: ['url'],
}),
url: flags.string({
required: false,
description: 'URL to the protobuf serialized payload file',
exclusive: ['path'],
}),
}
async run(): Promise<void> {
const { path, url } = this.parse(ChannelPayoutPayloadHeader).flags
if (!(path || url)) {
this.error('One of path or url should be provided')
}
try {
const serializedHeader = path
? await serializedPayloadHeader(readBytesFromFile('PATH', path))
: await serializedPayloadHeader(readBytesFromFile('URL', url!))
const header = ChannelPayoutsMetadata.Header.decode(serializedHeader)
this.log(
chalk.green(`Serialized payout header is ${chalk.cyanBright(Buffer.from(serializedHeader).toString('hex'))}\n`)
)
displayCollapsedRow({
'Payload Size (in bytes)': header.payloadLengthInBytes.toString(),
'Header Size (in bytes)': header.headerLengthInBytes.toString(),
'Number of channels': header.numberOfChannels,
})
displayTable(
(header.channelPayoutByteOffsets || []).map(({ channelId, byteOffset }) => ({
'Channel Id': channelId.toString(),
'Byte offset of channel record': byteOffset.toString(),
}))
)
} catch (error) {
this.error(`Invalid serialized input for decoding header ${error}`)
}
}
}