Skip to content

Commit c15840f

Browse files
authored
Merge pull request #34 from Akachain/develop
ok
2 parents 937bf61 + 36b33ca commit c15840f

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

lib/helper/InvokeService.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class InvokeService {
4444
try {
4545
// first setup the client for this org
4646
client = await common.getClientForOrg(orgName, userName)
47-
47+
4848
channel = await common.getChannel(orgName, userName, channelName);
4949

5050
if (!channel) {
@@ -116,7 +116,12 @@ class InvokeService {
116116
}
117117

118118
} else if (proposalResponses[i].response && proposalResponses[i].response.status === 200) {
119-
logger.debug('invoke chaincode proposal was good');
119+
logger.info('invoke chaincode proposal was good');
120+
logger.debug(util.format(
121+
'Successfully sent Proposal and received ProposalResponse: Status - %s, message - "%s", metadata - "%s", endorsement signature: %s',
122+
proposalResponses[i].response.status, proposalResponses[i].response.message,
123+
proposalResponses[i].response.payload, proposalResponses[i].endorsement.signature));
124+
logger.info("Endored by:", proposalResponses[i].peer.name);
120125
} else {
121126
// increase counter
122127
common.errorRequestCounter.inc();
@@ -128,10 +133,12 @@ class InvokeService {
128133
}
129134

130135
if (all_good) {
131-
logger.debug(util.format(
132-
'Successfully sent Proposal and received ProposalResponse: Status - %s, message - "%s", metadata - "%s", endorsement signature: %s',
133-
proposalResponses[0].response.status, proposalResponses[0].response.message,
134-
proposalResponses[0].response.payload, proposalResponses[0].endorsement.signature));
136+
// Check write sets
137+
if (channel.compareProposalResponseResults(proposalResponses)) {
138+
logger.info('All proposals compare equally!');
139+
} else {
140+
logger.warn('All proposals compare differently!')
141+
}
135142

136143
// wait for the channel-based event hub to tell us
137144
// that the commit was good or bad on each peer in our organization
@@ -212,14 +219,8 @@ class InvokeService {
212219

213220
// now see what each of the event hubs reported
214221
for (let i in resultsPromise) {
215-
let event_hub_result = resultsPromise[i];
216-
let event_hub = event_hubs[i];
217-
logger.debug('Event results for event hub :%s', event_hub.getPeerAddr());
218-
if (typeof event_hub_result === 'string') {
219-
logger.debug(event_hub_result);
220-
} else {
221-
if (!error_message) error_message = event_hub_result.toString();
222-
logger.debug(event_hub_result.toString());
222+
if (typeof resultsPromise[i] === 'string') {
223+
committedCount++
223224
}
224225
}
225226
}

lib/utils/common.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const logger = require('./logger').getLogger('akc-node-sdk');
1515
hfc.setLogger(logger);
1616

1717
// Declare sigleton variables
18-
global.CLIENT = null;
19-
global.CHANNEL = null;
18+
global.CLIENTS = {};
19+
global.CHANNELS = {};
2020

2121
/**
2222
* FUNCTION SECTION
@@ -67,8 +67,8 @@ const getClientForOrg = async (orgName, userName, isRefresh) => {
6767
logger.debug('getClientForOrg - ****** START %s', orgName);
6868

6969
// Check current singleton value
70-
if (!isRefresh && CLIENT) {
71-
return CLIENT;
70+
if (!isRefresh && CLIENTS[userName]) {
71+
return CLIENTS[userName];
7272
}
7373

7474
orgName = orgName || process.env.ORG_NAME;
@@ -95,7 +95,7 @@ const getClientForOrg = async (orgName, userName, isRefresh) => {
9595
}
9696

9797
// Set singleton value
98-
CLIENT = client
98+
CLIENTS[userName] = client;
9999

100100
return client;
101101
}
@@ -110,19 +110,20 @@ const getChannel = async (orgName, userName, channelName, isRefresh) => {
110110
logger.debug('getChannel - ****** START %s %s %s', orgName, channelName);
111111

112112
// Check current singleton value
113-
if (!isRefresh && CHANNEL) {
114-
return CHANNEL;
113+
if (!isRefresh && CHANNELS[userName]) {
114+
return CHANNELS[userName];
115115
}
116116

117117
orgName = orgName || process.env.ORG_NAME;
118118
userName = userName || process.env.USER_NAME;
119119
channelName = channelName || process.env.CHANNEL_NAME;
120120

121-
if (!CLIENT) {
122-
CLIENT = await getClientForOrg(orgName, userName);
121+
if (!CLIENTS[userName]) {
122+
CLIENTS[userName] = await getClientForOrg(orgName, userName);
123123
}
124-
CHANNEL = CLIENT.getChannel(channelName);
125-
return CHANNEL;
124+
125+
CHANNELS[userName] = CLIENTS[userName].getChannel(channelName);
126+
return CHANNELS[userName];
126127
};
127128

128129
/**

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@akachain/akc-node-sdk",
3-
"author": "hoangnh, hongsongp97, longnh, hainq",
4-
"version": "v2.1.6",
3+
"author": "hoangnh, hongsongp97, longnh, hainq, huanlv",
4+
"version": "v2.1.9-a",
55
"description": "AKC node.js SDK for Decentralized Application to connect to Fabric Peers",
66
"main": "index.js",
77
"scripts": {},

0 commit comments

Comments
 (0)