600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > Hyperledger Fabric 链码(2) 接口

Hyperledger Fabric 链码(2) 接口

时间:2020-11-19 09:48:01

相关推荐

Hyperledger Fabric 链码(2) 接口

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 dataInit(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) 删除账本中的一对键值。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。