-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
203 lines (182 loc) · 6.18 KB
/
cli.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
#!/usr/bin/env node
const { program } = require('commander')
const { version } = require('./package.json')
const getCurrentBlockDetails = require('./src/commands/explorer/getcurrentblock')
const { findBlock } = require('./src/commands/explorer/findblock')
const { checkAddress } = require('././src/commands/explorer/search-address')
const {
searchTransaction,
} = require('./src/commands/explorer/searchTransaction')
const { stakemind } = require('./src/commands/staking/stake')
const { unstakeMind } = require('./src/commands/staking/unstake')
const { showValidators } = require('./src/commands/staking/showValidators')
const { createWallet } = require('././src/commands/wallet/createwallet')
const installMind = require('./src/commands/node/install-node')
const initSecrets = require('./src/commands/node/setupnode')
const startMindServer = require('./src/commands/node/start')
const generateGenesisJson = require('./src/commands/node/getgenesis')
Promise.all([import('figlet'), import('chalk')]).then(([figlet, chalk]) => {
function displayTitle() {
console.log(
chalk.default.yellow(
figlet.default.textSync('MSC-CLI', { horizontalLayout: 'full' }),
),
)
}
// Display the title when the program starts
displayTitle()
program.version(version).description('CLI for interacting with Mind-chain')
program
.command('version')
.description('Display the current version')
.action(() => {
console.log('CLI Version:', version)
})
const explorer = program
.command('explorer')
.description('explorer related subcommands')
explorer
.command('getblock')
.description('get current block details')
.action(async () => {
const blockDetails = await getCurrentBlockDetails()
console.log('Current Block Details:', blockDetails)
})
explorer
.command('searchblock <blocknumber>')
.description('search block by block number')
.action(async (blockNumber) => {
try {
const blockDetails = await findBlock(parseInt(blockNumber))
console.log(`Block ${blockNumber} Details:`, blockDetails)
} catch (error) {
console.error(
'Error occurred while finding block details:',
error.message,
)
}
})
explorer
.command('checkaddress <address>')
.description('check details of an MSC address')
.action(async (address) => {
try {
const addressDetails = await checkAddress(address)
console.log(`Details for address ${address}:`)
console.log('Balance:', addressDetails.balance + ' MIND')
console.log('Transaction Count:', addressDetails.transactionCount)
console.log('Code Exists:', addressDetails.codeExists ? 'Yes' : 'No')
//console.log("ENS Name:", addressDetails.ensName);
} catch (error) {
console.error(error.message)
}
})
explorer
.command('searchtransaction <transactionHash>')
.description('search details of an MSC transaction')
.action(async (transactionHash) => {
try {
const transactionDetails = await searchTransaction(transactionHash)
console.log(`Details for transaction ${transactionHash}:`)
console.log('Hash:', transactionDetails.hash)
console.log('Block Number:', transactionDetails.blockNumber)
console.log('From:', transactionDetails.from)
console.log('To:', transactionDetails.to)
console.log('Value:', transactionDetails.value + ' MIND')
console.log('Gas Price:', transactionDetails.gasPrice)
console.log('Gas Limit:', transactionDetails.gasLimit)
console.log('Nonce:', transactionDetails.nonce)
console.log('Timestamp:', transactionDetails.timestamp)
console.log('Confirmations:', transactionDetails.confirmations)
} catch (error) {
console.error(chalk.yellow(error.message))
}
})
//staking commands
const staking = program
.command('staking')
.description('staking related subcommands')
staking
.command('stake <privateKey>')
.description('stake mind to the contract')
.action(async (privateKey) => {
try {
await stakemind(privateKey)
} catch (error) {
console.error(error.message)
}
})
staking
.command('unstake <privateKey>')
.description('unstake MIND from the contract')
.action(async (privateKey) => {
try {
await unstakeMind(privateKey)
} catch (error) {
console.error(chalk.red(error.message))
}
})
staking
.command('get-validators')
.description('show all current active validators')
.action(async () => {
try {
await showValidators()
} catch (error) {
console.error(chalk.red(error.message))
}
})
//wallet management
const wallet = program
.command('wallet')
.description('wallet management related subcommands')
wallet
.command('createwallet')
.option('-p, --path <path>', 'Path to store the wallet file')
.action((options) => {
// Check if the --path option is provided
if (!options.path) {
console.error(
'Error: Please provide the path to store the wallet using --path option.',
)
process.exit(1)
}
// Call createWallet function with the specified path
createWallet(options.path)
})
const node = program
.command('node ')
.description('node management related subcommands')
node
.command('install-mind')
.description('Install Mind binary')
.action(installMind)
node
.command('init-secrets')
.description('Initialize Mind secrets')
.option('-d, --data-dir <directory>', 'Specify the data directory')
.action((options) => {
if (!options.dataDir) {
console.error(
chalk.red(
'Error: Please specify the data directory using -d or --data-dir option.',
),
)
process.exit(1)
}
initSecrets(options.dataDir)
})
node
.command('start-mind-server')
.description('Start Mind node')
.action(() => {
startMindServer()
})
node
.command('get-genesis')
.description('dump genesis JSON file')
.action(() => {
generateGenesisJson()
})
program.parse(process.argv)
})