Hyperledger fabric Unable to query result

0 votes

I have invoked my chaincode with this command

> peer chaincode invoke -o orderer.example.com:7050  --tls
> $CORE_PEER_TLS_ENABLED --cafile
> /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
> -C ethos -n ethos_ccv100 -c '{"Args":["CreatePatientInfo","123456", "22", "175","74","133","37","Eggs","Fever", "Wei Quan", "Tsu",
> "11April1995","tsuweiquan@gmail.com","96259561", "SINGAPOREAN",
> "Chinese", "Buddist", "Single","13Aug2017"]}'

Now, when I run either of this command:

peer chaincode query -C ethos -n ethos_ccv100 -c '{"Args["queryPatientInfo","123456"]}'

or

peer chaincode query -C ethos -n ethos_ccv100 -c '{"function":"queryPatientInfo","Args":["123456"]}'

I am getting this output which is different from what I expected:

2018-30-10 12:48:32.066 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP 2018-30-10
12:48:32.066 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity 2018-30-10 
12:48:32.066 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc 2018-30-10
12:48:32.067 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc 2018-30-10
12:48:32.067 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext:
0A98070A6A08031A0B08A095C1CC0510...74496E666F0A09533935313139323447 2018-30-10 12:48:32.067 UTC
[msp/identity] Sign -> DEBU 006 Sign: digest:
4920E5394B2048EC5629886A51A0F022BED4803495C9FC08B5AB62A1463B92BD Query Result (Raw): 2018-30-10 12:48:32.073 UTC [main] main -> INFO 007 Exiting.....
root@6b6ec9e233e3:/opt/gopath/src/github.com/hyperledger/fabric/peer#
Oct 30, 2018 in Blockchain by digger
• 26,740 points
1,005 views

1 answer to this question.

0 votes

In Hyperledger Fabric v1.0.0 your chaincode should confirm following API:

// Chaincode interface must be implemented by all chaincodes. The fabric runs
// the transactions by calling these functions as specified.
type Chaincode interface {
    // Init is called during Instantiate transaction after the chaincode container
    // has been established for the first time, allowing the chaincode to
    // initialize its internal data
    Init(stub ChaincodeStubInterface) pb.Response

    // Invoke is called to update or query the ledger in a proposal transaction.
    // Updated state variables are not committed to the ledger until the
    // transaction is committed.
    Invoke(stub ChaincodeStubInterface) pb.Response
}

And also, 

Query(stub shim.ChaincodeStubInterface) pb.Response

is not a part of it, therefore you need to explicitly add dispatch to this function inside the Invoke, e.g.:

func (t *SampleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
    function, args := stub.GetFunctionAndParameters()
    if function == "CreatePatientInfo" {
        return CreatePatientInfo(stub, args)
    } else if function == "queryPatientInfo" {
        return t.Query(stub)
    }
    return shim.Success(nil)
}

Hope this helps

answered Oct 30, 2018 by Omkar
• 69,220 points

Related Questions In Blockchain

0 votes
1 answer

Hyperledger Composer: Not able to query fabric.

Add another rule to .acl file to ...READ MORE

answered Nov 12, 2018 in Blockchain by Omkar
• 69,220 points
569 views
0 votes
1 answer

Hyperledger Fabric: unable to check out source code from gerrit.hyperledger.org

There's something wrong with your SSH key. ...READ MORE

answered Nov 15, 2018 in Blockchain by Omkar
• 69,220 points
856 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,451 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,003 views
+1 vote
1 answer
+16 votes
4 answers
0 votes
1 answer

Hyperledger Fabric: How to retrieve result from Fabric Transaction?

invokeChainCode(securityContext, functionName, args, options) { ...READ MORE

answered Nov 8, 2018 in Blockchain by Omkar
• 69,220 points
1,886 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