Skip to content

Commit

Permalink
BE-756 Fix tx count in Chaincode view (#120)
Browse files Browse the repository at this point in the history
Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>
  • Loading branch information
nekia committed Jun 22, 2020
1 parent 96d4c7e commit 114cc88
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
6 changes: 6 additions & 0 deletions app/platform/fabric/FabricClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ class FabricClient {
discover_results
);

if ('peers_by_org' in discover_results) {
for (const org in discover_results.peers_by_org) {
logger.info('Discovered', org, discover_results.peers_by_org[org].peers);
}
}

return discover_results;
}

Expand Down
18 changes: 15 additions & 3 deletions app/platform/fabric/FabricConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,22 @@ class FabricConfig {
* @memberof FabricConfig
*/
isFabricCaEnabled() {
if (this.config.certificateAuthorities) {
return true;
if (this.config.certificateAuthorities === undefined) {
return false;
}

const org = this.getOrganization();
const caArray = this.config.organizations[org].certificateAuthorities;
if (caArray === undefined) {
return false;
}

const caName = caArray[0];
if (this.config.certificateAuthorities[caName] === undefined) {
return false;
}
return false;
logger.info('Fabric CA: Enabled');
return true;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions app/platform/fabric/Proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class Proxy {
node.status = 'DOWN';
if (discover_results && discover_results.peers_by_org) {
const org = discover_results.peers_by_org[node.mspid];
if (org === undefined) {
continue;
}
for (const peer of org.peers) {
if (peer.endpoint.indexOf(node.server_hostname) > -1) {
node.ledger_height_low = peer.ledger_height.low;
Expand Down
18 changes: 15 additions & 3 deletions app/platform/fabric/gateway/FabricGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
BlockDecoder
} = require('fabric-common');
const fabprotos = require('fabric-protos');
const concat = require('lodash/concat');

const FabricCAServices = require('fabric-ca-client');

Expand Down Expand Up @@ -266,6 +267,7 @@ class FabricGateway {
const contract = network.getContract('cscc');
const result = await contract.evaluateTransaction('GetChannels');
const resultJson = fabprotos.protos.ChannelQueryResponse.decode(result);
logger.debug('queryChannels', resultJson);
return resultJson;
}

Expand All @@ -281,6 +283,7 @@ class FabricGateway {
String(blockNum)
);
const resultJson = BlockDecoder.decode(resultByte);
logger.debug('queryBlock', resultJson);
return resultJson;
} catch (error) {
logger.error(
Expand All @@ -291,21 +294,29 @@ class FabricGateway {
}
}

async queryInstantiatedChaincodes() {
async queryInstantiatedChaincodes(channelName) {
const network = await this.gateway.getNetwork(this.defaultChannelName);
let contract = network.getContract('lscc');
let result = await contract.evaluateTransaction('GetChaincodes');
let resultJson = fabprotos.protos.ChaincodeQueryResponse.decode(result);
if (resultJson.chaincodes.length <= 0) {
resultJson = { chaincodes: [] };
contract = network.getContract('_lifecycle');
result = await contract.evaluateTransaction('QueryInstalledChaincodes', '');
resultJson = fabprotos.lifecycle.QueryInstalledChaincodeResult.References.decode(
const decodedReult = fabprotos.lifecycle.QueryInstalledChaincodesResult.decode(
result
);
for (const cc of decodedReult.installed_chaincodes) {
const ccInfo = cc.references.get(channelName);
if (ccInfo !== undefined) {
resultJson.chaincodes = concat(resultJson.chaincodes, ccInfo.chaincodes);
}
}
}
logger.debug('queryInstantiatedChaincodes', resultJson);
return resultJson;
}

async queryChainInfo(channelName) {
try {
const network = await this.gateway.getNetwork(this.defaultChannelName);
Expand All @@ -317,6 +328,7 @@ class FabricGateway {
channelName
);
const resultJson = fabprotos.common.BlockchainInfo.decode(resultByte);
logger.debug('queryChainInfo', resultJson);
return resultJson;
} catch (error) {
logger.error(
Expand Down
5 changes: 4 additions & 1 deletion app/platform/fabric/sync/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ class SyncServices {
discoveryResults
) {
const network_name = client.network_name;
const chaincodes = await client.fabricGateway.queryInstantiatedChaincodes();
const channel_name = client.getChannelNameByHash(channel_genesis_hash);
const chaincodes = await client.fabricGateway.queryInstantiatedChaincodes(
channel_name
);
for (const chaincode of chaincodes.chaincodes) {
let path = '-';
if (chaincode.path !== undefined) {
Expand Down

0 comments on commit 114cc88

Please sign in to comment.