-
Notifications
You must be signed in to change notification settings - Fork 115
/
constructUnsignedTx.ts
72 lines (62 loc) · 2.47 KB
/
constructUnsignedTx.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
import { flags } from '@oclif/command'
import { blake2AsHex } from '@polkadot/util-crypto'
import AdvancedTransactionsCommandBase from '../../base/AdvancedTransactionsCommandBase'
import { registry } from '@joystream/types'
import { OptionsWithMeta } from '@substrate/txwrapper-core'
import { ensureOutputFileIsWriteable } from '../../helpers/InputOutput'
export default class CreateUnsignedTxCommand extends AdvancedTransactionsCommandBase {
static description = 'Create a simple unsigned transaction, for signing offline.'
static flags = {
address: flags.string({
required: true,
description: 'The address that is performing the transaction.',
}),
module: flags.string({
required: true,
description: 'The module of the extrinsic',
}),
method: flags.string({
required: true,
description: 'The method of the extrinsic',
}),
output: flags.string({
char: 'o',
required: true,
description: 'Path to the file where the output JSON should be saved.',
}),
lifetime: flags.integer({
required: false,
description:
'Lifetime of the transaction, from constructed to included in a block, in blocks before it becomes invalid. Must be a power of two between 4 and 65536',
}),
tip: flags.integer({
required: false,
default: 0,
description: 'Optional "tip" (in base value) for faster block inclusion.',
}),
nonceIncrement: flags.integer({
required: false,
default: 0,
description:
'If you are preparing multiple transactions from the samme account, before broadcasting them, you need to increase the nonce by 1 for each. This value will be added to the nonce read from the chain.',
}),
}
async run(): Promise<void> {
const { address, module, method, lifetime, tip, nonceIncrement, output } = this.parse(CreateUnsignedTxCommand).flags
ensureOutputFileIsWriteable(output)
const unsignedMethod = await this.promptForTxMethod(module, method)
const txInfo = await this.getTxInfo(address, unsignedMethod, nonceIncrement, lifetime, tip)
const optionsWithMeta: OptionsWithMeta = {
metadataRpc: `0x${txInfo.metadataRpc.slice(2)}`,
registry,
}
const unsigned = await this.getDefinedMethod(txInfo, optionsWithMeta)
const call = unsigned.method
const callHash: string = blake2AsHex(call)
const txData = {
call,
callHash,
}
this.createTransactionReadyForSigning(unsigned, output, txData)
}
}