184.108.40.206 Hyperledger Fabric smart contract package requirements
Hyperledger Fabric (“Fabric”) chaincode can be compiled by multiple programming languages, including Golang, java, and node.js. Each chaincode program must implement a chaincode interface which usually consists of three basic functions: Init, Invoke, and Query.
Init: This function is called during the chaincode instantiation and its purpose is to prepare the ledger for future requests. This function must be implemented in all chaincodes.
Invoke: The Invoke function is called for all future requests from the off-BSN systems towards the DApps. Here all DApp custom functions or what the DApps can do (for example, to read data from the ledger, to write data in the ledger, to update data, to delete data) are defined. Simply put, Invoke can be understood as an entry point to the chaincode functions. The Invoke function also must be implemented in all chaincodes.
Query: The Query function provides a method of querying ledger data. This function can only be used for query purposes and does not offer any operations of ledger data. The Query function is not required to be implemented in all chaincodes.
To realize the automatic deployment of DApp services and to improve deployment efficiency, the following Fabric chaincode packaging requirements have been issued with different programming languages.
The main function must be at the same or higher level as all chaincodes in the project. The zipping path must be the same level folder where the main function is located, and the main function path is the src-based path.
Example: BsnBaseCC Package (the preset chaincode package)
BsnBaseCC ├─main.go ├─ChainCode/ ├─models/ └─utils/
The package should be zipped under BsnBaseCC/ (package name is not required), and the main function path (reference path) is BsnBaseCC.
Example: FabricBaseChaincode chaincode package on github (preset chaincode package)
github.com └─BSNDA └─FabricBaseChaincode └─chaincode └─go └─bsnBaseCC └─main.go └─ChainCode/ └─models/ └─utils/
It should be zipped under github.com/BSNDA/FabricBaseChaincode/chaincode/go/bsnBaseCC/ (package name is not required), and the main function path (reference path) is github.com/BSNDA/FabricBaseChaincode/ chaincode/go/bsnBaseCC.
Description: main.go: the entry; ChainCode: chaincode; models: entities; utils: utilities.
gradle or maven-built projects, the projects must contain build.gradle or pom.xml files.
Example: BsnBaseCC package
BsnBaseCC └─build.gradle └─src └─main └─java └─com.example.javacc └─javacc.java
Package needs to be zipped under BsnBaseCC/. Zip package name is not required.
Description: src/main/java: project directory; com.example.javacc: package name; javacc.java: chaincode information
package.json must be built into the project’s root directory. Package needs to be zipped under BsnBaseCC/. Zip package name is not required.
Example: BsnBaseCC package
BsnBaseCC └─marbles_chaincode.js └─package.json
Description: marbles_chaincode.js: chaincodes
Note: when publishing DApp services in the BSN portal, chaincode packages should be created in the project’s root directory using .zip format.