Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/platform/fabric/Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,24 @@ export class Proxy {
}
return results;
}

/*
* @param {*} contract_name
* @returns
* @memberof Proxy
*/
async getContractMetadata(network_id, contract_name) {
const client = this.platform.getClient(network_id);
const channel_name = Object.keys(client.fabricGateway.config.channels)[0];
let metadata;
try {
metadata = await client.fabricGateway.queryContractMetadata(channel_name, contract_name);
} catch (e) {
logger.debug('getContractMetadata >> ', e);
} if (metadata) {
return metadata;
}
logger.error('response_payloads is null');
return 'response_payloads is null';
}
}
10 changes: 10 additions & 0 deletions app/platform/fabric/gateway/FabricGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,14 @@ export class FabricGateway {
return null;
}
}
async queryContractMetadata(channel_name, contract_name) {
const network = await this.gateway.getNetwork(channel_name);
// Get the contract from the network.       
const contract = network.getContract(contract_name);
// Get the contract metadata from the network.
const result = await contract.evaluateTransaction('org.hyperledger.fabric:GetMetadata');
const metadata = JSON.parse(result.toString('utf8'));
logger.debug('queryContractMetadata', metadata)
return metadata;
}
}
17 changes: 16 additions & 1 deletion app/rest/platformroutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ export async function platformroutes(
}
});
});


/**
* Return channel metadata
* GET /metadata
* curl -i 'http://<host>:<port>/metadata/<chaincode>'
*/
router.get('/metadata/:chaincode', (req, res) => {
const chaincode = req.params.chaincode;
if (chaincode) {
proxy.getContractMetadata(req.network, chaincode).then((data: any) => {
res.send({ status: 200, data: data });
});
} else {
return requtil.invalidRequest(req, res);
}
});

} // End platformroutes()