Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the key has already existed in Hyperledger Fabric?

In hyperledger fabric chaincode I want to check whether a key already exists or not, so that if another record with the same key is tried to be stored in the ledger, it should show up error. What is the best way to do this in fabric?

like image 985
kailashsharan Avatar asked Jan 11 '19 05:01

kailashsharan


People also ask

How do you check chaincode in Hyperledger Fabric?

Test Your Chaincode on a Local Hyperledger Fabric Network After a chaincode is installed and deployed, you can submit transactions to the functions inside your chaincode by using the ochain invoke and ochain query commands.

Can Hyperledger Fabric be hacked?

It also adopts an endorsement policy to deal with malicious behaviors of peers. However, a malicious ordering service can easily make the endorsement policy ineffective. Therefore, Hyperledger Fabric is not reliable in an environment where an ordering service may be hacked.

Where is Blockchain data stored in Hyperledger Fabric?

Hyperledger fabric supports LevelDB and CouchDB as state databases, LevelDB is the default state database embedded in the peer process and stores chaincode data as key-value pairs.

What are the four stages of a chain code life cycle in Hyperledger?

We provide four commands to manage a chaincode's lifecycle: package , install , instantiate , and upgrade .


1 Answers

Use

stub.GetState(key)

and check if it returns any value. The key is indexed so it will not be so time-consuming even using couchdb. The history is maintained by levelDB that is very performative for key queries.

But a quick tip, avoid couchdb, try to design you chaincode to use composite key and dont use rich queries if you want more performance and throughput.

Hope it helps.

like image 101
Rodolfo Leal Avatar answered Dec 07 '22 22:12

Rodolfo Leal