diff --git a/fabric-client/lib/Client.js b/fabric-client/lib/Client.js index 554ebebc4e..02d79f2eb3 100644 --- a/fabric-client/lib/Client.js +++ b/fabric-client/lib/Client.js @@ -1098,6 +1098,7 @@ const Client = class extends BaseClient { * @property {string} metadataPath - Optional. The path to the top-level * directory containing metadata descriptors. * @property {string} chaincodeId - Required. Name of the chaincode + * @property {string} goPath - Optional. The path to be used with the golang chaincode. * @property {string} chaincodeVersion - Required. Version string of the * chaincode, such as 'v1' * @property {byte[]} chaincodePackage - Optional. Byte array of the archive @@ -1195,7 +1196,8 @@ const Client = class extends BaseClient { version: request.chaincodeVersion, path: request.chaincodePath, type: request.chaincodeType, - metadataPath: request.metadataPath + metadataPath: request.metadataPath, + goPath: request.goPath }); cdsBytes = await cdsPkg.toBuffer(); logger.debug(`installChaincode - built chaincode package (${cdsBytes.length} bytes)`); diff --git a/fabric-client/lib/Package.js b/fabric-client/lib/Package.js index e8288e2f9f..024a29f0ea 100644 --- a/fabric-client/lib/Package.js +++ b/fabric-client/lib/Package.js @@ -87,12 +87,13 @@ class Package { * @param {string} options.path The directory containing the smart contract. * @param {string} options.type The type of the smart contract, one of 'golang', 'car', 'node' or 'java'. * @param {string} [options.metadataPath] The directory containing the metadata descriptors. + * @param {string} options.goPath The path to be used with the golang chaincode. * @returns {Package} The smart contract package. */ - static async fromDirectory({name, version, path, type, metadataPath}) { + static async fromDirectory({name, version, path, type, metadataPath, goPath}) { logger.debug('Package.fromDirectory - entry - %s, %s, %s, %s', name, version, path, type); Package._validateNameAndVersion(name, version); - const codePackage = await Packager.package(path, type, false, metadataPath); + const codePackage = await Packager.package(path, type, false, metadataPath, goPath); logger.debug('Package.fromDirectory - code package is %s bytes', codePackage.length); const fixedPath = path.split('\\').join('/'); // for windows style paths const chaincodeSpec = { diff --git a/fabric-client/test/Client.js b/fabric-client/test/Client.js index 084ab6e481..b3ad04ad5c 100644 --- a/fabric-client/test/Client.js +++ b/fabric-client/test/Client.js @@ -1663,10 +1663,11 @@ describe('Client', () => { version: '0.0.1', path: 'mycc', type: undefined, - metadataPath: undefined + metadataPath: undefined, + goPath: undefined }).resolves(smartContractPackage); getTargetPeersStub.withArgs(['peer']).returns(['peer']); - const request = {chaincodeId: 'mycc', chaincodeVersion: '0.0.1', chaincodePath: 'mycc', targets: ['peer']}; + const request = {chaincodeId: 'mycc', chaincodeVersion: '0.0.1', chaincodePath: 'mycc', targets: ['peer'], goPath: undefined}; const response = await client.installChaincode(request); sinon.assert.calledWith(getTargetPeersStub, ['peer']); sinon.assert.calledOnce(fromDirectoryStub); @@ -1690,7 +1691,8 @@ describe('Client', () => { version: '0.0.1', path: 'mycc', type: 'java', - metadataPath: undefined + metadataPath: undefined, + goPath: undefined }).resolves(smartContractPackage); getTargetPeersStub.withArgs(['peer']).returns(['peer']); const request = { @@ -1698,6 +1700,7 @@ describe('Client', () => { chaincodeVersion: '0.0.1', chaincodePath: 'mycc', chaincodeType: 'java', + goPath: undefined, targets: ['peer'] }; const response = await client.installChaincode(request); @@ -1723,7 +1726,8 @@ describe('Client', () => { version: '0.0.1', path: 'mycc', type: 'java', - metadataPath: 'mycc/META-INF' + metadataPath: 'mycc/META-INF', + goPath: undefined }).resolves(smartContractPackage); getTargetPeersStub.withArgs(['peer']).returns(['peer']); const request = { @@ -1732,7 +1736,8 @@ describe('Client', () => { chaincodePath: 'mycc', chaincodeType: 'java', metadataPath: 'mycc/META-INF', - targets: ['peer'] + targets: ['peer'], + goPath: undefined }; const response = await client.installChaincode(request); sinon.assert.calledWith(getTargetPeersStub, ['peer']); @@ -1755,7 +1760,7 @@ describe('Client', () => { client.setDevMode(true); const fromDirectoryStub = sinon.stub(Package, 'fromDirectory').rejects(new Error('such error')); getTargetPeersStub.withArgs(['peer']).returns(['peer']); - const request = {chaincodeId: 'mycc', chaincodeVersion: '0.0.1', chaincodePath: 'mycc', targets: ['peer']}; + const request = {chaincodeId: 'mycc', chaincodeVersion: '0.0.1', chaincodePath: 'mycc', targets: ['peer'], goPath: undefined}; const response = await client.installChaincode(request); sinon.assert.calledWith(getTargetPeersStub, ['peer']); sinon.assert.notCalled(fromDirectoryStub); @@ -1776,7 +1781,7 @@ describe('Client', () => { it('should install using a chaincode package', async () => { const fromDirectoryStub = sinon.stub(Package, 'fromDirectory').rejects(new Error('such error')); getTargetPeersStub.withArgs(['peer']).returns(['peer']); - const request = {chaincodePackage: smartContractPackageBytes, targets: ['peer']}; + const request = {chaincodePackage: smartContractPackageBytes, targets: ['peer'], goPath: undefined}; const response = await client.installChaincode(request); sinon.assert.calledWith(getTargetPeersStub, ['peer']); sinon.assert.notCalled(fromDirectoryStub); @@ -1800,7 +1805,8 @@ describe('Client', () => { version: '0.0.1', path: 'mycc', type: undefined, - metadataPath: undefined + metadataPath: undefined, + goPath: undefined }).resolves(smartContractPackage); getTargetPeersStub.returns(['peer']); const request = { @@ -1809,7 +1815,8 @@ describe('Client', () => { chaincodePath: 'mycc', targets: [], channelNames: [], - txId: {isAdmin: isAdminStub, getNonce: getNonceStub, getTransactionID: getTransactionIDStub} + txId: {isAdmin: isAdminStub, getNonce: getNonceStub, getTransactionID: getTransactionIDStub, + goPath: undefined} }; const response = await client.installChaincode(request); sinon.assert.calledWith(getTargetPeersStub, []); @@ -1833,7 +1840,8 @@ describe('Client', () => { version: '0.0.1', path: 'mycc', type: undefined, - metadataPath: undefined + metadataPath: undefined, + goPath: undefined }).resolves(smartContractPackage); getTargetPeersStub.returns(['peer']); const request = { @@ -1842,7 +1850,8 @@ describe('Client', () => { chaincodePath: 'mycc', targets: [], channelNames: [], - txId: {isAdmin: isAdminStub, getNonce: getNonceStub, getTransactionID: getTransactionIDStub} + txId: {isAdmin: isAdminStub, getNonce: getNonceStub, getTransactionID: getTransactionIDStub}, + goPath: undefined }; const response = await client.installChaincode(request); sinon.assert.calledWith(getTargetPeersStub, []); @@ -1866,7 +1875,8 @@ describe('Client', () => { version: '0.0.1', path: 'mycc', type: undefined, - metadataPath: undefined + metadataPath: undefined, + goPath: undefined }).resolves(smartContractPackage); getTargetPeersStub.returns(); getPeersForOrgOnChannelStub.withArgs(['mychannel']).returns(['peer']); @@ -1874,7 +1884,8 @@ describe('Client', () => { chaincodeId: 'mycc', chaincodeVersion: '0.0.1', chaincodePath: 'mycc', - channelNames: ['mychannel'] + channelNames: ['mychannel'], + goPath: undefined }; const response = await client.installChaincode(request); sinon.assert.calledWith(getTargetPeersStub, undefined);