@@ -163,34 +163,44 @@ program
163
163
network = selectedNetwork
164
164
}
165
165
166
+ if ( ! supportedNetworks . includes ( network ) ) {
167
+ console . info ( `\n ${ logSymbols . error } ` , `error: the network '${ network } ' is not supported\n` )
168
+ return
169
+ }
170
+
166
171
if ( ! groupId ) {
167
- const subgraphGroups = new SemaphoreSubgraph ( network )
172
+ let groupIds
173
+
168
174
const spinnerGroups = new Spinner ( "Fetching groups" )
169
175
spinnerGroups . start ( )
170
- try {
171
- const groups = await subgraphGroups . getGroups ( )
172
176
177
+ try {
178
+ const semaphoreSubgraphGroups = new SemaphoreSubgraph ( network )
179
+ groupIds = await semaphoreSubgraphGroups . getGroupIds ( )
173
180
spinnerGroups . stop ( )
174
-
175
- if ( groups . length === 0 ) {
176
- console . info ( `\n ${ logSymbols . info } ` , "info: there are no groups in this network\n" )
181
+ } catch ( error ) {
182
+ try {
183
+ const semaphoreEthersGroups = new SemaphoreEthers ( network )
184
+ groupIds = await semaphoreEthersGroups . getGroupIds ( )
185
+ spinnerGroups . stop ( )
186
+ } catch {
187
+ spinnerGroups . stop ( )
188
+ console . info ( `\n ${ logSymbols . error } ` , "error: unexpected error with the SemaphoreEthers package" )
177
189
return
178
190
}
179
-
180
- const groupIds = groups . map ( ( { id } : any ) => id )
181
-
182
- const { selectedGroupId } = await inquirer . prompt ( {
183
- name : "selectedGroupId" ,
184
- type : "list" ,
185
- message : "Select one of the following existing group ids:" ,
186
- choices : groupIds
187
- } )
188
- groupId = selectedGroupId
189
- } catch ( error ) {
190
- spinnerGroups . stop ( )
191
- console . info ( `\n ${ logSymbols . error } ` , "error: unexpected error with the Semaphore subgraph" )
191
+ }
192
+ if ( groupIds . length === 0 ) {
193
+ console . info ( `\n ${ logSymbols . info } ` , "info: there are no groups in this network\n" )
192
194
return
193
195
}
196
+
197
+ const { selectedGroupId } = await inquirer . prompt ( {
198
+ name : "selectedGroupId" ,
199
+ type : "list" ,
200
+ message : "Select one of the following existing group ids:" ,
201
+ choices : groupIds
202
+ } )
203
+ groupId = selectedGroupId
194
204
}
195
205
196
206
if ( ! members && ! signals ) {
@@ -213,53 +223,54 @@ program
213
223
signals = showSignals
214
224
}
215
225
216
- if ( ! supportedNetworks . includes ( network ) ) {
217
- console . info ( `\n ${ logSymbols . error } ` , `error: the network '${ network } ' is not supported\n` )
218
- return
219
- }
226
+ let group
220
227
221
- const subgraph = new SemaphoreSubgraph ( network )
222
228
const spinner = new Spinner ( `Fetching group ${ groupId } ` )
223
-
224
229
spinner . start ( )
225
230
226
231
try {
227
- const group = await subgraph . getGroup ( groupId , { members , verifiedProofs : signals } )
228
-
232
+ const semaphoreSubgraph = new SemaphoreSubgraph ( network )
233
+ group = await semaphoreSubgraph . getGroup ( groupId , { members , verifiedProofs : signals } )
229
234
spinner . stop ( )
230
-
231
- if ( ! group ) {
235
+ } catch ( error ) {
236
+ try {
237
+ const semaphoreEthers = new SemaphoreEthers ( network )
238
+ group = await semaphoreEthers . getGroup ( groupId )
239
+ if ( group && members ) {
240
+ group . members = await semaphoreEthers . getGroupMembers ( groupId )
241
+ }
242
+ if ( group && signals ) {
243
+ group . verifiedProofs = await semaphoreEthers . getGroupVerifiedProofs ( groupId )
244
+ }
245
+ spinner . stop ( )
246
+ } catch {
247
+ spinner . stop ( )
232
248
console . info ( `\n ${ logSymbols . error } ` , "error: the group does not exist\n" )
233
-
234
249
return
235
250
}
251
+ }
236
252
237
- let content = ` ${ chalk . bold ( "Id" ) } : ${ group . id } \n`
238
- content += ` ${ chalk . bold ( "Admin" ) } : ${ group . admin } \n`
239
- content += ` ${ chalk . bold ( "Merkle tree" ) } :\n`
240
- content += ` Root: ${ group . merkleTree . root } \n`
241
- content += ` Depth: ${ group . merkleTree . depth } \n`
242
- content += ` Zero value: ${ group . merkleTree . zeroValue } \n`
243
- content += ` Number of leaves: ${ group . merkleTree . numberOfLeaves } `
244
-
245
- if ( members ) {
246
- content += `\n\n ${ chalk . bold ( "Members" ) } : \n${ group . members
247
- . map ( ( member : string , i : number ) => ` ${ i } . ${ member } ` )
248
- . join ( "\n" ) } `
249
- }
250
-
251
- if ( signals ) {
252
- content += `\n\n ${ chalk . bold ( "Signals" ) } : \n${ group . verifiedProofs
253
- . map ( ( { signal } : any ) => ` - ${ signal } ` )
254
- . join ( "\n" ) } `
255
- }
256
-
257
- console . info ( `\n${ content } \n` )
258
- } catch ( error ) {
259
- spinner . stop ( )
253
+ let content = ` ${ chalk . bold ( "Id" ) } : ${ group . id } \n`
254
+ content += ` ${ chalk . bold ( "Admin" ) } : ${ group . admin } \n`
255
+ content += ` ${ chalk . bold ( "Merkle tree" ) } :\n`
256
+ content += ` Root: ${ group . merkleTree . root } \n`
257
+ content += ` Depth: ${ group . merkleTree . depth } \n`
258
+ content += ` Zero value: ${ group . merkleTree . zeroValue } \n`
259
+ content += ` Number of leaves: ${ group . merkleTree . numberOfLeaves } `
260
+
261
+ if ( members ) {
262
+ content += `\n\n ${ chalk . bold ( "Members" ) } : \n${ group . members
263
+ . map ( ( member : string , i : number ) => ` ${ i } . ${ member } ` )
264
+ . join ( "\n" ) } `
265
+ }
260
266
261
- console . info ( `\n ${ logSymbols . error } ` , "error: unexpected error with the Semaphore subgraph" )
267
+ if ( signals ) {
268
+ content += `\n\n ${ chalk . bold ( "Signals" ) } : \n${ group . verifiedProofs
269
+ . map ( ( { signal } : any ) => ` - ${ signal } ` )
270
+ . join ( "\n" ) } `
262
271
}
272
+
273
+ console . info ( `\n${ content } \n` )
263
274
} )
264
275
265
276
program . parse ( process . argv )
0 commit comments