Skip to content

Commit

Permalink
Swap to using the published fabric-protos libraries (#320)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mbwhite committed May 26, 2022
1 parent ebf16ea commit eee5833
Show file tree
Hide file tree
Showing 62 changed files with 5,144 additions and 97,250 deletions.
3,391 changes: 928 additions & 2,463 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

26,085 changes: 0 additions & 26,085 deletions libraries/fabric-shim/bundle.d.ts

This file was deleted.

63,443 changes: 0 additions & 63,443 deletions libraries/fabric-shim/bundle.js

This file was deleted.

53 changes: 0 additions & 53 deletions libraries/fabric-shim/google-protos/google/protobuf/empty.proto

This file was deleted.

110 changes: 0 additions & 110 deletions libraries/fabric-shim/google-protos/google/protobuf/timestamp.proto

This file was deleted.

16 changes: 9 additions & 7 deletions libraries/fabric-shim/lib/chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* eslint-disable no-useless-escape */
'use strict';

const fabprotos = require('../bundle');

const util = require('util');
const {Certificate} = require('@fidm/x509');
const Logger = require('./logger');
Expand All @@ -21,6 +21,8 @@ const ChaincodeStub = require('./stub');
const KeyEndorsementPolicy = require('./utils/statebased');
const fs = require('fs');

const {peer} = require('@hyperledger/fabric-protos');

const StartCommand = require('./cmds/startCommand.js');

const yargs = require('yargs');
Expand Down Expand Up @@ -125,15 +127,15 @@ class Shim {

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

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

const chaincodePB = new peer.ChaincodeID();
chaincodePB.setName(chaincodeName);

client.chat({
type: fabprotos.protos.ChaincodeMessage.Type.REGISTER,
payload: fabprotos.protos.ChaincodeID.encode(chaincodeID).finish()
type: peer.ChaincodeMessage.Type.REGISTER,
payload: chaincodePB.serializeBinary()
});

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

this.idBytes = signingId.idBytes;
const normalizedCert = normalizeX509(this.idBytes.toString(), loggerPrefix);
const normalizedCert = normalizeX509(new TextDecoder().decode(this.idBytes), loggerPrefix);

// assemble the unique ID based on certificate
const certificate = Certificate.fromPEM(normalizedCert);
Expand Down
31 changes: 16 additions & 15 deletions libraries/fabric-shim/lib/contract-spi/chaincodefromcontract.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class ChaincodeFromContract {
_compileSchemas() {

const schemaList = [];
for (const name in this.metadata.components.schemas) {
const s = this.metadata.components.schemas[name];
for (const name in this.metadata.components.schemas) {
const s = this.metadata.components.schemas[name];

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


const contractData = this.contractImplementations[cn];
if (!contractData) {
throw new Error(`Contract name is not known: ${cn}`);
Expand All @@ -350,8 +351,8 @@ class ChaincodeFromContract {
ctx.setChaincodeStub(stub);
ctx.setClientIdentity(new ClientIdentity(stub));
ctx.logging = {
setLevel : Logger.setLevel,
getLogger : (name) => {
setLevel: Logger.setLevel,
getLogger: (name) => {
return Logger.getLogger(name ? `${cn}:${name}` : cn);
}
};
Expand All @@ -363,7 +364,7 @@ class ChaincodeFromContract {

// if the function exists, then we can call it otherwise, call the unkownn tx handler
if (functionExists) {

logger.debug(`${JSON.stringify(functionExists)}`);
// marhsall the parameters into the correct types for hanlding by
// the tx function
const parameters = dataMarshall.handleParameters(functionExists, txArgs, loggerPrefix);
Expand All @@ -382,7 +383,7 @@ class ChaincodeFromContract {
if (functionExists.returns) {
returnSchema = functionExists.returns;
}

logger.debug(`${JSON.stringify(result)},${returnSchema.schema}`);
// returnSchema can be undefined if there is no return value - the datamarshall can handle that
// return the data value, if any to the shim. Including converting the result to the wire format
return shim.success(dataMarshall.toWireBuffer(result, returnSchema.schema, loggerPrefix));
Expand All @@ -398,19 +399,19 @@ class ChaincodeFromContract {

} catch (error) {
// log the error and then fail the transaction
logger.error(`${loggerPrefix} ${error.toString()}`);
logger.error(`${loggerPrefix} ${error}`);
return shim.error(error.message);
}
}

/**
* Parse the fcn name to be name and function. These are separated by a :
* Anything after the : is treated as the function name
* No : implies that the whole string is a function name
*
* @param {String} fcn the combined function and name string
* @return {Object} split into name and string
*/
* Parse the fcn name to be name and function. These are separated by a :
* Anything after the : is treated as the function name
* No : implies that the whole string is a function name
*
* @param {String} fcn the combined function and name string
* @return {Object} split into name and string
*/
_splitFunctionName(fcn) {
// Did consider using a split(':') call to do this; however I chose regular expression for
// the reason that it provides definitive description.
Expand Down

0 comments on commit eee5833

Please sign in to comment.