1.Chaincode接口必须被所有的链上代码实现,fabric运行交易通过调用这些指定的函数
type Chaincode interface{ // 在容器建立连接之后再部署交易期间调用Init函数,准许链上代码初始化内部数据
Init(stub ChaincodeStubInterface, function string, args []string) ([]byte, error)
// 每次调用交易都会调用Invoke接口. 链上代码可能会改变状态变量
Invoke(stub ChaincodeStubInterface, function string, args []string) ([]byte, error)
// 查询交易时调用Query接口. 链上代码仅仅读(而不是修改)它的状态变量并其返回结果
Query(stub ChaincodeStubInterface, function string, args []string) ([]byte, error)
}
2. ChaincodeStubInterface用来部署链上代码apps来进入和修改他们的账本
type ChaincodeStubInterface interface {
// Get the arguments to the stub call as a 2D byte array
// 获取stub调用的参数来作为一个2维字节数组
GetArgs() [][]byte
// Get the arguments to the stub call as a string array
// 获取stub调用的参数来作为一个字符数组
GetStringArgs() []string
// 获取交易的ID
GetTxID() string
// InvokeChaincode 本地调用指定的链上代码,`Invoke`使用相同的交易,也就说链上代码调用
// 链上代码不会创建一个新的交易消息
InvokeChaincode(chaincodeName string, args [][]byte) ([]byte, error)
// InvokeChaincode 本地调用指定的链上代码,`Query`使用相同的交易,也就说链上代码调用
// 链上代码不会创建一个新的交易消息
QueryChaincode(chaincodeName string, args [][]byte) ([]byte, error)
// GetState通过Key来返回数组的特定值
GetState(key string) ([]byte, error)
// PutState向账本中写入特定的键和值
PutState(key string, value []byte) error
// DelState从账本中移除指定的键和值
DelState(key string) error
// RangeQueryState函数可以通过chaincode调用来查询状态范围内的键。假设startKey和endKey
// 在词典中,将返回一个迭代器,它可以用来遍历startKey和endKey之间的所有键。
// 迭代器返回键的顺序是随机的。
RangeQueryState(startKey, endKey string) (StateRangeQueryIteratorInterface, error)
// CreateTable创建一张新表,给出表名和列定义
CreateTable(name string, columnDefinitions []*ColumnDefinition) error
// GetTable如果表存在,返回指定的一张表,如果表不存在ErrTableNotFound错误
GetTable(tableName string) (*Table, error)
// DeleteTable删除表和实体相关的所有行
DeleteTable(tableName string) error
// InsertRow 插入一个新行进入指定的表
// 返回 -
// 如果行成功插入返回true和no error
// 如果已经存在给定的行就返回false和no error
// 如果指定的表名不存在返回false和TableNotFoundError
// 如果出现一个没有预料到的错误条件返回false和error
InsertRow(tableName string, row Row) (bool, error)
// ReplaceRow 在指定的表中更新行.
// 返回 -
// 如果行成功更新就返回false和no error
//