Skip to content

Commit ec39b85

Browse files
authored
Merge branch 'main' into main
Signed-off-by: Chinmayi D S <131844481+urgetolearn@users.noreply.github.com>
2 parents 5f29dae + f434ad2 commit ec39b85

File tree

5 files changed

+123
-35
lines changed

5 files changed

+123
-35
lines changed

extension.js

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ const {
2222
connectToFabric,
2323
decodeBlock,
2424
} = require("./src/blockReader/blockQueries");
25+
2526
const DelveDebugAdapterDescriptorFactory = require("./src/debugAdapter/DelveDebugAdapterDescriptorFactory");
2627

28+
const { invokeChaincode } = require('./src/invokechaincode/invoke.js')
2729
let loadedConnectionProfile = null;
2830

2931
const fabricsamples = require("./src/fabricsamples");
@@ -292,28 +294,20 @@ function activate(context) {
292294
);
293295

294296
context.subscriptions.push(disposableExtractFunctions);
295-
296297
function isGoChaincodeFile(filePath) {
297-
return filePath.toLowerCase().endsWith(".go");
298+
return filePath.toLowerCase().endsWith('.go');
299+
}
300+
function isJavaChaincodeFile(filePath) {
301+
return filePath.toLowerCase().endsWith('.java');
298302
}
299-
300303
function extractGoFunctions(code) {
301304
const functionDetails = [];
302-
const regex =
303-
/func\s*\((\w+)\s+\*SmartContract\)\s*(\w+)\s*\((.*?)\)\s*(\w*)/g;
305+
const regex = /func\s*\((\w+)\s+\*SmartContract\)\s*(\w+)\s*\((.*?)\)\s*(\w*)/g;
304306
let match;
305307

306-
while ((match = regex.exec(code)) !== null) {
307-
const functionName = match[2];
308-
const params = match[3];
309-
functionDetails.push({ name: functionName, params });
310-
}
311-
312-
return functionDetails;
313-
}
314308

315-
function filterIntAndStringFunctions(functions) {
316-
return functions
309+
function filterIntAndStringFunctions(functions) {
310+
return functions
317311
.filter((func) => /int|string/.test(func.params))
318312
.map((func) => `${func.name}(${func.params})`);
319313
}
@@ -324,6 +318,7 @@ function activate(context) {
324318
context.workspaceState.update("storedFunctions", storedFunctions);
325319
}
326320

321+
327322
function showStoredFunctions(context, outputChannel) {
328323
const storedFunctions = context.workspaceState.get("storedFunctions", []);
329324

@@ -403,25 +398,7 @@ function activate(context) {
403398
});
404399
}
405400

406-
async function invokeCommand(functionName, argumentValues) {
407-
outputChannel.appendLine(
408-
`Invoking function ${functionName} with arguments: ${argumentValues.join(
409-
", "
410-
)}`
411-
);
412-
413-
try {
414-
outputChannel.appendLine(
415-
`Simulated invocation of ${functionName}(${argumentValues.join(
416-
", "
417-
)})`
418-
);
419-
} catch (error) {
420-
outputChannel.appendLine(`Error during invocation: ${error.message}`);
421-
}
422-
423-
outputChannel.show();
424-
}
401+
425402
context.subscriptions.push(
426403
vscode.commands.registerCommand(
427404
"fabric-network.switchNetwork",
@@ -440,6 +417,23 @@ function activate(context) {
440417
treeViewProviderFabric.setActiveNetwork(fabricItem);
441418
}
442419

420+
421+
context.subscriptions.push(
422+
vscode.commands.registerCommand(
423+
"fabric-network.switchNetwork",
424+
async (treeItem) => {
425+
const descItem = treeViewProviderDesc.getNetworkByLabel(treeItem.label);
426+
const fabricItem = treeViewProviderFabric.getNetworkByLabel(
427+
treeItem.label
428+
);
429+
430+
if (descItem) {
431+
treeViewProviderDesc.setActiveNetwork(descItem);
432+
}
433+
if (fabricItem) {
434+
treeViewProviderFabric.setActiveNetwork(fabricItem);
435+
}
436+
443437
const activeNetwork = fabricItem || descItem;
444438
if (!activeNetwork) {
445439
vscode.window.showErrorMessage(

package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,13 @@
263263
]
264264
},
265265
"dependencies": {
266+
266267
"@hyperledger/fabric-protos": "^0.2.2",
267268
"@vscode/debugadapter": "^1.68.0",
268269
"dotenv": "^16.4.5",
270+
271+
"@hyperledger/fabric-gateway": "^1.7.0",
272+
269273
"fabric-ca-client": "^2.2.20",
270274
"fabric-network": "^2.2.20",
271275
"fabric-protos": "^2.2.20",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "fabric-network",
3+
"version": "1.0.0",
4+
"client": {
5+
"organization": "Org1",
6+
"connection": {
7+
"timeout": {
8+
"peer": "300"
9+
}
10+
}
11+
},
12+
"channels": {
13+
"mychannel": {
14+
"orderers": [
15+
{
16+
"url": "grpcs://localhost:7050"
17+
}
18+
],
19+
"peers": {
20+
"peer0.org1.example.com": {
21+
"url": "grpcs://localhost:7051"
22+
}
23+
}
24+
}
25+
},
26+
"organizations": {
27+
"Org1": {
28+
"mspid": "Org1MSP",
29+
"peerNames": ["peer0.org1.example.com"],
30+
"certificateAuthorities": ["ca.org1.example.com"]
31+
}
32+
},
33+
"orderers": [
34+
{
35+
"url": "grpcs://localhost:7050"
36+
}
37+
],
38+
"peers": {
39+
"peer0.org1.example.com": {
40+
"url": "grpcs://localhost:7051"
41+
}
42+
}
43+
}

src/invokechaincode/invoke.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { Gateway, Wallets } = require('fabric-network');
2+
const FabricCAServices = require('fabric-ca-client');
3+
const path = require('path');
4+
const fs = require('fs');
5+
const { log } = require('console');
6+
7+
async function invokeChaincode(functionName, args, context) {
8+
try {
9+
10+
const ccpPath = path.resolve(__dirname, 'connection-profile.json');
11+
const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
12+
const wallet = await Wallets.newFileSystemWallet(path.join(process.cwd(), 'wallet'));
13+
const gateway = new Gateway();
14+
await gateway.connect(ccp, {
15+
wallet,
16+
identity: 'admin',
17+
discovery: { enabled: true, asLocalhost: true }
18+
});
19+
20+
21+
const network = await gateway.getNetwork('mychannel');
22+
const contract = network.getContract('mychaincode');
23+
24+
const result = await contract.submitTransaction('CreateAsset', 'asset1', '100');
25+
console.log(`Chaincode invoked successfully. Result: ${result.toString()}`);
26+
27+
28+
await gateway.disconnect();
29+
30+
return result.toString();
31+
} catch (error) {
32+
console.error(`Failed to invoke chaincode: ${error.message}`);
33+
throw new Error(`Failed to invoke chaincode: ${error.message}`);
34+
}
35+
}
36+
37+
38+
invokeChaincode();

0 commit comments

Comments
 (0)