标签:transaction Fabric Invoke Init key 链码 Hyperledger string
1.Chaincode interface:每个链码程序必须实现链码接口,用以响应接收的事务。
1.1 go语言的“shim ”包中,接口规范如下:
- Init:在链码实例化或者升级的时候被调用,完成数据初始化
- Invoke:客户端调用Invoke方法来提交交易提案,在更新或查询提案事务中分类帐本数据状态的时候被调用
type Chaincode interface {
// Init is called during Instantiate transaction after the chaincode container
// has been established for the first time, allowing the chaincode to
// initialize its internal data
Init(stub ChaincodeStubInterface) pb.Response
// Invoke is called to update or query the ledger in a proposal transaction.
// Updated state variables are not committed to the ledger until the
// transaction is committed.
Invoke(stub ChaincodeStubInterface) pb.Response
}
2. ChaincodeStubinterface:shim中的另一个重要接口,用于访问和修改帐本,以及实现链间调用
共定义了36个成员方法
eg.
- GetFunctionAndParameters()(function string,params []string)返回被调用函数的名称以及参数列表
- GetStringArgs()[]string 直接返回参数列表
- GetState(key string)([]byte,error) 根据指定的key值查询数据状态
- PutState(key string,value []byte)error 根据指定的key,将对应的value保存到帐本中
- DelState(key) 删除账本中的一对键值。
标签:transaction,Fabric,Invoke,Init,key,链码,Hyperledger,string 来源: https://blog.csdn.net/thefist11cc/article/details/116864969
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。