Reputation: 461
Can I store data directly into database without a Chain-code in Hyperledger Fabric. I can do it in Hyperledger composer, by directly calling the API(composer REST SERVER) for asset that I declare.
I have read somewhere that chain-code owns the database so that means that it cannot be store directly and hyperledger composer actually in a way overcome this. am I right? can someone please clarify what I am missing.
Upvotes: 0
Views: 1290
Reputation: 13
Chaincode is part of the mandatory components of Fabric. When you are making calls to the REST SERVER from your app to query or add new information to the ledger, Fabric needs to use the chaincode to execute that command.
Without chaincode your Fabric network would not have any "business logic" (for example, seller1 provides assests to buyer2 with a minimum of XItems and maximum of YItems). Also, workflow to include changes into the blockchain require as a first step an endorsement, which every peer sign a transaction proposal using the chaincode, this means ==> No chaincode = no endorsement for a transaction proposal = no changes into the blockchain ( Check "Phase 1: Proposal" --> https://hyperledger-fabric.readthedocs.io/en/release-1.4/peers/peers.html#phase-1-proposal )
Whether anyone in a Fabric network can change the ledger without executing a chaincode, that means that anyone can include data that is not adjust to your business model/logic.
Composer and it´s components are just an optional layer on top of Fabric. All the components included in composer just interact with Fabric (the mandatory/foundation layer), without chaincode, Fabric will not be able to query or change the ledger status, so Composer components that use this feature will fail.
Upvotes: 0
Reputation: 6335
if you use composer then you automatically use the chaincode you deployed to the network in the form of a bna. That bna is chaincode. The API created automatically for you by composer-rest-server leverages that chaincode and it creates endpoints for you to access said chaincode and work with the network.
You can extend the bna, you can add access rules or create transactions, whatever you need really. Now, you also mentioned a database.
The way hyperledger works is like this:
the ledger itself is a file on disk, it's not a database. That file contains everything that happens and stores every single block of information with the transactions they contain. There is a world database as well, but that one only exposes the current state of every asset, not every single state change. There is no point in changing that database directly anyway since it can and will be easily recreated whenever required.
One final thing from me, composer is going out, IBM has announced that it will no longer develop / maintain it, so you need to consider other ways:
https://lists.hyperledger.org/g/composer/message/125
Upvotes: 0
Reputation: 353
Composer runs on Fabric. It uses some generic chaincode behind the scene that are using your model/transaction files to put and get data from the database.
To just store data using Fabric, you would have to code a simple chaincode. Fortunately, in the sample files provided by Hyperledger Fabric, you can find exactly how to do it. See marbles: https://github.com/hyperledger/fabric-samples/tree/release-1.2/chaincode
Upvotes: 1