From a25428151d20818eeb29a72fa8a387ca40a98dd2 Mon Sep 17 00:00:00 2001 From: TsvetanG Date: Mon, 17 Mar 2025 21:36:01 -0400 Subject: [PATCH] Issue 819 - Fix join channel when importing ordering service Signed-off-by: TsvetanG --- .../JoinChannelModal/JoinChannelModal.js | 12 +++++++++++- packages/apollo/src/rest/OrdererRestApi.js | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/apollo/src/components/JoinChannelModal/JoinChannelModal.js b/packages/apollo/src/components/JoinChannelModal/JoinChannelModal.js index 6b527680..06c283f0 100644 --- a/packages/apollo/src/components/JoinChannelModal/JoinChannelModal.js +++ b/packages/apollo/src/components/JoinChannelModal/JoinChannelModal.js @@ -329,11 +329,18 @@ class JoinChannelModal extends React.Component { await this.checkPeerMappings(this.props.peer); } // Find the channel members + let mspId = ""; try { + + if (this.props.peer) { + const peerDetails = await PeerRestApi.getPeerDetails(this.props.peer[0].id, true); + mspId = peerDetails.msp_id; + } let options = { ordererId: selectedOrderer.node_id, channelId: selectedChannel, - configtxlator_url: this.props.configtxlator_url + configtxlator_url: this.props.configtxlator_url, + requestingMspId: mspId, }; let config = await OrdererRestApi.getChannelConfig(options); let memberIds = this.props.existingMembers.map(x => x.id); @@ -359,6 +366,9 @@ class JoinChannelModal extends React.Component { } catch (error) { this.props.updateState(SCOPE, { loading: false }); Log.error('An error occurred when filtering peer list', error); + if(error.code && error.code === "no_certs_available") { + return; + } return Promise.reject({ title: error.code || 'error_join_channel_not_found', details: error, diff --git a/packages/apollo/src/rest/OrdererRestApi.js b/packages/apollo/src/rest/OrdererRestApi.js index 8667f5dc..3b26aa6c 100644 --- a/packages/apollo/src/rest/OrdererRestApi.js +++ b/packages/apollo/src/rest/OrdererRestApi.js @@ -22,6 +22,9 @@ import Helper from '../utils/helper'; import ChannelApi from './ChannelApi'; import { NodeRestApi } from './NodeRestApi'; import { RestApi } from './RestApi'; +import { MspRestApi } from './MspRestApi'; +import IdentityApi from './IdentityApi'; + const bytes = require('bytes'); const org_template = require('../utils/configtx/org_template.json'); const urlParser = require('url'); @@ -585,6 +588,18 @@ class OrdererRestApi { cert: ordererCerts ? ordererCerts.cert : null, private_key: ordererCerts ? ordererCerts.private_key : null, }; + if (!test.cert && !test.private_key && options.requestingMspId) { + //read the certs/key of the MSP admin identity + const requestingMsp = await MspRestApi.getMSPDetails(options.requestingMspId); + Log.info("Requesting MSP: ", requestingMsp); + let mspIdentities = await IdentityApi.getIdentitiesForMsp(requestingMsp); + let mspAdminIdentities = mspIdentities.filter( (identity) => requestingMsp.admins.includes(identity.cert)); + if (mspAdminIdentities.length > 1) { + test.msp_id = options.requestingMspId; + test.cert = mspAdminIdentities[0].cert; + test.private_key = mspAdminIdentities[0].private_key; + } + } const opts = { msp_id: test.msp_id, client_cert_b64pem: test.cert, @@ -596,6 +611,9 @@ class OrdererRestApi { }; let resp; try { + if (!opts.client_cert_b64pem || !opts.client_prv_key_b64pem) { + throw { code: 'no_certs_available' }; + } let getChannelConfigBlockFromOrderer; if (options.genesis) { getChannelConfigBlockFromOrderer = promisify(window.stitch.getChannelsGenesisFromOrderer);