September 17, 2019

Oracle Blockchain Quick Start Guide

Want to start learning Blockchain and be comfortable in building an enterprise blockchain solution using the Oracle Blockchain Platform? Hope this book "Oracle Blockchain Quick Start Guide - A practical approach to implementing blockchain in your enterprise" (Authored by Vivek Acharya, Nimesh Prakash, and Me, published by Packt) would help you.

This book is intended to become a quick reference to learn Blockchain, Hyperledger Fabric, Design strategies, and build chaincode on the Oracle Blockchain Platform.

This book covers,
  • Exploring Blockchain and Blockchain-as-a-service (BaaS)
  • Construing Distributed Ledger Tech and Blockchain
  • Delving into Hyperledger Fabric
  • Engage in Business Case on Blockchain platform
  • Manage Solutions on Oracle Blockchain Platform
  • Developing Solutions on Oracle Blockchain Platform
For the convenience of beginners and developers, this book also provides all the code samples to download and execute.

The book is Globally available on Packt, Amazon, Google, and Kobo.

Oracle Blockchain Quick Start Guide


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

March 22, 2019

OBP - Writing Blockchain chaincode in Node JS

[OBP]

This post is to show how to write a chain code in NodeJS. Since version 1.2, the opensource Hyperledger fabric blockchain framework supports nodeJS to write chain codes. As Oracle Blockchain Platform (OBP) built on Hyperledger fabric and it upgrades to Hyperledger fabric 1.3 (latest version), we can also write chain codes using NodeJS in OBP.

Let's see a sample chain code. Below is the procedure to write and deploy a chain code into OBP written in Node JS.

  • Create a package.json file with the basic details and dependencies of the libraries
  • Create node js file/files (.js) and configure them to the above package.json
  • Zip the folder with both js and package.json files
  • Click on "Deploy chain code" in OBP under "Chaincodes" tab and select the zip file
Note: You just need to create package.json, not required to run npm commands to install the dependent libraries in the folder before packaging(zip) the project as the OBP will run internally once you deploy the code.

Below is the sample package.json file.


{

"name": "reviews",
"version": "1.0.0",
"description": "Chaincode implemented in node.js",
"engines": {
"node": ">=8.4.0",
"npm": ">=5.3.0"
},
"scripts": { "start" : "node reviews.js" },
"engine-strict": true,
"license": "Apache-2.0",
"dependencies": {
"fabric-shim": "~1.1.0"
}
}


Below is the sample Node js file.


const shim = require('fabric-shim');

const Chaincode = class {

    async Init(stub) {
        return shim.success();
    }

    async Invoke(stub) {
        let ret = stub.getFunctionAndParameters();
        let method = this[ret.fcn];
        console.log("Inside invoke. Calling method: " + ret.fcn);
        if (!method) {
            shim.error(Buffer.from('Received unknown function ' + ret.fcn + ' invocation'));
        }

        try {
            let payload = await method(stub, ret.params);
            return shim.success(payload);
        } catch (err) {
            console.log(err);
            return shim.error(err);
        }
    }
    //Method to save or update a user review to a product
    async saveReview(stub, args) {
        console.log("inside saveReview: " + JSON.stringify(args));
        if (args.length < 3) {
            throw 'Incorrect number of arguments. Expecting productid,userid and rating.';
        }
        var assetReview = {};
        assetReview.productid = args[0];//String
        assetReview.userid = args[1];//String
        assetReview.rating = args[2];//Number
        assetReview.comment = args[3];//String
        await stub.putState(assetReview.userid, Buffer.from(JSON.stringify(assetReview)));

    }//End of method

}

shim.start(new Chaincode());


Note: In the above js sample, the first statement requires fabric-shim package which is mandatory to execute the chain code.

March 13, 2019

Configure Rich History in Oracle Blockchain Platform

 [OBP]

