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?
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.
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.
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.
We provide four commands to manage a chaincode's lifecycle: package , install , instantiate , and upgrade .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With