7

Let's suppose the following network architecture:

A -> Chaincode1 -> fabcar

A is the application, Chaincode1 is a chaincode in Go and fabcar is a chaincode in Nodejs. They are on the same channel: "mychannel".

When is performed the operation APIstub.InvokeChaincode from the Chaincode1 such as APIstub.InvokeChaincode("fabcar", chainCodeArgs, "mychannel"), is there a possibility for the chaincode fabcar (the chaincode called) to get the id of the the caller chaincode?

The getCreator() method in the fabcar chaincode just returns the caller organization; but the information needed is the chaincode id or some info only connected to the Chaincode1.


UPDATE

I tryed the getSignedProposal() method as written in the official documentation of hyperledger: https://fabric-shim.github.io/ChaincodeStub.html#getSignedProposal__anchor

The getSignedProposal() method returns a fully decoded object of the signed transaction proposal of type SignedProposal. The SignedProposal object represents the request object sent by the client application to the chaincode.

Executing the following code:

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

the result is the following:

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] } } }

Seems really difficult to understand which is the info where is possible to retrieve the calling chaincode ID. Here is the link of the doc concerning the SignedProposal type: https://fabric-shim.github.io/global.html#SignedProposal

Riccardo Persiani
  • 702
  • 1
  • 5
  • 25
  • 3
    People voting -1 can at least explain what is wrong with my question so I can correct? Mine seems a problem that could be interesting for all the community. Thanks for understanding. – Riccardo Persiani Aug 10 '18 at 12:47

2 Answers2

3

No, it is not currently possible to do this because the chaincode itself does not have an identity, per se.

christo4ferris
  • 4,039
  • 1
  • 17
  • 30
  • So there is no way to know in which way a chaincode called another one. This sounds real bad If someone wants to reply with a callback... – Riccardo Persiani Aug 10 '18 at 14:07
  • 1
    Theoretical you should be able extract information from SingedProposal, which in case of cc2cc just passed from one to another, hence second one can use it. – Artem Barger Aug 12 '18 at 11:41
2

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.

You can use GetSignedProposal method, i.e.:

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

the SignedProposal contains information of the original chaincode client sent transaction proposal, in case of chaincode to chaincode invocation SignedProposal simply forwarded, hence you can extract information of previous chaincode.

NOTE: If you have complex chain of chaincodes invocations, e.g. chaincode1 calls chaincode2 which calls chaincode3, SignedProposal will contain information of chaincode1 i.e. you won't know about chaincode2.

Artem Barger
  • 40,769
  • 9
  • 59
  • 81