-
Notifications
You must be signed in to change notification settings - Fork 115
/
channelPayoutProofAtByteOffset.ts
54 lines (48 loc) · 1.78 KB
/
channelPayoutProofAtByteOffset.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 { channelPayoutProofAtByteOffset } from '@joystream/js/content'
import { readBytesFromFile } from '@joystream/js/utils'
import { Command, flags } from '@oclif/command'
import { displayCollapsedRow } from '../../helpers/display'
export default class ChannelPayoutProofAtByteOffset extends Command {
static description = 'Get channel payout record from serialized payload at given byte.'
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'],
}),
}
static args = [
{
name: 'byteOffset',
required: true,
description: 'Byte offset of payout record from start of payload',
},
]
async run(): Promise<void> {
const { path, url } = this.parse(ChannelPayoutProofAtByteOffset).flags
const { byteOffset } = this.parse(ChannelPayoutProofAtByteOffset).args
const start = Number.parseInt(byteOffset as string)
try {
if (!(path || url)) {
this.error('One of path or url should be provided')
}
const payoutProof = path
? await channelPayoutProofAtByteOffset(readBytesFromFile('PATH', path), start)
: await channelPayoutProofAtByteOffset(readBytesFromFile('URL', url!), start)
displayCollapsedRow({
'Channel Id': payoutProof.channelId,
'Cumulative Payout Earned': payoutProof.cumulativeRewardEarned,
'Merkle Proof Branch': JSON.stringify(payoutProof.merkleBranch),
'Payout reason': payoutProof.reason,
})
console.log(payoutProof.merkleBranch)
} catch (error) {
this.error(`Invalid byte offset for payout record ${error}`)
}
}
}