Connecting Oracle Autonomous Transactional Process (ATP) as a Rich History Database in Oracle Blockchain Platform is very easy. It takes just a few configuration steps. Let's see, how to do the configuration.
  • Get the ATP connection details. For this, log in to ATP service console
  • Download wallet package file and copy the TNS name for the connection string to be used
  • Open blockchain instance console
  • As shown in the below figure, click on "Configure Rich History tab"

  • Below window will be opened. Fill the information like username, password of rich history database, paste the copied TNS name in the "Connection String" field, upload the saved wallet file and then click on save

  • Now the ATP has been configured as rich history database to Oracle blockchain. 
  • Go to channels and click on the channel's settings to which the rich history has to be configured and select "Configure Rich History"
  • Below window will open. Check the box to enable rich history for the channel

  • From now on, all the transactions of the channel will be sync with the ATP database automatically
  • At least one transaction has to be done in blockchain to initiate this sync process
  • You can observe three tables created in ATP as shown below and each table name is prefixed with the blockchain instance name_channel name. For example, if the instance name is "dealer" and the channel name is "dealerchannel" then, the tables created are 
    • dealer_dealerchannel_hist
    • dealer_dealerchannel_last
    • dealer_dealerchannel_state

  •  Below image shows the structure of each table created



#autonomous #blockchain #oracleblockchain

February 5, 2019

Introduction to Oracle Blockchain Cloud Service (OBCS) - Blockchain made easy

[OBCS]

"Blockchain" is the most buzzing word in the industry at present. I am fortunate to be part of this technology and starting my blog writings/learnings on this technology with this post. In this post, we will see how the Oracle Blockchain Cloud Service (OBCS) looks like its console, features and how Oracle made blockchain easy.

#OBCS is built on open source Hyperledger fabric blockchain framework. Hence, OBCS supports all the features of Hyperledger fabric, in-fact it made easy to implement the blockchain by reducing a lot of configurations to create channels, nodes, rest services etc, so that, we can concentrate only on logic (chain code or smart contract) implementation. We need to do basic configurations, rest everything will be taken care of by OBCS.

Before begin, we need to understand the basic terms used in OBCS.
  • Founder: It is an organization which is creating the blockchain network. In OBCS, only the founder holds the Orderer.
  • Participant: It is an organization which is participating in the blockchain network.
  • Orderer: A defined collective of nodes that orders transactions into a block. The ordering service exists independent of the peer processes and orders transactions on a first-come-first-serve basis for all channel’s on the network.
  • CertificateAuthority: It is responsible to provide membership to peers in the network.
Let's start the OBCS exploring.
  • Once you login to OBCS console, you can see a list of blockchain instances created (You can create a new instance also from here)
  • Open console of any of the instances, it will open a dashboard which looks like as below
  • The above screen is the dashboard of a blockchain network founder. You can see 
    • The number of channels created in this instance
    • The number of peers added 
    • The orderer (One order per a network)
    • The number of chain codes deployed
    • The number of organizations participated in the network
    • and other information like the health of nodes, channel activity, and peer activity
  • In the case of the participant organization,  the dashboard looks as below where you see only the count of peers, channels and chain codes
  • Below are other tabs/options available in the console
    • Network: This tab shows who are all participating in the network. The founder can see all the participants in the network, however, the participant can see only himself and the founder. The below image shows a topology view of the founder network. You can see participant organizations and their peers along with a Certificate Authority (CA) and an Orderer. If you see this view from a participant organization, it would look similar (participant organizations and their peers) except Orderer.

    • Nodes: This tab shows all the peers including self peers and remote peers who are all part of the network. Also, a node of Certificate Authority (CA). If it is the founder, he can see an extra node for Orderer. Below image is a topology view of the nodes. This will look similar (Nodes and their peers) in both founder and participant console.

    • Channels: This tab is to list the existing channels. Also, you can create a new channel and join peers with it.
    • Chaincodes: This is where our smart contact will be deployed. Here, we will do deployment, initiation, and instantiation of a chain code. While deploying, we will choose the channel in which the logic should deploy. This chain code (smart contract) can write/update ledger of the channel. At present Oracle Blockchain supports chain codes written in GO language and Node JS. However soon, it will support Java also as Hyperledger fabric is already supporting java.


#Oracle #OBCS #OracleBlockchain