Skip to content

Commit 68e873e

Browse files
MuthuSundaravadivelMuthu  Sundaravadivel
andauthored
Enable Log Traces Begin Commit Button functionality (#886)
Signed-off-by: Muthu Sundaravadivel <[email protected]> Co-authored-by: Muthu Sundaravadivel <[email protected]>
1 parent bd922fe commit 68e873e

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

packages/apollo/src/components/ChaincodeModal/ChaincodeModal.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const Log = new Logger(SCOPE);
4545

4646
export class ChaincodeModal extends React.Component {
4747
componentDidMount() {
48+
Log.debug('componentDidMount -> getData()');
4849
this.getData();
4950
}
5051

@@ -80,6 +81,7 @@ export class ChaincodeModal extends React.Component {
8081
}
8182

8283
async getData() {
84+
Log.debug('getData() start');
8385
this.props.updateState(SCOPE, { loading: true });
8486
this.clearData();
8587
const channel = await this.getChannelInformation();
@@ -89,6 +91,7 @@ export class ChaincodeModal extends React.Component {
8991
await this.getMspInformation();
9092
}
9193
this.props.updateState(SCOPE, { loading: false });
94+
Log.debug('getData() done');
9295
}
9396

9497
async getChannelInformation() {
@@ -108,6 +111,11 @@ export class ChaincodeModal extends React.Component {
108111
this.props.updateState(SCOPE, {
109112
channel,
110113
});
114+
Log.debug('getChannelInformation()', {
115+
channel_id: channel && channel.id,
116+
peer_count: channel && channel.peers ? channel.peers.length : 0,
117+
orderer_count: channel && channel.orderers ? channel.orderers.length : 0,
118+
});
111119
return channel;
112120
}
113121

@@ -136,6 +144,7 @@ export class ChaincodeModal extends React.Component {
136144
});
137145
}
138146
this.props.updateState(SCOPE, { members });
147+
Log.debug('getChannelMembers()', { count: members.length, msp_ids: members.map(m => m.id) });
139148
return members;
140149
}
141150

@@ -159,6 +168,14 @@ export class ChaincodeModal extends React.Component {
159168
});
160169
}
161170
if (signatureRequest) {
171+
Log.debug('getSignatureRequest() found existing signatureRequest', {
172+
channel_id: channel.id,
173+
sequence: signatureRequest.ccd && signatureRequest.ccd.chaincode_sequence,
174+
chaincode_id: signatureRequest.ccd && signatureRequest.ccd.chaincode_id,
175+
orgs2sign_initial: signatureRequest.orgs2sign ? signatureRequest.orgs2sign.length : 0,
176+
signature_count_initial: signatureRequest.signature_count,
177+
required_initial: _.get(signatureRequest, 'current_policy.number_of_signatures', 1),
178+
});
162179
for (let i = 0; i < members.length; i++) {
163180
const member = members[i];
164181
let test = signatureRequest.orgs2sign.filter(org => org.msp_id === member.id);
@@ -210,6 +227,12 @@ export class ChaincodeModal extends React.Component {
210227
host: channel.peers[0].url2use,
211228
channel_id: channel.id,
212229
});
230+
Log.debug('getSignatureRequest() computed values', {
231+
signature_count: signatureRequest.signature_count,
232+
required: _.get(signatureRequest, 'current_policy.number_of_signatures', 1),
233+
orgs2sign_final: signatureRequest.orgs2sign ? signatureRequest.orgs2sign.length : 0,
234+
committed,
235+
});
213236
} else {
214237
// no signature request, so get existing approvals
215238
const opts = {
@@ -241,13 +264,21 @@ export class ChaincodeModal extends React.Component {
241264
signature,
242265
});
243266
}
267+
Log.debug('getSignatureRequest() no active signatureRequest; built committed approvals', {
268+
approvals_count: commited_approvals.length,
269+
});
244270
}
245271
this.props.updateState(SCOPE, {
246272
signatureRequest,
247273
approvals,
248274
committed,
249275
commited_approvals,
250276
});
277+
Log.debug('getSignatureRequest() updated state', {
278+
has_signatureRequest: !!signatureRequest,
279+
committed,
280+
approvals_summary: approvals.map(a => `${a.msp_id}:${a.approved ? 'Y' : 'N'}`),
281+
});
251282
return signatureRequest;
252283
}
253284

@@ -285,6 +316,12 @@ export class ChaincodeModal extends React.Component {
285316
ready_to_commit = true;
286317
}
287318
}
319+
Log.debug('renderApprovals()', {
320+
committed,
321+
number_of_signatures,
322+
required_signatures,
323+
ready_to_commit,
324+
});
288325
return (
289326
<div className="ibp-chaincode-approval">
290327
{Helper.renderFieldSummary(
@@ -1088,6 +1125,17 @@ export class ChaincodeModal extends React.Component {
10881125
}
10891126

10901127
render() {
1128+
Log.debug('render() evaluating submit button', {
1129+
selected: !!this.props.selected,
1130+
show_commit: !!this.props.show_commit,
1131+
committed: !!this.props.committed,
1132+
signatureRequest: this.props.signatureRequest
1133+
? {
1134+
signature_count: this.props.signatureRequest.signature_count,
1135+
required: _.get(this.props, 'signatureRequest.current_policy.number_of_signatures', 1),
1136+
}
1137+
: null,
1138+
});
10911139
let button = undefined;
10921140
let onSubmit = undefined;
10931141
if (this.props.signatureRequest) {
@@ -1097,15 +1145,29 @@ export class ChaincodeModal extends React.Component {
10971145
onSubmit = this.props.show_commit
10981146
? this.onCommit
10991147
: () => {
1148+
Log.debug('render() begin_commit selected, toggling commit view');
11001149
this.props.updateState(SCOPE, { show_commit: true });
11011150
return Promise.reject();
11021151
};
1152+
} else {
1153+
Log.debug('render() begin_commit disabled: not enough signatures', {
1154+
current: this.props.signatureRequest.signature_count,
1155+
required: _.get(this.props, 'signatureRequest.current_policy.number_of_signatures', 1),
1156+
});
11031157
}
1158+
} else {
1159+
Log.debug('render() begin_commit disabled: chaincode already committed');
11041160
}
1161+
} else {
1162+
Log.debug('render() begin_commit disabled: no signatureRequest');
11051163
}
11061164
if (this.props.selected) {
11071165
button = this.props.t(this.props.selected.signature ? 'update_proposal' : 'approve_proposal');
11081166
onSubmit = this.onApprove;
1167+
Log.debug('render() approve/update button active', {
1168+
selected_msp: this.props.selected && this.props.selected.msp_id,
1169+
hasSignature: !!(this.props.selected && this.props.selected.signature),
1170+
});
11091171
}
11101172
return (
11111173
<Wizard onClose={this.props.onClose}

0 commit comments

Comments
 (0)