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