Git Product home page Git Product logo

ibm-blockchain-js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ibm-blockchain-js's Issues

Init_marble function call failed

Trying to use example code to use ibm-blockchain-js.

my sample code:

// Starting out by requiring all dependancies
var Ibc = require ('ibm-blockchain-js');
var ibc = new Ibc();
// Then define new instances that will be needed

var chaincode = {};
// configure ibc-js sdk by defining options
var options = {
network:{
peers: [{
"api_host": "864acfab0a734673a4f99844a8b02129-vp0.us.blockchain.ibm.com",
"api_port": 444,
"api_port_tls": 444,
"id": "864acfab0a734673a4f99844a8b02129-vp0",
"api_url": "http://864acfab0a734673a4f99844a8b02129-vp0.us.blockchain.ibm.com:444"
}],
users: [{
"username": "user_type1_1",
"secret": "2b19ed2755",
"enrollId": "user_type1_1",
"enrollSecret": "2b19ed2755"
}],
options:{
quiet: false,
timeout: 60000
}
},
chaincode:{
zip_url: 'https://github.com/ibm-blockchain/marbles/archive/v1.0.zip',
unzip_dir: 'marbles-1.0/chaincode/part1',
git_url: 'http://gopkg.in/ibm-blockchain/marbles.v1/chaincode/part1',
deployed_name: null
}
};

// Load the Marbles1 chaincode, with defined options, and return call-back-when-ready function.
ibc.load(options, cb_ready);

// Define the call-back-when-ready function returned above
// call-back-when-ready function has err
function cb_ready(err, cc){
//response has chaincode functions
//app1.setup(ibc, cc);
//app2.setup(ibc, cc);
// if the deployed name is blank, then chaincode has not been deployed
chaincode = cc;
if(cc.details.deployed_name === null){
cc.deploy('init', ['99'], null, cb_deployed);
}
else{
console.log('chaincode summary file indicates chaincode has been previously deployed');
cb_deployed();
}
}
// Step 5 ==================================
function cb_deployed(err){
console.log('sdk has deployed code and waited');
//chaincode.query.read(['a']);
chaincode.invoke.init_marble("marble1", "blue", "35", "mdonthi", cb_invoked);
}
function cb_invoked(e, a){
console.log('response: ', e, a);
}

logs looks like:

ibc-js] Peer: 864acfab0a734673a4f99844a8b02129-vp0-864acfab0a73...:444
[ibc-js] Registering 864acfab0a734673a4f99844a8b02129-vp0-864acfab0a73...:444 w/enrollId - user_type1_1
[https POST - b] /registrar
body: {"enrollId":"user_type1_1","enrollSecret":"2b19ed2755"}
[https POST - b] Status code: 200
[ibc-js] Registration success x1 : user_type1_1
[ibc-js] removing temp dir
[ibc-js] Downloading zip
redirect... https://codeload.github.com/IBM-Blockchain/marbles/zip/v1.0
[ibc-js] Downloading zip
[ibc-js] Unzipping zip
[ibc-js] Unzip done
[ibc-js] Scanning files [ 'part1_chaincode.go' ]
[ibc-js] Parsing file for shim version
[ibc-js] Found shim version: github.com/hyperledger/fabric/core/chaincode/shim
[ibc-js] Parsing file for invoke functions - part1_chaincode.go
[ibc-js] Found cc invoke function: init
[ibc-js] Found cc invoke function: delete
[ibc-js] Found cc invoke function: write
[ibc-js] Found cc invoke function: init_marble
[ibc-js] Found cc invoke function: set_user
[ibc-js] Parsing file for query functions - part1_chaincode.go
[ibc-js] Found cc query function: read
[ibc-js] load_chaincode() finished
[ibc-js] Deploy Chaincode - Starting
[ibc-js] function: init , arg: [ '99' ]

 Waiting...

