Hyperledger Fabric How to retrieve result from Fabric Transaction

0 votes

The object that I get from this is Undefined. 

async submit(resource, method) {
    try{
      this.businessNetworkDefinition = await this.bizNetworkConnection.connect(cardname);
      if (!this.businessNetworkDefinition) {
        console.log("Error in network connection");
        throw "Error in network connection";
      }

      let factory        = this.businessNetworkDefinition.getFactory();
      let transaction    = factory.newTransaction(NS, method);

      Object.assign(transaction, resource)
      return await this.bizNetworkConnection.submitTransaction(transaction);
    }catch(error){
      console.log(error);
      throw error;
    }
  }
Nov 8, 2018 in Blockchain by slayer
• 29,370 points
1,913 views

1 answer to this question.

0 votes
invokeChainCode(securityContext, functionName, args, options) {
        const method = 'invokeChainCode';
        LOG.entry(method, securityContext, functionName, args, options);

        if (!this.businessNetworkIdentifier) {
            return Promise.reject(new Error('No business network has been specified for this connection'));
        }

        // Check that a valid security context has been specified.
        HLFUtil.securityCheck(securityContext);

        // Validate all the arguments.
        if (!functionName) {
            return Promise.reject(new Error('functionName not specified'));
        } else if (!Array.isArray(args)) {
            return Promise.reject(new Error('args not specified'));
        }

        try {
            args.forEach((arg) => {
                if (typeof arg !== 'string') {
                    throw new Error('invalid arg specified: ' + arg);
                }
            });
        } catch(error) {
            return Promise.reject(error);
        }

        let txId = this._validateTxId(options);

        let eventHandler;

        // initialize the channel if it hasn't been initialized already otherwise verification will fail.
        LOG.debug(method, 'loading channel configuration');
        return this._initializeChannel()
            .then(() => {

                // check the event hubs and reconnect if possible. Do it here as the connection attempts are asynchronous
                this._checkEventhubs();

                // Submit the transaction to the endorsers.
                const request = {
                    chaincodeId: this.businessNetworkIdentifier,
                    txId: txId,
                    fcn: functionName,
                    args: args
                };
                return this.channel.sendTransactionProposal(request); // node sdk will target all peers on the channel that are endorsingPeer
            })
            .then((results) => {
                // Validate the endorsement results.
                LOG.debug(method, `Received ${results.length} result(s) from invoking the composer runtime chaincode`, results);
                const proposalResponses = results[0];
                let {validResponses} = this._validatePeerResponses(proposalResponses, true);

                // Submit the endorsed transaction to the primary orderers.
                const proposal = results[1];
                const header = results[2];

                // check that we have a Chaincode listener setup and ready.
                this._checkCCListener();
                eventHandler = HLFConnection.createTxEventHandler(this.eventHubs, txId.getTransactionID(), this.commitTimeout);
                eventHandler.startListening();
                return this.channel.sendTransaction({
                    proposalResponses: validResponses,
                    proposal: proposal,
                    header: header
                });
            })
            .then((response) => {
                // If the transaction was successful, wait for it to be committed.
                LOG.debug(method, 'Received response from orderer', response);

                if (response.status !== 'SUCCESS') {
                    eventHandler.cancelListening();
                    throw new Error(`Failed to send peer responses for transaction '${txId.getTransactionID()}' to orderer. Response status '${response.status}'`);
                }
                return eventHandler.waitForEvents();
            })
            .then(() => {
                LOG.exit(method);
            })
            .catch((error) => {
                const newError = new Error('Error trying invoke business network. ' + error);
                LOG.error(method, newError);
                throw newError;
            });
    }

But this keeps waiting for an event. This approach does not work as of now.

answered Nov 8, 2018 by Omkar
• 69,220 points

Related Questions In Blockchain

+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 17,100 points
2,989 views
0 votes
1 answer

How can I retrieve to and from address in transaction directly from blockchain?

The spending conditions, i.e., who is able ...READ MORE

answered Jul 11, 2018 in Blockchain by Shashank
• 10,400 points
1,321 views
0 votes
1 answer

Hyperledger Fabric: How to access transaction ID in invoke function?

You can access transaction ID in Invoke ...READ MORE

answered Nov 5, 2018 in Blockchain by Omkar
• 69,220 points
2,432 views
0 votes
1 answer

Hyperledger Fabric: How to get transaction history using key?

history, err := stub.GetHistoryForKey(key_value) for history.HasNext() { ...READ MORE

answered Nov 20, 2018 in Blockchain by Omkar
• 69,220 points
3,548 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,465 views
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,740 points
1,032 views
+1 vote
1 answer
0 votes
1 answer

Hyperledger Fabric 1.0 how to maintain privacy from OSNs?

Yes, OSNs can see all the transaction ...READ MORE

answered Jul 2, 2018 in Blockchain by Omkar
• 69,220 points
886 views
0 votes
1 answer

Hyperledger Fabric: How to retrieve success payload via nodejs client?

The channel.sendTransactionProposal generates a Response object You ...READ MORE

answered Oct 30, 2018 in Blockchain by Omkar
• 69,220 points
804 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP