In Hyperledger-Fabric how to get Ethereum like "msg.sender" in chaincode? (also when chaincode A calls chaincode B, will the "msg.sender" be script-address of A (like in Ethereum)?
Does Hyperledger-Fabric provide a way to find out who (msg.sender in Ethereum) called the chaincode?
2 Answers
To add onto Mo-Che Chan's answer:
func (stub *ChaincodeStub) GetCreator() ([]byte, error)
GetCreator returns SignatureHeader.Creator of the signedProposal this Stub refers to.
GetCreator should get signedProposal and proposal.
From the HyperLedger blog:
The Creator field holds x.509 certificate, public key and membership service provided (MSP) who issued these identity to the client. The Nonce field contains some random bytes.
type SignatureHeader struct { Creator []byte Nonce []byte }
And from another post on the same blog, a diagram of the block structure. It has a section in each transaction (see row 4) for
Creator Identity (certificate, public key) - Client
It seems as if yes, this would be the equivalent of msg.sender in Solidity.

- 1,229
- 18
- 15
-
Thank you for referencing the blog, I don't know how I haven't found it sooner. Is there a preferred/easy way to reconstruct the Creator Identity part design time (since I need to embed the content, i.e. the byte array, into the chaincode)? Should I concatenate some crypto materials (if so, which ones), or should I hijack an SDK request sent toward the network and extract it from that? – Attila Klenik Oct 12 '17 at 11:14
func (stub *ChaincodeStub) GetCreator() ([]byte, error)
GetCreator returns SignatureHeader.Creator of the signedProposal this Stub refers to.
GetCreator should get signedProposal and proposal.

- 51
- 3
-
1I'm more concerned about second part of my question. Paraphrasing - can chaincode act as account? (when chaincode A calls chaincode B, will the "msg.sender" be script-address of A?) – Rupert Redding May 16 '17 at 04:26