从 Hyperledger Fabric Node SDK 中的函数 InvokeChaincode() 获取链码调用者 ID

Get chaincode caller ID from the function InvokeChaincode() in Hyperledger Fabric Node SDK

假设网络架构如下:

A -> Chaincode1 -> fabcar

A 是应用程序,Chaincode1 是 Go 中的链代码,fabcar 是一个Nodejs 中的链码。 他们在同一个频道:"mychannel"。

当从 Chaincode1 执行操作 APIstub.InvokeChaincode 时,例如 APIstub.InvokeChaincode("fabcar", chainCodeArgs, "mychannel"),chaincode fabcar[ 是否有可能=59=](调用的链码)获取调用者链码的 id

fabcar 链码中的 getCreator() 方法只是 returns 调用方组织;但需要的信息是 链码 ID 或一些仅连接到 Chaincode1.

的信息

更新

我尝试了hyperledger官方文档中写的getSignedProposal()方法:https://fabric-shim.github.io/ChaincodeStub.html#getSignedProposal__anchor

getSignedProposal() 方法 returns 类型为 SignedProposal 的签名交易提案的完全解码对象。 SignedProposal 对象表示客户端应用程序发送给链码的请求对象。

执行以下代码:

const proposal = stub.getSignedProposal();
console.log("signed proposal: ", proposal);

结果如下:

signed proposal:  { signature: <Buffer 30 45 02 21 00 c3 a7 91 4c 74 f9 c2 97 04 fc 84 91 6a 71 2d 69 ad 0e a9 22 f2 ed 53 a3 66 97 56 17 d7 d7 3a e6 02 20 13 26 8a 4f f6 3d 86 4e f9 35 ae ... >,
  proposal:
   { header: { signature_header: [Object], channel_header: [Object] },
     payload: { input: [Object], TransientMap: [Object] } } }

似乎真的很难理解哪些信息可以检索调用链代码 ID。 这是关于 SignedProposal 类型的文档的 link:https://fabric-shim.github.io/global.html#SignedProposal

不,目前不可能这样做,因为链码本身没有身份。

The getCreator() function in the fabcar chaincode just returns the caller organization, I want the chaincode id or some info only connected to the Chaincode1.

您可以使用GetSignedProposal方法,即:

// data elements part of a transaction proposal.
GetSignedProposal() (*pb.SignedProposal, error)

SignedProposal 包含原始链码客户端发送的交易提议的信息,如果链码到链码调用 SignedProposal 简单转发,因此您可以提取先前链码的信息。

注意:如果您有复杂的链代码调用链,例如chaincode1 调用 chaincode2 调用 chaincode3,SignedProposal 将包含 chaincode1 的信息,即您赢了不知道 chaincode2.