Hands-On Blockchain with Hyperledger
上QQ阅读APP看书,第一时间看更新

Designing a Data and Transaction Model with Golang

In Hyperledger Fabric, chaincode is a form of a smart contract written by a developer. Chaincode implements a business logic agreed upon by stakeholders of the blockchain network. The functionality is exposed to client applications for them to invoke, provided they have the correct permissions.

Chaincode runs as an independent process in its own container, isolated from the other components of the Fabric network. An endorsing peer manages the lifetime of the chaincode and of the transaction invocations. In response to client invocations, the chaincode queries and updates the ledger and generates a transactions proposal.

In this chapter, we will learn how to develop chaincode in the Go language and we will implement the smart contract business logic of the scenario. Finally, we will explore the key concepts and libraries necessary for developing a fully functional chaincode.

While in the next sections we will explore snippets of code related to the concepts you can get a complete implementation of the chaincode at the following address:

https://github.com/HyperledgerHandsOn/trade-finance-logistics/tree/master/chaincode/src/github.com/trade_workflow_v1

Note that this is also available in the local git clone we created in the previous chapter.We have two versions of the chaincode, one in the trade_workflow folder and another in the trade_workflow_v1 folder. We need two versions to demonstrate upgrades later in Chapter 9, Life in a Blockchain Network. In this chapter, we use the v1 version to demonstrate how to write chaincode in Go.

In this chapter, we will be covering the following topics:

  • Creating a chaincode
  • Access control
  • Implementing chaincode functions
  • Testing chaincode
  • Chaincode design topics
  • Logging output