Skip to content

Commit eee5833

Browse files
authored
Swap to using the published fabric-protos libraries (#320)
Move the codebase to directly using the published protobuf libraries. The fabric-protos repo, as well as holding the 'main' copy of the protos, also publishes packages for each language These can then be pulled dirctly here; everything under version control. Removes the need to the copies of the protobufs held locally in this repo. Signed-off-by: Matthew B White <whitemat@uk.ibm.com>
1 parent ebf16ea commit eee5833

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+5144
-97250
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 928 additions & 2463 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libraries/fabric-shim/bundle.d.ts

Lines changed: 0 additions & 26085 deletions
This file was deleted.

libraries/fabric-shim/bundle.js

Lines changed: 0 additions & 63443 deletions
This file was deleted.

libraries/fabric-shim/google-protos/google/protobuf/empty.proto

Lines changed: 0 additions & 53 deletions
This file was deleted.

libraries/fabric-shim/google-protos/google/protobuf/timestamp.proto

Lines changed: 0 additions & 110 deletions
This file was deleted.

libraries/fabric-shim/lib/chaincode.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* eslint-disable no-useless-escape */
77
'use strict';
88

9-
const fabprotos = require('../bundle');
9+
1010
const util = require('util');
1111
const {Certificate} = require('@fidm/x509');
1212
const Logger = require('./logger');
@@ -21,6 +21,8 @@ const ChaincodeStub = require('./stub');
2121
const KeyEndorsementPolicy = require('./utils/statebased');
2222
const fs = require('fs');
2323

24+
const {peer} = require('@hyperledger/fabric-protos');
25+
2426
const StartCommand = require('./cmds/startCommand.js');
2527

2628
const yargs = require('yargs');
@@ -125,15 +127,15 @@ class Shim {
125127

126128
const chaincodeName = opts['chaincode-id-name'];
127129
const client = new ChaincodeSupportClient(chaincode, url, optsCpy);
128-
const chaincodeID = {
129-
name: chaincodeName
130-
};
131130

132131
logger.info(util.format('Registering with peer %s as chaincode "%s"', opts['peer.address'], chaincodeName));
133132

133+
const chaincodePB = new peer.ChaincodeID();
134+
chaincodePB.setName(chaincodeName);
135+
134136
client.chat({
135-
type: fabprotos.protos.ChaincodeMessage.Type.REGISTER,
136-
payload: fabprotos.protos.ChaincodeID.encode(chaincodeID).finish()
137+
type: peer.ChaincodeMessage.Type.REGISTER,
138+
payload: chaincodePB.serializeBinary()
137139
});
138140

139141
// return the client object to give the calling code
@@ -256,7 +258,7 @@ class ClientIdentity {
256258
this.mspId = signingId.mspid;
257259

258260
this.idBytes = signingId.idBytes;
259-
const normalizedCert = normalizeX509(this.idBytes.toString(), loggerPrefix);
261+
const normalizedCert = normalizeX509(new TextDecoder().decode(this.idBytes), loggerPrefix);
260262

261263
// assemble the unique ID based on certificate
262264
const certificate = Certificate.fromPEM(normalizedCert);

libraries/fabric-shim/lib/contract-spi/chaincodefromcontract.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class ChaincodeFromContract {
8686
_compileSchemas() {
8787

8888
const schemaList = [];
89-
for (const name in this.metadata.components.schemas) {
90-
const s = this.metadata.components.schemas[name];
89+
for (const name in this.metadata.components.schemas) {
90+
const s = this.metadata.components.schemas[name];
9191

9292
schemaList.push(s);
9393
}
@@ -316,7 +316,7 @@ class ChaincodeFromContract {
316316
* The invokeFunctionality function is called for all the invoke operations; init is also redirected to here
317317
*
318318
* @param {ChaincodeStub} stub Stub class giving the full api
319-
* @param {Object} fAndP Function and Paramters obtained from the smart contract argument
319+
* @param {Object} fAndP Function and Paramters obtained from the smart contract argument
320320
*/
321321
async invokeFunctionality(stub) {
322322
const bufferArgs = stub.getBufferArgs();
@@ -335,6 +335,7 @@ class ChaincodeFromContract {
335335
const {contractName: cn, function: fn} = this._splitFunctionName(fAndP);
336336
logger.debug(`${loggerPrefix} Invoking ${cn} ${fn}`);
337337

338+
338339
const contractData = this.contractImplementations[cn];
339340
if (!contractData) {
340341
throw new Error(`Contract name is not known: ${cn}`);
@@ -350,8 +351,8 @@ class ChaincodeFromContract {
350351
ctx.setChaincodeStub(stub);
351352
ctx.setClientIdentity(new ClientIdentity(stub));
352353
ctx.logging = {
353-
setLevel : Logger.setLevel,
354-
getLogger : (name) => {
354+
setLevel: Logger.setLevel,
355+
getLogger: (name) => {
355356
return Logger.getLogger(name ? `${cn}:${name}` : cn);
356357
}
357358
};
@@ -363,7 +364,7 @@ class ChaincodeFromContract {
363364

364365
// if the function exists, then we can call it otherwise, call the unkownn tx handler
365366
if (functionExists) {
366-
367+
logger.debug(`${JSON.stringify(functionExists)}`);
367368
// marhsall the parameters into the correct types for hanlding by
368369
// the tx function
369370
const parameters = dataMarshall.handleParameters(functionExists, txArgs, loggerPrefix);
@@ -382,7 +383,7 @@ class ChaincodeFromContract {
382383
if (functionExists.returns) {
383384
returnSchema = functionExists.returns;
384385
}
385-
386+
logger.debug(`${JSON.stringify(result)},${returnSchema.schema}`);
386387
// returnSchema can be undefined if there is no return value - the datamarshall can handle that
387388
// return the data value, if any to the shim. Including converting the result to the wire format
388389
return shim.success(dataMarshall.toWireBuffer(result, returnSchema.schema, loggerPrefix));
@@ -398,19 +399,19 @@ class ChaincodeFromContract {
398399

399400
} catch (error) {
400401
// log the error and then fail the transaction
401-
logger.error(`${loggerPrefix} ${error.toString()}`);
402+
logger.error(`${loggerPrefix} ${error}`);
402403
return shim.error(error.message);
403404
}
404405
}
405406

406407
/**
407-
* Parse the fcn name to be name and function. These are separated by a :
408-
* Anything after the : is treated as the function name
409-
* No : implies that the whole string is a function name
410-
*
411-
* @param {String} fcn the combined function and name string
412-
* @return {Object} split into name and string
413-
*/
408+
* Parse the fcn name to be name and function. These are separated by a :
409+
* Anything after the : is treated as the function name
410+
* No : implies that the whole string is a function name
411+
*
412+
* @param {String} fcn the combined function and name string
413+
* @return {Object} split into name and string
414+
*/
414415
_splitFunctionName(fcn) {
415416
// Did consider using a split(':') call to do this; however I chose regular expression for
416417
// the reason that it provides definitive description.

0 commit comments

Comments
 (0)