Skip to content

Commit 90afa5c

Browse files
committed
chaincode metadata changes added
Signed-off-by: SunnyAjin <[email protected]>
1 parent 7eace22 commit 90afa5c

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

app/platform/fabric/Proxy.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,4 +597,24 @@ export class Proxy {
597597
}
598598
return results;
599599
}
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+
}
600620
}

app/platform/fabric/gateway/FabricGateway.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,14 @@ export class FabricGateway {
523523
return null;
524524
}
525525
}
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+
}
526536
}

app/rest/platformroutes.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,21 @@ export async function platformroutes(
254254
}
255255
});
256256
});
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+
});
258273

259274
} // End platformroutes()

0 commit comments

Comments
 (0)