Hyperledger Fabric implementation — Part 2
Hyperledger Fabric implementation: Good to Know info when working with Fabric v1.1 SDK
In Part 1 ,we explored the overview of Chaincode and their API’s using Node.js and Golang. In this story , we will go through the general information about Fabric SDK and their API.
In the later series, we will explore an end to end use case implementation written using the Chaincode and how it can be interact with application via Fabric SDK. The last series will have an Front end application which will interact with Ledger using Chaincode , Smart contract and application layer.
Please let me, if anyone needs help in the setting up the development environment. I will add it in the last series.
GOOD TO KNOW
Fabric SDK consists of mainly two components.
* Fabric client : overall network interaction and transaction flow APIs
* Fabric CA client : participant management APIs
Development of code flow, can be broadly classified into three categories
1) User Interface Implementation process
Every user must have user name,account name,user affiliation,user enrollment certificate information(Enrollment Object),user Membership Service Provider Identifier
As a starting step, create a java class which implements User interface.
APIs to Explore :
Interface :org.hyperledger.fabric.sdk.Enrollment , org.hyperledger.fabric.sdk.User
2) Certificate Authority mechanism
- Create a new instance of Client Certificate Authority. Considering Fabric CA in this series.
- Enroll and Load the admin user. CA will generate admin user crypto by default
- Register with existing admin (API use this admin as a registrar) and Enroll non-admin user.
APIs to Explore :
Class : org.hyperledger.fabric_ca.sdk.HFCAClient.
Methods : createNewInstance() , setCryptoSuite(),enroll(),register()
Class : org.hyperledger.fabric_ca.sdk.RegistrationRequest
Methods : enroll()
3) Transaction flow
- Create a new instance of Fabric Client Certificate and set the CryptoSuite and user context. Considering admin works on complete transaction flow in this series.
- Create or Get the channel and initialize it by adding peer ,orderer, eventhub to it.
APIs to Explore :
Class : org.hyperledger.fabric.sdk.HFClient
Methods : setCryptoSuite(),setUserContext()
Class : org.hyperledger.fabric.sdk.Channel
Methods : newChannel(),addPeer(),addEventHub(),addOrderer(),initialize(),getChannel()
- Invoke a Query to ledger is achieved by first creating new Query Proposal Request .Then set a chaincode id, chaincode function and chain code argument to the request. Query Response is returned by calling queryByChaincode method on the required channel.
APIs to Explore :,
Class : org.hyperledger.fabric_ca.sdk.HFClient
Methods : newQueryProposalRequest()
Class : org.hyperledger.fabric.sdk.QueryByChaincodeRequest
Methods : setChaincodeID(),setFcn(),setArgs()
Class : org.hyperledger.fabric.sdk.ChaincodeID
Methods : newBuilder(),setName(),build()
Class : org.hyperledger.fabric.sdk.ProposalResponse
Methods : getChaincodeActionResponsePayload()
- Invoke a Modify(Create/Update/Delete) request on ledger is achieved by first creating new Transaction Proposal Request .Then set a chaincode id, chaincode function and chain code argument to the request. Proposal Response is returned by calling sendTransactionProposal method on the required channel. If proposal is valid, transaction is sent to orderer using sendTransaction via channel which returns the Event. Event is used to find the whether transaction was commited to ledger via isValid method and to get transaction id for the committed transaction.
APIs to Explore :
Class : org.hyperledger.fabric_ca.sdk.HFClient
Methods : newTransactionProposalRequest()
Class : org.hyperledger.fabric.sdk.TransactionProposalRequest
Methods : setChaincodeID(), setFcn(), setArgs()
Class : org.hyperledger.fabric.sdk.Channel
Methods : sendTransactionProposal(), sendTransaction()
Class : org.hyperledger.fabric.sdk.ChaincodeID
Methods : newBuilder(), setName(), build()
Class : org.hyperledger.fabric.sdk.ProposalResponse
Methods : getChaincodeActionResponsePayload()
Ordering service contains the critical information about the network like
* Organization details who are part of network
* Existing Channels details.
* Organization and Channel relationship
* Policies for any change in the network
To add a new Organization participant,
* Add the details about new Organization participant (Mandatory) to the orderer
* If organization like to maintain a ledger , peer details needs to be added (optional)
Peers
* By default all the peers are committer. Peer can additionally take endorser role by enabling the bootstrap configuration.
* Broadcast the events(when block is added to ledger) to interested parties on a specified port
Identities
* Every operation should be digitally signed. every resource(order node,peer node,user) must have certificates , signed by a Certificate Authority (CA).
Fabric CA
* Provides REST APIs for dynamic identity management with registration, enrollment (getting certificates), revocation and re-enrollment.
* user which are created in this way is only a member ,but not admin(managing channel & chaincode)
References
Fabric SDK Java : https://github.com/hyperledger/fabric-sdk-java
Fabric CA : http://hyperledger-fabric-ca.readthedocs.io/en/latest/users-guide.html
EventHub : https://fabric-sdk-node.github.io/EventHub.html