@@ -24,54 +24,49 @@ let loadedConnectionProfile = null;
24
24
const fabricsamples = require ( "./src/fabricsamples" ) ;
25
25
26
26
function activate ( context ) {
27
- const fabricDebuggerPath = 'C:\\Users\\Public\\fabric-debugger' ;
28
- function runupBashScript ( ) {
27
+ const fabricDebuggerPath = 'C:\\Users\\chinm\\fabric-debugger' ;
28
+
29
+ let greenButton = vscode . commands . registerCommand ( 'myview.button1' , ( ) => {
29
30
const platform = process . platform ;
30
- const changeDirCommand = `cd "${ fabricDebuggerPath } "` ;
31
- let runScriptCommand ;
31
+ let command ;
32
32
if ( platform === 'win32' ) {
33
- runScriptCommand = `wsl bash local-networkup.sh` ;
33
+ command = `cd " ${ fabricDebuggerPath } " && wsl bash local-networkup.sh` ;
34
34
} else {
35
- runScriptCommand = `bash local-networkup.sh` ;
35
+ command = `cd " ${ fabricDebuggerPath } " && bash local-networkup.sh` ;
36
36
}
37
- const fullCommand = ` ${ changeDirCommand } && ${ runScriptCommand } ` ;
38
- exec ( fullCommand , ( err , stdout , stderr ) => {
37
+
38
+ exec ( command , ( err , stdout , stderr ) => {
39
39
if ( err ) {
40
40
vscode . window . showErrorMessage ( `Error: ${ stderr } ` ) ;
41
- console . error ( `Error: ${ stderr } ` ) ;
42
41
return ;
43
42
}
44
- vscode . window . showInformationMessage ( `Output: ${ stdout } ` ) ;
45
43
console . log ( `Output: ${ stdout } ` ) ;
44
+ vscode . window . showInformationMessage ( "network is up and running" ) ;
46
45
} ) ;
47
- }
48
- let greenButton = vscode . commands . registerCommand ( 'myview.button1' , ( ) => {
49
- runupBashScript ( ) ;
50
46
} ) ;
51
- context . subscriptions . push ( greenButton ) ;
52
- function rundownBashScript ( ) {
47
+
48
+ let redButton = vscode . commands . registerCommand ( 'myview.button2' , ( ) => {
53
49
const platform = process . platform ;
54
- const changeDirCommand = `cd " ${ fabricDebuggerPath } "` ;
55
- let runScriptCommand ;
50
+
51
+ let command ;
56
52
if ( platform === 'win32' ) {
57
- runScriptCommand = `wsl bash local-networkdown.sh` ;
53
+ command = `cd " ${ fabricDebuggerPath } " && wsl bash local-networkdown.sh` ;
58
54
} else {
59
- runScriptCommand = `bash local-networkdown.sh` ;
55
+ command = `cd " ${ fabricDebuggerPath } " && bash local-networkdown.sh` ;
60
56
}
61
- const fullCommand = `${ changeDirCommand } && ${ runScriptCommand } ` ;
62
- exec ( fullCommand , ( err , stdout , stderr ) => {
57
+
58
+ // Execute the command
59
+ exec ( command , ( err , stdout , stderr ) => {
63
60
if ( err ) {
64
61
vscode . window . showErrorMessage ( `Error: ${ stderr } ` ) ;
65
- console . error ( `Error: ${ stderr } ` ) ;
66
62
return ;
67
63
}
68
- vscode . window . showInformationMessage ( `Output: ${ stdout } ` ) ;
69
64
console . log ( `Output: ${ stdout } ` ) ;
65
+ vscode . window . showInformationMessage ( "network is down" ) ;
70
66
} ) ;
71
- }
72
- let redButton = vscode . commands . registerCommand ( 'myview.button2' , ( ) => {
73
- rundownBashScript ( ) ;
74
67
} ) ;
68
+
69
+ context . subscriptions . push ( greenButton ) ;
75
70
context . subscriptions . push ( redButton ) ;
76
71
77
72
@@ -96,7 +91,6 @@ function activate(context) {
96
91
vscode . window . createTreeView ( "wallets" , {
97
92
treeDataProvider : treeViewProviderWallet ,
98
93
} ) ;
99
-
100
94
const loadProfilesAndWallets = async ( ) => {
101
95
try {
102
96
const savedProfiles = await loadConnectionProfilesFromStorage ( context ) ;
@@ -240,7 +234,135 @@ function activate(context) {
240
234
}
241
235
)
242
236
) ;
237
+ const outputChannel = vscode . window . createOutputChannel ( "Chaincode Invocation" ) ;
238
+
243
239
240
+ let disposableExtractFunctions = vscode . commands . registerCommand ( 'extension.extractFunctions' , function ( ) {
241
+ const editor = vscode . window . activeTextEditor ;
242
+ if ( ! editor ) {
243
+ vscode . window . showInformationMessage ( 'No active editor. Open a chaincode file.' ) ;
244
+ return ;
245
+ }
246
+ const filePath = editor . document . fileName ;
247
+ const text = editor . document . getText ( ) ;
248
+ let functions = [ ] ;
249
+
250
+ if ( isGoChaincodeFile ( filePath ) ) {
251
+ functions = extractGoFunctions ( text ) ;
252
+ }
253
+
254
+ const filteredFunctions = filterIntAndStringFunctions ( functions ) ;
255
+ const uniqueFunctions = [ ...new Set ( filteredFunctions ) ] ;
256
+ storeFunctions ( uniqueFunctions , context ) ;
257
+
258
+ vscode . window . showInformationMessage ( `Extracted and stored ${ uniqueFunctions . length } unique functions with int or string parameters.` ) ;
259
+
260
+ showStoredFunctions ( context , outputChannel ) ;
261
+ } ) ;
262
+
263
+ context . subscriptions . push ( disposableExtractFunctions ) ;
264
+
265
+
266
+ function isGoChaincodeFile ( filePath ) {
267
+ return filePath . toLowerCase ( ) . endsWith ( '.go' ) ;
268
+ }
269
+
270
+ function extractGoFunctions ( code ) {
271
+ const functionDetails = [ ] ;
272
+ const regex = / f u n c \s * \( ( \w + ) \s + \* S m a r t C o n t r a c t \) \s * ( \w + ) \s * \( ( .* ?) \) \s * ( \w * ) / g;
273
+ let match ;
274
+
275
+ while ( ( match = regex . exec ( code ) ) !== null ) {
276
+ const functionName = match [ 2 ] ;
277
+ const params = match [ 3 ] ;
278
+ functionDetails . push ( { name : functionName , params } ) ;
279
+ }
280
+
281
+ return functionDetails ;
282
+ }
283
+
284
+ function filterIntAndStringFunctions ( functions ) {
285
+ return functions . filter ( func => / i n t | s t r i n g / . test ( func . params ) ) . map ( func => `${ func . name } (${ func . params } )` ) ;
286
+ }
287
+
288
+ function storeFunctions ( functions , context ) {
289
+ let storedFunctions = context . workspaceState . get ( 'storedFunctions' , [ ] ) ;
290
+ storedFunctions = [ ...new Set ( [ ...storedFunctions , ...functions ] ) ] ;
291
+ context . workspaceState . update ( 'storedFunctions' , storedFunctions ) ;
292
+ }
293
+
294
+ function showStoredFunctions ( context , outputChannel ) {
295
+ const storedFunctions = context . workspaceState . get ( 'storedFunctions' , [ ] ) ;
296
+
297
+ vscode . window . showQuickPick ( storedFunctions , {
298
+ placeHolder : 'Select a function to invoke' ,
299
+ canPickMany : false
300
+ } ) . then ( selectedFunction => {
301
+ if ( selectedFunction ) {
302
+ vscode . window . showInformationMessage ( `Selected: ${ selectedFunction } ` ) ;
303
+ promptForArgumentsSequentially ( selectedFunction , outputChannel ) ;
304
+ }
305
+ } ) ;
306
+ }
307
+
308
+ async function promptForArgumentsSequentially ( selectedFunction , outputChannel ) {
309
+ const functionPattern = / ( \w + ) \( ( .* ) \) / ;
310
+ const match = functionPattern . exec ( selectedFunction ) ;
311
+
312
+ if ( ! match ) {
313
+ vscode . window . showErrorMessage ( "Invalid function format." ) ;
314
+ return ;
315
+ }
316
+
317
+ const functionName = match [ 1 ] ;
318
+ const paramList = match [ 2 ] . split ( ',' ) . map ( param => param . trim ( ) ) ;
319
+
320
+ let argumentValues = [ ] ;
321
+
322
+ for ( let param of paramList ) {
323
+ if ( / i n t / . test ( param ) ) {
324
+ const input = await vscode . window . showInputBox ( { prompt : `Enter an integer value for ${ param } ` } ) ;
325
+ const intValue = parseInt ( input , 10 ) ;
326
+ if ( isNaN ( intValue ) ) {
327
+ vscode . window . showErrorMessage ( `Invalid integer value for ${ param } .` ) ;
328
+ return ;
329
+ }
330
+ argumentValues . push ( intValue ) ;
331
+ } else if ( / s t r i n g / . test ( param ) ) {
332
+ const input = await vscode . window . showInputBox ( { prompt : `Enter a string value for ${ param } ` } ) ;
333
+ if ( ! input ) {
334
+ vscode . window . showErrorMessage ( `Invalid string value for ${ param } .` ) ;
335
+ return ;
336
+ }
337
+ argumentValues . push ( `"${ input } "` ) ;
338
+ }
339
+ }
340
+
341
+ const finalArgs = argumentValues . join ( ', ' ) ;
342
+ outputChannel . show ( ) ;
343
+ outputChannel . appendLine ( `Function: ${ functionName } ` ) ;
344
+ outputChannel . appendLine ( `Arguments: ${ finalArgs } ` ) ;
345
+
346
+ vscode . window . showInformationMessage ( `Arguments captured. Press "Invoke" to execute the command.` , "Invoke" ) . then ( selection => {
347
+ if ( selection === "Invoke" ) {
348
+ invokeCommand ( functionName , argumentValues ) ;
349
+ }
350
+ } ) ;
351
+ }
352
+
353
+
354
+ async function invokeCommand ( functionName , argumentValues ) {
355
+ outputChannel . appendLine ( `Invoking function ${ functionName } with arguments: ${ argumentValues . join ( ', ' ) } ` ) ;
356
+
357
+ try {
358
+
359
+ outputChannel . appendLine ( `Simulated invocation of ${ functionName } (${ argumentValues . join ( ', ' ) } )` ) ;
360
+ } catch ( error ) {
361
+ outputChannel . appendLine ( `Error during invocation: ${ error . message } ` ) ;
362
+ }
363
+
364
+ outputChannel . show ( ) ;
365
+ }
244
366
context . subscriptions . push (
245
367
vscode . commands . registerCommand (
246
368
"fabric-network.switchNetwork" ,
0 commit comments