@@ -448,8 +448,11 @@ ibc.prototype.block_stats = function(id, cb){
448448//read() - read generic variable from chaincode state
449449//============================================================================================================================
450450function read ( name , username , cb ) {
451- if ( typeof username === 'function' || ( username == null && cb == null ) ) {
452- cb = username ; //cb is in 2nd param OR null use known username
451+ if ( typeof username === 'function' ) { //if cb is in 2nd param use known username
452+ cb = username ;
453+ username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
454+ }
455+ if ( username == null ) { //if username not provided, use known valid one
453456 username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
454457 }
455458
@@ -485,10 +488,14 @@ function read(name, username, cb){
485488//query() - read generic variable from chaincode state
486489//============================================================================================================================
487490function query ( args , username , cb ) {
488- if ( typeof username === 'function' || ( username == null && cb == null ) ) {
489- cb = username ; //cb is in 2nd param OR null use known username
491+ if ( typeof username === 'function' ) { //if cb is in 2nd param use known username
492+ cb = username ;
490493 username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
491494 }
495+ if ( username == null ) { //if username not provided, use known valid one
496+ username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
497+ }
498+
492499 var options = {
493500 path : '/devops/query'
494501 } ;
@@ -521,10 +528,14 @@ function query(args, username, cb){
521528//write() - write generic variable to chaincode state
522529//============================================================================================================================
523530function write ( name , val , username , cb ) {
524- if ( typeof username === 'function' || ( username == null && cb == null ) ) {
525- cb = username ; //cb is in 2nd param OR null use known username
531+ if ( typeof username === 'function' ) { //if cb is in 2nd param use known username
532+ cb = username ;
526533 username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
527534 }
535+ if ( username == null ) { //if username not provided, use known valid one
536+ username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
537+ }
538+
528539 var options = {
529540 path : '/devops/invoke'
530541 } ;
@@ -558,10 +569,14 @@ function write(name, val, username, cb){
558569//remove() - delete a generic variable from chaincode state
559570//============================================================================================================================
560571function remove ( name , username , cb ) {
561- if ( typeof username === 'function' || ( username == null && cb == null ) ) {
562- cb = username ; //cb is in 2nd param OR null use known username
572+ if ( typeof username === 'function' ) { //if cb is in 2nd param use known username
573+ cb = username ;
563574 username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
564575 }
576+ if ( username == null ) { //if username not provided, use known valid one
577+ username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
578+ }
579+
565580 var options = {
566581 path : '/devops/invoke'
567582 } ;
@@ -626,10 +641,14 @@ ibc.prototype.register = function(index, enrollID, enrollSecret, cb) {
626641//deploy() - deploy chaincode and call a cc function
627642//============================================================================================================================
628643function deploy ( func , args , save_path , username , cb ) {
629- if ( typeof username === 'function' || ( username == null && cb == null ) ) {
630- cb = username ; //cb is in 2nd param OR null use known username
644+ if ( typeof username === 'function' ) { //if cb is in 2nd param use known username
645+ cb = username ;
646+ username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
647+ }
648+ if ( username == null ) { //if username not provided, use known valid one
631649 username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
632650 }
651+
633652 console . log ( '[ibc-js] Deploying Chaincode - Starting' ) ;
634653 console . log ( '[ibc-js] \tfunction:' , func , ', arg:' , args ) ;
635654 console . log ( '\n\n\t Waiting...' ) ; //this can take awhile
@@ -728,10 +747,14 @@ function build_chaincode_func(name){
728747 console . log ( '[ibc-js] Found cc function: ' , name ) ;
729748 ibc . chaincode . details . func . push ( name ) ;
730749 ibc . chaincode [ name ] = function ( args , username , cb ) { //create the function in the chaincode obj
731- if ( typeof username === 'function' || ( username == null && cb == null ) ) {
732- cb = username ; //cb is in 2nd param OR null use known username
750+ if ( typeof username === 'function' ) { //if cb is in 2nd param use known username
751+ cb = username ;
752+ username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
753+ }
754+ if ( username == null ) { //if username not provided, use known valid one
733755 username = ibc . chaincode . details . peers [ ibc . selectedPeer ] . user ;
734756 }
757+
735758 var options = { path : '/devops/invoke' } ;
736759 var body = {
737760 chaincodeSpec : {
0 commit comments