Giter Site home page Giter Site logo

deeptiman / offchaindata Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 15.0 29 KB

Hyperledger Fabric OffChain Storage

Go 95.36% Shell 4.64%
hyperledger-fabric blockchain-technology offchain-storage couchdb mapreduce mapreduce-demo golang docker grpc-go grpc-service

offchaindata's Introduction

OffChain Data

GitHub last commit GitHub language count GitHub top language

N|Solid

OffChain Data is a sample demonstration to understand the concept of implementing offchain storage and it's capability in Hyperledger fabric Blockchain network. So, this project will work as a peer block event listener and will store the block details in the CouchDB that can be query through MapReduce.

Medium writeup : https://medium.com/@deeptiman/offchain-storage-in-hyperledger-fabric-77e28bd99e0c

Configuration requirements

You need to add the certain project details in `config.json`, so that it will be used to create an event listener and the Blocks will be received through GRPC delivery client.

export FABRIC_CFG_PATH= /home/user/go/src/github.com/exampleledger/fixtures
       {
            "peer_config_path": "exampleledger/fixtures/crypto-config/peerOrganizations/",
            "msp_id": "Org1MSP",
            "msp_type": "bccsp",    
            "msp_config_dir": "org1.example.ledger.com/users/[email protected]/msp",
            "client_key": "org1.example.ledger.com/peers/peer0.org1.example.ledger.com/tls/server.key",
            "client_cert": "org1.example.ledger.com/peers/peer0.org1.example.ledger.com/tls/server.crt",
            "root_cert": "org1.example.ledger.com/peers/peer0.org1.example.ledger.com/tls/ca.crt",
            "server": "peer0.org1.example.ledger.com:7051",
            "channel_id": "exampleledger",
            "config_file": "configtx"
       }

Create CouchDB local instance

The CouchDB local instance can be created using Docker.

docker run --publish 5990:5984 --detach --name offchaindb hyperledger/fabric-couchdb
docker start offchaindb

Mock Chaincode Model

I have followed a sample user model to create the offchaindb. You can also create your own chaincode model and the offchaindata will listen the `KVWriteSet` to store in the couchdb.

Sample Model

type SampleUser struct {
	Email 	  string 		`json:"email"`	
	Name 	  string 		`json:"name"`
	Age	  string		`json:"age"`
	Country   string		`json:"country"`
 }

Configure MapReduce

MapReduce will query the offchain data from CouchDB. So, you need to configure MapReduce for certain design element from CouchDB collection.

Configure MapReduce for Email

curl -X PUT http://127.0.0.1:5990/offchaindb/_design/emailviewdesign/ -d '{"views":{"emailview":{"map":"function(doc) { emit(doc.email,1);}", "reduce":"function (keys, values, combine) {return sum(values)}"}}}' -H 'Content-Type:application/json'

Output

{"ok": true, "id":"_design/emailviewdesign", "rev": "1-f34147f686003ff5c7da5a5e7e2759b8"}

Query Reduce function to count total email

curl -X GET http://127.0.0.1:5990/offchaindb/_design/emailviewdesign/_view/emailview?reduce=true

Output

{"rows":[
		{"key":null,"value":7}
	]}

Query Map function to list all emails

curl -X GET http://127.0.0.1:5990/offchaindb/_design/emailviewdesign/_view/emailview?group=true

Output

{"rows":[
		{"key":"[email protected]","value":1},
		{"key":"[email protected]","value":1},
		{"key":"[email protected]","value":1},
		{"key":"[email protected]","value":1},
		{"key":"[email protected]","value":1},
		{"key":"[email protected]","value":1},
		{"key":"[email protected]","value":1}
	]}

So, all the query peformed in offchain without querying from blockchain ledger.

License

This project is licensed under the MIT License

offchaindata's People

Contributors

deeptiman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

offchaindata's Issues

Problems does not contain package github.com/hyperledger/fabric/common/localmsp

Hi,I just wanna use this project, but this problem occured. Really I don't know how to deal with it.
The problem is:

go get github.com/hyperledger/fabric/common/localmsp: module 
github.com/hyperledger/fabric@upgrade (v2.1.1+incompatible) found, 
but does not contain package github.com/hyperledger/fabric/common/localmsp

I know the reason is that the package github.com/hyperledger/fabric/common/localmsp could not to be download, but how can I get the package ?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.