-
Notifications
You must be signed in to change notification settings - Fork 115
/
deleteChannel.ts
75 lines (68 loc) · 2.63 KB
/
deleteChannel.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
import FeeProfileCommandBase from '../../base/FeeProfileCommandBase'
import { flags } from '@oclif/command'
import { createType } from '@joystream/types'
import chalk from 'chalk'
import { formatBalance } from '@polkadot/util'
const DEFAULT_ASSETS_NUM = 2
export default class FeeProfileDeleteChannel extends FeeProfileCommandBase {
static description = 'Create fee profile of content.delete_channel extrinsic.'
static flags = {
assetsNum: flags.integer({
char: 'a',
default: DEFAULT_ASSETS_NUM,
description: 'Number of assets to use for estimating the costs/returns',
}),
distributionBucketsNum: flags.integer({
char: 'D',
description:
'Number of distribution buckets to use for estimating tx fee.\n' +
"By default this number will be based on the current chain's dynamic bag policy for channel bags",
}),
storageBucketsNum: flags.integer({
char: 'S',
description:
'Number of storage buckets to use for estimating tx fee.\n' +
"By default this number will be based on the current chain's dynamic bag policy for channel bags",
}),
...super.flags,
}
async run(): Promise<void> {
const api = this.getOriginalApi()
const {
assetsNum,
storageBucketsNum: forcedStorageBucketsNum,
distributionBucketsNum: forcedDistributionBucketsNum,
} = this.parse(FeeProfileDeleteChannel).flags
const dataObjectBloatBond = await this.getApi().dataObjectStateBloatBond()
const channelBloatBond = await this.getApi().channelStateBloatBond()
const channelBagPolicy = await api.query.storage.dynamicBagCreationPolicies('Channel')
const storageBucketsNum = forcedStorageBucketsNum || channelBagPolicy.numberOfStorageBuckets.toNumber()
const distributionBucketsNum =
forcedDistributionBucketsNum ||
Array.from(channelBagPolicy.families.entries()).reduce((sum, curr) => (sum += curr[1].toNumber()), 0)
this.log(`Data object bloat bond: ${chalk.cyanBright(formatBalance(dataObjectBloatBond))}`)
this.log(`Channel bloat bond: ${chalk.cyanBright(formatBalance(channelBloatBond))}`)
this.log('Parameters:')
this.jsonPrettyPrint(
JSON.stringify({
storageBucketsNum,
distributionBucketsNum,
assetsNum,
})
)
const tx = api.tx.content.deleteChannel(
{ Member: 0 },
0,
createType('PalletContentChannelBagWitness', {
storageBucketsNum,
distributionBucketsNum,
}),
assetsNum
)
const returns = {
dataObjectsBloatBond: dataObjectBloatBond.muln(assetsNum),
channelBloatBond,
}
await this.profile(tx, undefined, returns)
}
}