/
tezster.js
executable file
·312 lines (280 loc) · 9.82 KB
/
tezster.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/usr/bin/env node
'use strict';
const program = require('commander'),
{ prompt } = require('inquirer'),
fs = require('fs'),
{ TezsterManager } = require('./tezster-manager'),
{ confFile } = require('./modules/cli-constants'),
{ setupStopNodesParameters } = require('./utils/setup.stopNodes.parameters'),
{ accountSetProviderParameters } = require('./utils/account.setProvider.parameters'),
{ accountRestoreWalletParameters } = require('./utils/account.restoreWallet.parameters'),
{ contractDeployParameters } = require('./utils/contracts.deploy.parameters'),
{ contractCallParameters } = require('./utils/contracts.call.parameters'),
{ version } = require('./package.json');
if(!fs.existsSync(confFile)) {
require('./preinstall');
require('./postinstall');
}
const tezstermanager = new TezsterManager();
/******* To setup tezos nodes on user system */
program
.version(version, '-v, --version')
.command('setup')
.description('To set up Tezos nodes')
.action(function(){
tezstermanager.setupNodes();
});
/******* To start local tezos nodes on user system*/
program.command('start-nodes')
.description(`Starts local Tezos nodes`)
.action(function(){
tezstermanager.startNodes();
});
/******* To stop local tezos nodes on user system*/
program.command('stop-nodes')
.usage(`\n(This command provides the interactive shell)`)
.description(`Stops local Tezos nodes`)
.action(function() {
if (process.argv.length > 3) {
console.log('Incorrect usage of stop-nodes command. Correct usage: - tezster stop-nodes');
return;
}
prompt(setupStopNodesParameters).then((setupStopNodesParametersResponse) => {
if(setupStopNodesParametersResponse.response) {
tezstermanager.stopNodes();
}
});
});
/******* To get local nodes current status*/
program.command('node-status')
.description('Fetch Tezos local nodes current status')
.action(function() {
tezstermanager.nodeStatus();
});
/******* To set the rpc-node */
program
.command('set-rpc-node')
.usage(`\n(This command provides the interactive shell)`)
.description('To change the default rpc node provider')
.action(function() {
if (process.argv.length > 3) {
console.log('Incorrect usage of set-rpc-node command. Correct usage: - tezster set-rpc-node');
return;
}
prompt(accountSetProviderParameters).then(accountSetProviderParameterValues => {
tezstermanager.setProvider(accountSetProviderParameterValues);
});
});
/******* To get the current rpc-node */
program
.command('get-rpc-node')
.description('To fetch the current rpc node')
.action(function(){
tezstermanager.getProvider();
});
/******* To get the list accounts */
program
.command('list-accounts')
.description('To fetch all the accounts')
.action(function(){
tezstermanager.listAccounts();
});
/*******for check the balance check */
program
.command('get-balance')
.usage('<account/contract(pkh)>')
.description('To get the balance of account/contracts')
.action(function(){
tezstermanager.getBalance();
});
/******* To Create an account */
program
.command('create-wallet')
.usage('<wallet-label>')
.description('To create a new account')
.action(function(){
tezstermanager.createWallet();
});
/* Restores an testnet faucet account */
program
.command('add-testnet-account')
.usage('<account-label> <absolut-path-to-json-file>')
.description('Restores a testnet faucet account from json file')
.action(function(){
tezstermanager.addTestnetAccount();
});
/* Restores an testnet faucet account */
program
.command('activate-testnet-account')
.usage('<account-label>')
.description('Activates a testnet faucet account resored using tezster')
.action(function(){
tezstermanager.activateTestnetAccount();
});
/******* To restore an existing wallet */
program
.command('restore-wallet')
.usage(`<wallet-label>)`)
.description('Interactive command to restore an existing wallet using mnemonic-phrase or secret/private key')
.action(function(){
if (process.argv.length <=3 || process.argv.length > 4) {
console.log('Incorrect usage of restore-wallet command. Correct usage: - tezster restore-wallet <wallet-label>');
return;
}
prompt(accountRestoreWalletParameters).then(accountRestoreWalletParameterValues => {
if(Object.values(accountRestoreWalletParameterValues)[0] === 'Mnemonic Phrases') {
tezstermanager.restoreWalletUsingMnemonic(process.argv[3], Object.values(accountRestoreWalletParameterValues)[1]);
} else {
tezstermanager.restoreWalletUsingSecret(process.argv[3], Object.values(accountRestoreWalletParameterValues)[1]);
}
});
});
/******* To remove an account */
program
.command('remove-account')
.usage('<account-label/identity/hash>')
.description('To remove an existing account')
.action(function(){
tezstermanager.removeAccount();
});
/******* TO get the list Contracts */
program
.command('list-contracts')
.description('To fetch all the contracts')
.action(function(){
tezstermanager.listContracts();
});
/*******deploy contract written in Michelson*/
program
.command('deploy')
.option('-i', '--interactive', 'use interactive mode')
.usage(`\n(This command provides the interactive shell to deploy a smart contract)`)
.description('Deploys a smart contract written in Michelson')
.action(function() {
if(process.argv[3] !== '-i') {
tezstermanager.deployContractNonInterativeMode();
return;
} else if(process.argv[3] === '-i') {
prompt(contractDeployParameters).then(deployParamaterValues => {
tezstermanager.deployContractInterativeMode(deployParamaterValues);
});
return;
}
});
/*******calls contract written in Michelson*/
program
.command('call')
.option('-i', '--interactive', 'use interactive mode')
.usage(`\n(This command provides the interactive shell to call deployed smart contract)`)
.description('Calls a smart contract with given value provided in Michelson format')
.action(function() {
if(process.argv[3] !== '-i') {
tezstermanager.callContractNonInterativeMode();
return;
} else if(process.argv[3] === '-i') {
prompt(contractCallParameters).then(callParamaterValues => {
tezstermanager.callContractInterativeMode(callParamaterValues);
});
return;
}
});
/*******gets storage for a contract*/
program
.command('get-storage')
.usage('<contract-name/address>')
.description('Returns current storage for given smart contract')
.action(function(){
tezstermanager.getStorage();
});
/******* To Create an contract */
program
.command('add-contract')
.usage('<label> <address>')
.description('Adds a smart contract with label for interaction')
.action(function(){
tezstermanager.addContract();
});
/******* To remove a contract */
program
.command('remove-contract')
.usage('<contract-label>')
.description('To remove deployed contract from list')
.action(function(){
tezstermanager.removeContract();
});
/******* To transfer the amount */
program
.command('transfer')
.usage('<amount(ꜩ)> <from> <to> <--optional gas-fee(muꜩ, default is 3000 muꜩ)>')
.description('To transfer the funds between accounts')
.action(function(){
tezstermanager.transfer();
});
/* list transactions done with tezster */
program
.command('list-transactions')
.description('List down all the transactions')
.action(function(){
tezstermanager.listTransactions();
});
/* list down all the entry points and initial storage format from smart contract */
program
.command('list-entry-points')
.usage('<contract-absolute-path/contract-address>')
.description('List down all entry points and initial storage format from smart contract')
.action(function(){
tezstermanager.listEntryPoints();
});
/* Get all logs file in archive file fromat on user system */
program
.command('get-logs')
.description('Fetch log files on user system in archive file format')
.action(function(){
tezstermanager.getLogFiles();
});
program
.on('--help', () => {
console.log('\nTo know more about particular command usage:\n\ttezster [command] --help');
});
if (process.argv.length <= 2){
program.help();
}
var commands=process.argv[2];
const validCommands = [
'setup',
'start-nodes',
'stop-nodes',
'node-status',
'get-logs',
'get-rpc-node',
'set-rpc-node',
'transfer',
'get-balance',
'list-entry-points',
'deploy',
'call',
'get-storage',
'add-contract',
'list-contracts',
'remove-contract',
'list-accounts',
'create-wallet',
'restore-wallet',
'remove-account',
'add-testnet-account',
'activate-testnet-account',
'list-transactions',
'-v',
'--version',
'--help',
'-h'];
if (validCommands.indexOf(commands) < 0 && process.argv.length >2 ) {
const re = RegExp(`.*${commands.toLowerCase().split('').join('.*')}.*`)
const availableCommands = validCommands.filter(elem => elem.match(re));
console.log('\x1b[31m%s\x1b[0m', 'Error: ' + `Invalid command\nPlease run 'tezster --help' to get info about commands `);
if(availableCommands.toString()) {
console.log('\nThe most similar commands are:');
console.log('\t'+availableCommands.toString().replace(/,/g,'\n\t'));
}
}
program.parse(process.argv);