知识卡片
Init与Invoke链码接口
书中 Go 示例的 SimpleChaincode 用指针接收器实现 Chaincode 接口。Init 处理部署与升级初始化,Invoke 分派查询或调用。两者通过传入的 ChaincodeStubInterface 操作状态和参数,返回 pb.Response;shim.Start 将这一实现交给链码运行时。
结构图:
classDiagram
class Chaincode {
<<interface>>
+Init(stub ChaincodeStubInterface) pb.Response
+Invoke(stub ChaincodeStubInterface) pb.Response
}
class SimpleChaincode {
+Init(stub shim.ChaincodeStubInterface) pb.Response
+Invoke(stub shim.ChaincodeStubInterface) pb.Response
}
class ChaincodeStubInterface {
<<interface>>
+GetState(key string) ([]byte, error)
+PutState(key string, value []byte) error
}
Chaincode <|.. SimpleChaincode : 指针类型隐式实现
SimpleChaincode ..> ChaincodeStubInterface : 运行时传入
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 区块链应用开发 13.2 链码的原理、接口与结构 · 查看原书依据
type Chaincode interface { Init(stub ChaincodeStubInterface) pb.Response Invoke(stub ChaincodeStubInterface) pb.Response }
参考来源
- 位置:《区块链原理、设计与应用》第13章《区块链应用开发》,13.2 链码的原理、接口与结构(来源项目 book-source,`extracted/区块链原理、设计与应用/_epub-src/OEBPS/Text/chapter113.xhtml`,正文块 9)
- 结论依据:摘录点明Init与Invoke链码接口所用的对象或动作。细节与适用条件由本节相邻步骤、配置或例子限定。
- 原始内容:type Chaincode interface { Init(stub ChaincodeStubInterface) pb.Response Invoke(stub ChaincodeStubInterface) pb.Response }