July 23, 2019

Invoking/executing rich query in Oracle Blockchain Platform (OBP)

[OBP] This example is developed in NodeJS.

Hyperledger blockchain ledger is storing data in Key-Value pairs. So, if to fetch the data from the ledger, we will pass the key. But do you know, we can query the ledger without the key aswell.
Hyperledger blockchain is providing an option to query the ledger using a rich query. ChaincodeStub class has a method getQueryResult() which does this job. Please note that this method is supported only for state databases that support rich query. Below is the syntax of the method.

Syntax:
    <async> getQueryResult(query)

Input:
   A query string is in the native syntax of the underlying state database

Returns:
   Promise for StateQueryIterator Object

Below is the node JS code snippet to see the implementation of this method. In the below example, I am taking a product id from a user and fetching the set of keys and their JSON objects from the state database where the JSON object contains the given product id.

        let queryString = "SELECT key, valueJson FROM <STATE> WHERE json_extract(valueJson, '$.productid') = '" + args[0] + "'";
        let resultsIterator = await stub.getQueryResult(queryString);
        let results = [];

        while (true) {
            let oneRecord = {};
            let res = await resultsIterator.next();
            if (res.value && res.value.value.toString()) {
                let val = res.value.value.toString('utf8');
                try {
                    oneRecord.value = JSON.parse(val);
                } catch (err) {
                    console.log(err);
                    oneRecord.value = val;
                }
                results.push(oneRecord);
            }
            if (res.done) {
                await resultsIterator.close();
                return Buffer.from(JSON.stringify(results));
            }
        }

In the above example, the getQueryResult()  returns a promise object with an iterator. Hence, we need to call next() method of it to get the inside values.

June 18, 2019

Oracle blockchain error: chaincode fingerprint mismatch data mismatch

[#OBP]

There are two Organizations (one is the founder and the other is a participant) in a channel (channel name is team1)  in Oracle blockchain network. A chaincode (chain code name is "oow") is deployed and instantiated with version v1 in the founder. A line in the chaincode is changed and deployed the code in the participant with the same version v1. While executing the REST endpoints, below error occurred as Oracle blockchain tries to match the code and their versions in all the peers of the channel and the chaincode are not matching in the peers. Solution for this is to deploy the chaincode with the new version on all the organizations.

{
    "returnCode": "Failure",
    "info": {
        "proxyError": "Proposal not pass",
        "peerErrors": [
            {
                "peerId": "prodhonestpeer1",
                "errMsg": "Sending proposal to prodhonestpeer1 failed because of: gRPC failure=Status{code=UNKNOWN, description=error executing chaincode: could not get ChaincodeDeploymentSpec for oow:v1.2: get ChaincodeDeploymentSpec for oow/team1 from LSCC error: chaincode fingerprint mismatch data mismatch, cause=null}",
                "verified": false
            },
            {
                "peerId": "prodhonestpeer0",
                "errMsg": "Sending proposal to prodhonestpeer0 failed because of: gRPC failure=Status{code=UNKNOWN, description=error executing chaincode: could not get ChaincodeDeploymentSpec for oow:v1.2: get ChaincodeDeploymentSpec for oow/team1 from LSCC error: chaincode fingerprint mismatch data mismatch, cause=null}",
                "verified": false
            }
        ]
    },
    "txid": "973a7518438bf9c62db240ea41dce88ef78854caa20"
}

#OBP #OracleBlockchain #Blockchain

May 6, 2019

Oracle blockchain error: executing chaincode premature execution

[#OBPCS]

I received the below error while executing a rest service of a participant in the Oracle Blockchain network. I deployed and instantiated successfully a new version of a chain code into all the participants of a channel in the network. While executing the corresponding rest service, it has thrown the below error. This is because I executed the rest service immediately after the code was instantiated. It took a few seconds to available. I executed the rest service again after a few seconds and then it worked without any code or configuration changes. :).

It looks funny, but it worked for me.  So, when you see this error, don't be panic. Just wait a few seconds and try again. This is because it may take some time for chain code to be ready on rest servers as these changes have to be applied to many containers in the backend.

{
"returnCode":"Failure",
"info":{
"proxyError":"Failed query proposal from peer(s) prodorganicpeer1, prodorganicpeer0.",
"peerErrors":[
{
"peerId":"prodorganicpeer1",
"errMsg":"Sending proposal to prodorganicpeer1 failed because of: gRPC failure=Status{code=UNKNOWN, description=error executing chaincode: premature execution - chaincode (oow:v1.3) launched and waiting for registration, cause=null}",
"verified":false
},
{
"peerId":"prodorganicpeer0",
"errMsg":"Sending proposal to prodorganicpeer0 failed because of: gRPC failure=Status{code=UNKNOWN, description=error executing chaincode: premature execution - chaincode (oow:v1.3) launched and waiting for registration, cause=null}",
"verified":false
}
]
}}

#OBPCS #OracleBlockchain #Blockchain