[https POST - m] /chaincode
body: {"jsonrpc":"2.0","method":"deploy","params":{"type":1,"chaincodeID":{"path":"http://gopkg.in/ibm-blockchain/marbles.v1/chaincode/part1"},"ctorMsg":{"function":"init","args":["99"]},"secureContext":"user_type1_1"},"id":1478646962678}
[https POST - m] Status code: 200

 deploy success [waiting another 45 seconds]
 5836a766abb5f6585af53aebeba3be92153f991b7406456c98cf03313e0f27325d59bacaaf3ad2b76a05e6b80789ed6bb570fd17ef16e9ac6487f268f6f25b26 

[ibc-js] Deploy Chaincode - Complete
sdk has deployed code and waited
[https POST - e] /chaincode
body: {"jsonrpc":"2.0","method":"invoke","params":{"type":1,"chaincodeID":{"name":"5836a766abb5f6585af53aebeba3be92153f991b7406456c98cf03313e0f27325d59bacaaf3ad2b76a05e6b80789ed6bb570fd17ef16e9ac6487f268f6f25b26"},"ctorMsg":{"function":"init_marble","args":"marble1"},"secureContext":"blue"},"id":1478647016573}
[https POST - e] Status code: 400
[https POST - e] Error - status code: 400 {"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Error unmarshalling chaincode request payload: json: cannot unmarshal string into Go value of type []string"},"id":null}
[ibc-js] init_marble - failure: 400 { jsonrpc: '2.0',
error:
{ code: -32700,
message: 'Parse error',
data: 'Error unmarshalling chaincode request payload: json: cannot unmarshal string into Go value of type []string' },
id: null }
/Users/maruthidonthi/Desktop/cc126-blockchain/bluemix/node_modules/ibm-blockchain-js/index.js:914
if(cb) cb(helper.eFmt('invoke() error', statusCode, e), null);
^

TypeError: cb is not a function
at Object.options.failure (/Users/maruthidonthi/Desktop/cc126-blockchain/bluemix/node_modules/ibm-blockchain-js/index.js:914:12)
at failure (/Users/maruthidonthi/Desktop/cc126-blockchain/bluemix/node_modules/ibm-blockchain-js/lib/rest.js:119:30)
at IncomingMessage. (/Users/maruthidonthi/Desktop/cc126-blockchain/bluemix/node_modules/ibm-blockchain-js/lib/rest.js:209:5)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)

ChainCode object coming null in callback function

var fs = require('fs');
var Ibc1 = require('ibm-blockchain-js');
var ibc = new Ibc1();
var chaincode = {};
var creds = fs.readFileSync('creds.json')
var opt = JSON.parse(creds);
console.log(opt.peers)
var options = {
network:{
peers: opt.peers,
users: opt.users,
options: { //this is optional
quiet: true,
timeout: 60000
}
},
chaincode:{
zip_url: 'https://github.com/coderundebug12/sample-master.zip',
unzip_dir: 'sample-master',
git_url: 'https://github.com/coderundebug12/sample'
}
};

ibc.load(options, function(err, cc){
console.log(cc)
});

Deployment failed

I am trying to deploy marbles chaincode using ibm-blockchain-js.

Here is my Code:

// Starting out by requiring all dependancies
var Ibc = require ('ibm-blockchain-js');
 var ibc = new Ibc();
// Then define new instances that will be needed

var chaincode = {};


// configure ibc-js sdk by defining options
var options = {
    network:{
      peers: [{
        "api_host": "xxxxxxxxxxxxxxx",
        "api_port": 444,
        "api_port_tls": 444,
        "id": "xxxxxx",
        "api_url": "http://xxxxxx.us.blockchain.ibm.com:444"
      }],
      users: [{
        "username": "user_type1_0",
        "secret": "xxxxx",
        "enrollId": "user_type1_0",
        "enrollSecret": "xxxxxxx"
      }],
      options:{
        quiet: false,
        timeout: 60000
      }
    },
    chaincode:{
            zip_url: 'https://github.com/ibm-blockchain/marbles-chaincode/archive/master.zip',
            unzip_dir: 'marbles-chaincode-master/part2',
            git_url: 'https://github.com/ibm-blockchain/marbles-chaincode/part2',
            deployed_name: null
        },
  };

// Load the Marbles2 chaincode, with defined options, and return call-back-when-ready function.
ibc.load(options, cb_ready);

