Middleware – wrapping and driving the chaincode

The following diagram maps the transaction stages discussed in the Application and Transaction Stages section and illustrated in Figure 5.1: The stages in the creation and operation of a blockchain application, to Fabric terms and using Fabric terminology:

Figure 5.3: The stages in the creation and operation of a blockchain application

Fabric peers, orderers, and CAs (or MSPs) communicate using gRPC (https://grpc.io/), as well as the process spawned by the peer to run the chaincode (the process is really a Docker container). This process exports a service endpoint implementing the JSON RPC 2.0 specification (http://www.jsonrpc.org/specification) for channel and chaincode operations. We can write a wrapper application that communicates directly with chaincode using the service specification, but then we would have to write logic to parse and interpret the payload as well. With the Fabric platform and its specification likely to change in the future, this is not necessarily the best and most maintainable way to write an application, especially for production purposes. Fortunately, Hyperledger Fabric provides the means to run chaincode operations while hiding the details of the interface specifications and the communication protocol, in two different ways:

  • Command-Line Interface (CLI): Fabric provides commands that can be run from a Terminal to perform the various operations indicated in Figure 5.3: The stages in the creation and operation of a blockchain application. The tool to run these commands is peer, which is generated upon downloading the Fabric source code and building it (using make, or just make peer). Different switches can be used with this command to perform different channel and chaincode operations, and you will see some examples in this section.
  • Software Development Kit (SDK): Hyperledger provides a toolkit and set of libraries for the easy development of applications to wrap the channel and chaincode operations in multiple languages, such as Node.js, Java, Go, and Python. These SDKs also provide functions to interact with MSPs, or instances of the Fabric CA.

Although CLI tools can be used for testing and demonstration purposes, they are inadequate for application development. The SDK libraries, in addition to the functions mentioned previously, provide the ability to subscribe to events emanating from the network, communicating information about state changes that are needed to drive the application logic. We will use the Node.js SDK to demonstrate how to build both our middleware and the higher-layer application. It is left to the reader to build equivalent applications in other languages of their choice using one of the other SDKs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.139.169