Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fabric-shim

Package Overview
Dependencies
Maintainers
2
Versions
304
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fabric-shim - npm Package Compare versions

Comparing version 1.3.0-snapshot.18 to 1.3.0-snapshot.19

30

lib/contract-spi/chaincodefromcontract.js

@@ -99,5 +99,3 @@ /*

let splitFcn = fcn.split('.');
let fn = splitFcn.pop();
let ns = splitFcn.join('.');
let {namespace:ns,function:fn} = this._splitFunctionName(fcn);

@@ -115,3 +113,2 @@ if (!this.contracts[ns]){

if (functionExists) {
// before tx fn

@@ -136,2 +133,27 @@ await contractInstance.beforeTransaction(ctx);

/**
* Parse the fcn name to be namespace 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 namespace 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.
// Split will just split - you would then need to write the code to handle edge cases
// for no input, for multiple :, for multiple : without intervening characters
// https://regex101.com/ is very useful for understanding
const regex = /([^:]*)(?::|^)(.*)/g;
let result = {namespace:'',function:''};
let m = regex.exec(fcn);
result.namespace = m[1];
result.function = m[2];
return result;
}
/**
* get information on the contracts

@@ -138,0 +160,0 @@ */

2

package.json
{
"name": "fabric-shim",
"version": "1.3.0-snapshot.18",
"version": "1.3.0-snapshot.19",
"description": "A node.js implementation of Hyperledger Fabric chaincode shim, to allow endorsing peers and user-provided chaincodes to communicate with each other",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -203,3 +203,3 @@ /*

stubInterface.getFunctionAndParameters.returns({
fcn:'alpha.alpha',
fcn:'alpha:alpha',
params: [ 'arg1','arg2' ]

@@ -262,3 +262,3 @@ } );

stubInterface.getFunctionAndParameters.returns({
fcn:'beta.beta',
fcn:'beta:beta',
params: [ 'arg1','arg2' ]

@@ -319,3 +319,3 @@ } );

stubInterface.getFunctionAndParameters.returns({
fcn:'beta.beta',
fcn:'beta:beta',
params: [ 'arg1','arg2' ]

@@ -376,3 +376,3 @@ } );

stubInterface.getFunctionAndParameters.returns({
fcn:'wibble.alpha',
fcn:'wibble:alpha',
params: [ 'arg1','arg2' ]

@@ -400,3 +400,3 @@ } );

stubInterface.getFunctionAndParameters.returns({
fcn:'alpha.wibble',
fcn:'alpha:wibble',
params: [ 'arg1','arg2' ]

@@ -464,3 +464,3 @@ } );

stubInterface.getFunctionAndParameters.returns({
fcn:'org.hyperledger.fabric.getMetaData',
fcn:'org.hyperledger.fabric:getMetaData',
params: [ 'arg1','arg2' ]

@@ -504,2 +504,35 @@ } );

describe('#_splitFunctionName',()=>{
let cc;
beforeEach(()=>{
// actual contract instance is not important for this test
cc = new ChaincodeFromContract([SCBeta]);
});
it('should handle the usual case of ns:fn',()=>{
let result= cc._splitFunctionName('namespace:function');
result.should.deep.equal({namespace:'namespace',function:'function'});
});
it('should handle the case of no namespace explicit',()=>{
let result = cc._splitFunctionName(':function');
result.should.deep.equal({namespace:'',function:'function'});
});
it('should handle the case of no namespace implict',()=>{
let result = cc._splitFunctionName('function');
result.should.deep.equal({namespace:'',function:'function'});
});
it('should handle the case of no input',()=>{
let result = cc._splitFunctionName('');
result.should.deep.equal({namespace:'',function:''});
});
it('should handle the case of multiple :',()=>{
let result = cc._splitFunctionName('namespace:function:with:colons:');
result.should.deep.equal({namespace:'namespace',function:'function:with:colons:'});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc