链码调用另一个链码(Hyperledger Fabric)

问题描述 投票:0回答:4

我有一个由 3 个组织和两个渠道组成的网络。

channelone:org1、org2、链码- fabcar

channeltwo:org1、org3、链码- fabphone

我想使用 fabcar 查询链码- fabphone。

hyperledger-fabric blockchain
4个回答
0
投票

您可以使用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


0
投票

如果您使用 javascript 或 typescript 编写链代码,则可以使用以下代码:

const args = [functionName, ...]
const result = await ctx.stub.invokeChaincode(chaincodeName, args, channelName)

return result.payload.toString('utf8')

0
投票

您只能使用 org1 对等点从 fabcar 调用 fabphone,因为如果两个互相调用的链码安装在同一个对等点中,则 invokechaincode API 可以工作


-2
投票

我认为这是不可能的。您只能在同一通道内调用链码函数。函数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)
}
© www.soinside.com 2019 - 2024. All rights reserved.