// Define the call-back-when-ready function returned above
// call-back-when-ready function has err
function cb_ready(err, cc){
	//response has chaincode functions
  //app1.setup(ibc, cc);
  //app2.setup(ibc, cc);
	// if the deployed name is blank, then chaincode has not been deployed
	if(cc.details.deployed_name === null){
        cc.deploy('init', ['99'], {save_path: './cc_summaries', delay_ms: 60000}, cb_deployed);
  	}
  	else{
  		console.log('chaincode summary file indicates chaincode has been previously deployed');
      cb_deployed();
	}
}
// Step 5 ==================================
    function cb_deployed(err){
        console.log('sdk has deployed code and waited');
        //chaincode.query.read(['a']);
    }

When I try to execute I got the deployment error 400. Here is my logs looks like:

[ibc-js] Peer: 864acfab0a734673a4f99844a8b02129-vp0-864acfab0a73...:444
[ibc-js] No membership users found after filtering, assuming this is a network w/o membership
[ibc-js] removing temp dir
[ibc-js] Downloading zip
redirect... https://codeload.github.com/IBM-Blockchain/marbles-chaincode/zip/master
[ibc-js] Downloading zip
[ibc-js] Unzipping zip
[ibc-js] Unzip done
[ibc-js] Scanning files [ 'part2_chaincode.go' ]
[ibc-js] Parsing file for shim version
[ibc-js] Found shim version: github.com/openblockchain/obc-peer/openchain/chaincode/shim
[ibc-js] Parsing file for invoke functions - part2_chaincode.go
[ibc-js] Found cc invoke function: init
[ibc-js] Found cc invoke function: delete
[ibc-js] Found cc invoke function: write
[ibc-js] Found cc invoke function: init_marble
[ibc-js] Found cc invoke function: set_user
[ibc-js] Found cc invoke function: open_trade
[ibc-js] Found cc invoke function: perform_trade
[ibc-js] Found cc invoke function: remove_trade
[ibc-js] Parsing file for query functions - part2_chaincode.go
[ibc-js] Found cc query function: read
[ibc-js] load_chaincode() finished
[ibc-js] Deploy Chaincode - Starting
[ibc-js] function: init , arg: [ '99' ]

 Waiting...

[https POST - z] /devops/deploy
body: {"type":"GOLANG","chaincodeID":{"path":"https://github.com/ibm-blockchain/marbles-chaincode/part2"},"ctorMsg":{"function":"init","args":["99"]}}
[https POST - z] Status code: 400
[https POST - z] Error - status code: 400 {"Error": "Must supply username for chaincode when security is enabled."}
[ibc-js] deploy - failure: 400

Any Help would be helpful. Thanks in advance.

Querying error not handled

When querying a chaincode, the "error" field of the response it not treated as an error.

Example :
[ibc-js] get_all_clients - success: { jsonrpc: '2.0', error: { code: -32000, message: 'Registration missing', data: 'User not logged in. Use the \'/registrar\' endpoint to obtain a security token.' }, id: 1465917260947 }

When the response is as shown, the specified callback is called with its first parameter as null and the second as undefined (respectively corresponding to error and result).

The problem is, you could not have any information about this error in the scope of the callback function.

Chaincode with commented functions = faults

Leaving functions intact but commented in Chaincode results in false positives

As of ruslan-ardashev/marbles-chaincode@830007b,

[ibc-js] Scanning files [ 'part2_works_with_sdk_v1.0.0.go' ]
[ibc-js] Parsing file for invoke functions - part2_works_with_sdk_v1.0.0.go
[ibc-js] Found cc invoke function:  init
[ibc-js] Found cc invoke function:  delete
[ibc-js] Found cc invoke function:  write
[ibc-js] Found cc invoke function:  init_marble
[ibc-js] Found cc invoke function:  set_user
[ibc-js] Found cc invoke function:  open_trade
[ibc-js] Found cc invoke function:  perform_trade
[ibc-js] Found cc invoke function:  remove_trade
[ibc-js] Parsing file for query functions - part2_works_with_sdk_v1.0.0.go
[ibc-js] Found cc query function:  read
[ibc-js] load_chaincode() finished

Removing commented functions works as expected
ruslan-ardashev/marbles-chaincode@cd9a0a4

