File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -597,4 +597,24 @@ export class Proxy {
597
597
}
598
598
return results ;
599
599
}
600
+
601
+ /*
602
+ * @param {* } contract_name
603
+ * @returns
604
+ * @memberof Proxy
605
+ */
606
+ async getContractMetadata ( network_id , contract_name ) {
607
+ const client = this . platform . getClient ( network_id ) ;
608
+ const channel_name = Object . keys ( client . fabricGateway . config . channels ) [ 0 ] ;
609
+ let metadata ;
610
+ try {
611
+ metadata = await client . fabricGateway . queryContractMetadata ( channel_name , contract_name ) ;
612
+ } catch ( e ) {
613
+ logger . debug ( 'getContractMetadata >> ' , e ) ;
614
+ } if ( metadata ) {
615
+ return metadata ;
616
+ }
617
+ logger . error ( 'response_payloads is null' ) ;
618
+ return 'response_payloads is null' ;
619
+ }
600
620
}
Original file line number Diff line number Diff line change @@ -523,4 +523,14 @@ export class FabricGateway {
523
523
return null ;
524
524
}
525
525
}
526
+ async queryContractMetadata ( channel_name , contract_name ) {
527
+ const network = await this . gateway . getNetwork ( channel_name ) ;
528
+ // Get the contract from the network.
529
+ const contract = network . getContract ( contract_name ) ;
530
+ // Get the contract metadata from the network.
531
+ const result = await contract . evaluateTransaction ( 'org.hyperledger.fabric:GetMetadata' ) ;
532
+ const metadata = JSON . parse ( result . toString ( 'utf8' ) ) ;
533
+ logger . debug ( 'queryContractMetadata' , metadata )
534
+ return metadata ;
535
+ }
526
536
}
Original file line number Diff line number Diff line change @@ -254,6 +254,21 @@ export async function platformroutes(
254
254
}
255
255
} ) ;
256
256
} ) ;
257
-
257
+
258
+ /**
259
+ * Return channel metadata
260
+ * GET /metadata
261
+ * curl -i 'http://<host>:<port>/metadata/<chaincode>'
262
+ */
263
+ router . get ( '/metadata/:chaincode' , ( req , res ) => {
264
+ const chaincode = req . params . chaincode ;
265
+ if ( chaincode ) {
266
+ proxy . getContractMetadata ( req . network , chaincode ) . then ( ( data : any ) => {
267
+ res . send ( { status : 200 , data : data } ) ;
268
+ } ) ;
269
+ } else {
270
+ return requtil . invalidRequest ( req , res ) ;
271
+ }
272
+ } ) ;
258
273
259
274
} // End platformroutes()
You can’t perform that action at this time.
0 commit comments