写在前面
本文粗略介绍如何编写链码、链码的整体结构以及链码的API,以官方示例代码讲解
链码整体结构
链码开发者教程 — hyperledger-fabricdocs master 文档
- 写链码之前要先导入两个包:
shim
、peer
,所有用到的API都在这两个包里 - 链码的开头一定要定义一个
SimpleAsset
结构体来作为Chaincode shim
方法的接收者,这个结构体里面可以什么也不写,我们只是在后面函数调用一下它
package main
import (
"fmt"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-protos-go/peer"
)
// SimpleAsset implements a simple chaincode to manage an asset
type SimpleAsset struct {
}
- 实现链码初始化方法
Init
,使用