(no invoke functions found, as expected)

[ibc-js] Parsing file for query functions - part2_works_with_sdk_v1.0.0.go
[ibc-js] Found cc query function:  read
[ibc-js] load_chaincode() finished

Looks like a parsing issue

fs.access error

When I node start, I receive the following error. How can I fix this?

    fs.access(unzip_cc_dest, cb_file_exists);                                       //check if files exist ye
       ^

TypeError: Object # has no method 'access'
at cb_ready (/root/marbles/node_modules/ibm-blockchain-js/index.js:181:6)
at /root/marbles/node_modules/ibm-blockchain-js/lib/helper.js:44:4
at Object.oncomplete (fs.js:107:15)

Test cases should load the module from within itself

Test cases should do

var ibc = require('../')

instead of

var ibc = require('ibm-blockchain-js')

because the latter requires either the user to install the npm globally, in which case the user isn't actually testing the version on master.

filter_users function limits use of custom usernames in obcca

The following filter is being applied inside the ibc.register() function in order to filter out the users that are of the 'client' usertype. However, this function seems to be specifically build for the standard demo in which the usernames as given in the Marbles demo - app.js file start with user_type1_ .

`//==================================================================
//filter_users() - only get client level usernames - [1=client, 2=nvp, 4=vp, 8=auditor accurate as of 2/18]
//==================================================================
function filter_users(users){

var valid_users = [];
for(var i = 0; i < users.length; i++) {

    if(users[i].username.indexOf('user_type1') == 0){       //type should be 1 for client
        valid_users.push(users[i]);
    }
}
return valid_users;

}`

Suggestion would be to give the user object an additional attribute to store their user type which the SDK filter_users function can filter on.

no local chaincode deployment

I run takes marvels chaincode local download, it did not find the directory connection ...

Under inde part of the js code, I'd like to run the js chaincode local, download the code in relation to the local server time-consuming just to be running on the local server.

How can I change non-zip and unzip and local chaincode call in the following?

        zip_url: 'https://github.com/ibm-blockchain/marbles-chaincode/archive/master.zip', 
        unzip_dir: 'marbles-chaincode-master / part2_v1.0.0', 
        git_url: 'https://github.com /ibm-blockchain/marbles-chaincode/part2_v1.0.0 '

ibc.chain_stats times out bescause default_options in rest.js is modified

The symptom is that the http get called from ibc.prototype.chain_stats times out.

The culprit is mergeBtoA. It copies properties from default_options into the passed options object. That passed object is subsequently modifed to add options.header.content-length property. The problem here is that the header object is actually still the default_options.header object. So the default header is modified and that content length is incorrectly specified for a subsequent get calls that should have no content-length specified.

Commit c10ac4276228657e4de3f9b1fd4023e368bd9575 tries to fix this bug by deleting the content-length property when body is empty. However this is not a complete fix as other header properties will still be potentially incorrect. The right fix is to modify mergeBtoA:

            a[i] = JSON.parse(JSON.stringify(b[i]));

This (deep) clones a new object instead of substituting the one from default_options.

Also probably bad practice to modify the passed options object. A similar strategy could be employed to clone it as well.

Shadowing blockchain history?

I have a demo application on bluemix blockchain where I need to access state history. I'm not sure blockchain-js has sufficient function to allow that.

The application is a real use case of a county assessor's office. There are owners and there are property titles that can be transferred between owners. When viewing a property title, it is necessary to list the ownership history. I had previously implemented this application using the Open Assets protocol atop the bitcoin blockchain.

I understand the blockchain itself does not support history, so it is necessary to shadow history. I looked at using ibc.monitor_blockheight to trigger on every block a read the blockchain state using chaincode.read. But that doesn't work as the state could have changed multiple times before it is read.

Is there a better way to save or access history as needed for my application? Or is some protocol/API development needed to support that?

How to find the summaries file?

i cannot find .cc_summaries file. I am not able to successfully deploy the chaincode as it is giving me 'chaincode summary file indicates chaincode has been previously deployed'. However there is no deployed chaincode in the temp folder. What can be the issues? Please suggest some measures i need to take to sort out this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.