![](/img/trans.png)
[英]Hyperledger fabric chaincode: function calling another function from within chaincode?
[英]Chaincode calling another chaincode (Hyperledger Fabric)
我有一个由 3 个组织和两个频道组成的网络。
channelone:ORG1,ORG2,chaincode- fabcar
channeltwo:ORG1,org3,chaincode- fabphone
我想使用 fabcar 查询 chaincode-fabphone。
您可以使用 stub.InvokeChaincode 方法从另一个调用一个链码 -
response := stub.InvokeChaincode(chaincodeName, invokeArgs, channelName)
if response.Status != shim.OK {
return nil
}
return response.Payload
有关更多详细信息,请参阅-https : //sourcegraph.com/github.com/hyperledger/fabric/-/blob/core/chaincode/shim/interfaces.go#L62 :3
如果您使用 javascript 或 typescript 编写链代码,则可以使用以下代码:
const args = [functionName, ...]
const result = await ctx.stub.invokeChaincode(chaincodeName, args, channelName)
return result.payload.toString('utf8')
我认为这是不可能的。 您只能在同一通道内调用链码函数。 函数 invokeChaincode 使用与原始交易相同的交易上下文。 看看https://github.com/hyperledger-archives/fabric/blob/master/core/chaincode/shim/chaincode.go
// InvokeChaincode locally calls the specified chaincode `Invoke` using the
// same transaction context; that is, chaincode calling chaincode doesn't
// create a new transaction message.
func (stub *ChaincodeStub) InvokeChaincode(chaincodeName string, function string,
args []string) ([]byte, error) {
return handler.handleInvokeChaincode(chaincodeName, function, args, stub.UUID)
}
// QueryChaincode locally calls the specified chaincode `Query` using the
// same transaction context; that is, chaincode calling chaincode doesn't
// create a new transaction message.
func (stub *ChaincodeStub) QueryChaincode(chaincodeName string, function string, args
[]string) ([]byte, error) {
return handler.handleQueryChaincode(chaincodeName, function, args, stub.UUID)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.