【发布时间】:2018-03-19 10:34:14
【问题描述】:
我想从 fabric 1.0 中的另一个链码调用一个链码 所以我有一些问题: 1)我们可以在单个节点上安装两个链码吗 2)如果我们在不同的peer上安装两个chaincode,我们如何调用另一个? 3)如果有人有示例,请分享。
【问题讨论】:
标签: hyperledger-fabric hyperledger
我想从 fabric 1.0 中的另一个链码调用一个链码 所以我有一些问题: 1)我们可以在单个节点上安装两个链码吗 2)如果我们在不同的peer上安装两个chaincode,我们如何调用另一个? 3)如果有人有示例,请分享。
【问题讨论】:
标签: hyperledger-fabric hyperledger
这应该很容易实现,这里是一个例子:
// Invoke
func (am *accountManagement) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
actionName, params := stub.GetFunctionAndParameters()
if actionName == "callAnotherCC" {
chainCodeArgs := util.ToChaincodeArgs("anotherCCFunc", "paramA")
response := stub.InvokeChaincode("anotherCCName", chainCodeArgs, "channelName")
if response.Status != shim.OK {
return shim.Error(response.Message)
}
return shim.Success(nil)
}
// NOTE: This is an example, hence assuming only valid call is to call another chaincode
return shim.Error(fmt.Sprintf("[ERROR] No <%s> action defined", actionName))
}
作为@Gari,在评论中正确说明:
确保两个链码都安装在每个背书节点上非常重要
考虑阅读以下材料:
【讨论】: