-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
226 lines (219 loc) · 4.84 KB
/
index.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
const {
createAsset,
mint,
burn,
assetDetails,
accountDetails,
approvals,
freeze,
thaw,
freezeAsset,
thawAsset,
transfer,
forceTransfer,
transferKeepAlive,
approveTransfer,
cancelApproval,
transferApproved,
destroy,
touchOther,
block,
setTeam,
transferOwnership,
setMetadata,
clearMetadata,
assetMetadata,
createMultisig,
createMultisigTx,
approveMultisigTx,
transferNative,
nativeBalance,
batchBurn,
} = require('./blockchainServices');
const inquirer = require('inquirer');
const {
Calls,
} = require('./blockchainServices/palletCalls/helpers/blockchainCalls');
const { getLedgerAddress } = require('./blockchainServices/setup');
const choices = [
'Create Asset',
'Mint',
'Burn',
'Batch Burn',
'Transfer',
'Force Transfer',
'Transfer Keep Alive',
'Approve Transfer',
'Cancel Approval',
'Transfer Approved',
'Transfer Native',
'Native Balance',
'Block',
'Touch Other',
'Freeze',
'Thaw',
'Freeze Asset',
'Thaw Asset',
'Set Team',
'Transfer Ownership',
'Set Metadata',
'Clear Metadata',
'Asset Metadata',
'Create Multisig',
'Create Multisig Tx',
'Approve Multisig Tx',
'Destroy',
'Asset Details',
'Account Details',
'Approvals Details',
'Display Ledger Address',
];
const networks = ['Kusama Asset Hub', 'Polkadot Asset Hub', 'local'];
const network = {
type: 'list',
name: 'chosenNetwork',
message: 'Select Network',
pageSize: choices.length,
choices: networks,
config: '',
};
const intro = {
type: 'list',
name: 'action',
message: 'Select Action',
pageSize: choices.length,
choices: choices,
};
const main = async () => {
intro.pageSize =
intro.choices.length < process.stdout.rows
? intro.choices.length
: process.stdout.rows - 2;
const { chosenNetwork } = await inquirer.prompt(network);
handleNetwork(chosenNetwork);
const { action } = await inquirer.prompt(intro);
const calls = new Calls();
switch (action) {
case 'Create Asset':
await createAsset(calls);
break;
case 'Mint':
await mint(calls);
break;
case 'Burn':
await burn(calls);
break;
case 'Batch Burn':
await batchBurn(calls);
break;
case 'Transfer':
await transfer(calls);
break;
case 'Force Transfer':
await forceTransfer(calls);
break;
case 'Transfer Keep Alive':
await transferKeepAlive(calls);
break;
case 'Approve Transfer':
await approveTransfer(calls);
break;
case 'Cancel Approval':
await cancelApproval(calls);
break;
case 'Transfer Approved':
await transferApproved(calls);
break;
case 'Freeze':
await freeze(calls);
break;
case 'Thaw':
await thaw(calls);
break;
case 'Freeze Asset':
await freezeAsset(calls);
break;
case 'Thaw Asset':
await thawAsset(calls);
break;
case 'Set Team':
await setTeam(calls);
break;
case 'Transfer Ownership':
await transferOwnership(calls);
break;
case 'Destroy':
await destroy(calls);
break;
case 'Touch Other':
await touchOther(calls);
break;
case 'Block':
await block(calls);
break;
case 'Asset Details':
await assetDetails();
break;
case 'Account Details':
await accountDetails();
break;
case 'Approvals Details':
await approvals();
break;
case 'Set Metadata':
await setMetadata(calls);
break;
case 'Clear Metadata':
await clearMetadata(calls);
break;
case 'Asset Metadata':
await assetMetadata();
break;
case 'Create Multisig':
await createMultisig();
break;
case 'Create Multisig Tx':
await createMultisigTx(calls);
break;
case 'Approve Multisig Tx':
await approveMultisigTx(calls);
break;
case 'Transfer Native':
await transferNative(calls);
break;
case 'Native Balance':
await nativeBalance(calls);
break;
case 'Display Ledger Address (Ledger Generic App)':
console.log(await getLedgerAddress());
break;
default:
throw new Error('invalid choice');
}
main();
};
const handleNetwork = (chosenNetwork) => {
let setNetwork = {
name: '',
endpoint: '',
};
switch (chosenNetwork) {
case networks[0]:
setNetwork.endpoint = 'wss://kusama-asset-hub-rpc.polkadot.io';
setNetwork.name = 'Kusama Asset Hub';
setNetwork.config='Kusama'
break;
case networks[1]:
setNetwork.endpoint = 'wss://polkadot-asset-hub-rpc.polkadot.io';
setNetwork.name = 'Polkadot Asset Hub';
setNetwork.config='Polkadot'
break;
case networks[2]:
setNetwork.endpoint = 'ws://localhost:9944';
setNetwork.name = 'local';
setNetwork.config='local'
break;
}
global.network = setNetwork;
};
main();