Uploaded image for project: 'Fabric'
  1. Fabric
  2. FAB-14439

private data collection node-sdk sample not working

    XMLWordPrintable

Details

    Description

      As per example in the document: https://fabric-sdk-node.github.io/release-1.4/tutorial-private-data.html

      Reference Chaincode: https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode/marbles02_private

      The code in the document gives a bad proposal response.

      Here is the SDK log:

       

      2019-03-01T06:16:20.039Z - debug: [client-utils.js]: buildChannelHeader - type 3 channel_id mychannel tx_id NaN epoch null chaincode_id marble
      2019-03-01T06:16:20.042Z - debug: [client-utils.js]: buildProposal - adding in transientMap
      Unknown macro: { marblename}
      2019-03-01T06:16:20.056Z - debug: [crypto_ecdsa_aes]: ecdsa signature: negative=0, words=[37122400, 56231231, 47016136, 30581968, 6785216, 45689559, 34947538, 54145038, 22507532, 3105674, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], length=10, red=null, negative=0, words=[9694465, 61460886, 60646008, 56278728, 16513404, 39877521, 55050391, 50393339, 39001155, 1960412, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], length=10, red=null, recoveryParam=0
      2019-03-01T06:16:20.057Z - debug: [Remote.js]: getUrl::grpcs://somehost:7051
      2019-03-01T06:16:20.057Z - debug: [Peer.js]: sendProposal - Start ----org1-service-peer1 grpcs://somehost:7051
      2019-03-01T06:16:20.058Z - debug: [Remote.js]: getUrl::grpcs://somehost:7060
      2019-03-01T06:16:20.058Z - debug: [Peer.js]: sendProposal - Start ----org2-service-peer1 grpcs://somehost:7060
      2019-03-01T06:16:20.071Z - debug: [Remote.js]: Successfully connected to remote gRPC server
      2019-03-01T06:16:20.076Z - debug: [Remote.js]: Successfully connected to remote gRPC server
      2019-03-01T06:16:20.095Z - debug: [Peer.js]: sendProposal - Received proposal response from peer "grpcs://somehost:7060": status - 500
      2019-03-01T06:16:20.101Z - debug: [Peer.js]: sendProposal - Received proposal response from peer "grpcs://somehost:7051": status - 500
      2019-03-01T06:16:20.102Z - debug: [client-utils.js]: sendPeersProposal - Promise is rejected: Error: marble must be a key in the transient map
      2019-03-01T06:16:20.102Z - debug: [client-utils.js]: sendPeersProposal - Promise is rejected: Error: marble must be a key in the transient map

       
      As per the last error line in the log, even adding the following:
       
      var data = {"marble": transient_data}
      causes error of Illegal Buffer
       
      The chaincode expects marble as a key in the json and the value to be a base64 encoding of the transient JSON
       
      So, here is what worked:

      var transient_data = {
          'name': 'marble2', 
          'color': 'blue', 
          'size': 8, 
          'owner': 'Joe', 
          'price': 80 
      };
      var data = JSON.stringify(transient_data); // Convert transient data object to JSON string
      data = new Buffer(data).toString('base64'); // convert the JSON string to base64 encoded string
      var marble_private = { "marble": data };  //Add the encoded data as a value to the marble key expected by the marbles chaincode
      const tx_id = client.newTransactionID();
      tx_id_string = tx_id.getTransactionID();
      var request = {
          chaincodeId: 'marble',
          txId: tx_id,
          fcn: 'initMarble',
          args: [], // all data is transient data
          transientMap: marble_private, // private data
      };
      

       

      After running this the transaction is committed successfully.

       

      2019-03-01T06:40:12.694Z - debug: [client-utils.js]: buildChannelHeader - type 3 channel_id mychannel tx_id NaN epoch null chaincode_id marble3
      2019-03-01T06:40:12.698Z - debug: [client-utils.js]: buildProposal - adding in transientMap { marble: 'eyJuYW1lIjoibWFyYmxlNiIsImNvbG9yIjoiYmx1ZSIsInNpemUiOjgsIm93bmVyIjoiSm9lIiwicHJpY2UiOjgwfQ==' }
      2019-03-01T06:40:12.711Z - debug: [crypto_ecdsa_aes]: ecdsa signature: negative=0, words=[42134526, 50606244, 23915505, 49316395, 9771392, 1077880, 37773943, 15416817, 13714539, 1796388, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], length=10, red=null, negative=0, words=[14715548, 18008218, 6840247, 23891351, 53988489, 46167869, 10562088, 43343042, 35793986, 62966, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], length=10, red=null, recoveryParam=1
      2019-03-01T06:40:12.712Z - debug: [Remote.js]: getUrl::grpcs://somehost:7051
      2019-03-01T06:40:12.712Z - debug: [Peer.js]: sendProposal - Start ----org1-service-peer1 grpcs://somehost:7051
      2019-03-01T06:40:12.713Z - debug: [Remote.js]: getUrl::grpcs://somehost:7060
      2019-03-01T06:40:12.713Z - debug: [Peer.js]: sendProposal - Start ----org2-service-peer1 grpcs://somehost:7060
      2019-03-01T06:40:12.726Z - debug: [Remote.js]: Successfully connected to remote gRPC server
      2019-03-01T06:40:12.731Z - debug: [Remote.js]: Successfully connected to remote gRPC server
      2019-03-01T06:40:12.760Z - debug: [Peer.js]: sendProposal - Received proposal response from peer "grpcs://somehost:7051": status - 200
      2019-03-01T06:40:12.770Z - debug: [Peer.js]: sendProposal - Received proposal response from peer "grpcs://somehost:7060": status - 200
      2019-03-01T06:40:12.770Z - debug: [client-utils.js]: sendPeersProposal - Promise is fulfilled: [object Object]
      2019-03-01T06:40:12.771Z - debug: [client-utils.js]: sendPeersProposal - Promise is fulfilled: [object Object]

       
       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kshitij.sinha Kshitij Sinha
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: