Lets say that we have two different chaincodes: cc1 and cc2.
If cc1 invokes cc2 is there a way for cc2 to check if the invocation is coming from cc1.
A chaincode can be invoked to update or query the ledger in a proposal transaction. Given the appropriate permission, a chaincode may invoke another chaincode, either in the same channel or in different channels, to access its state.
We provide four commands to manage a chaincode's lifecycle: package , install , instantiate , and upgrade .
Chaincode runs in a seperate process from the peer and initializes and manages the ledger state through transactions submitted by applications. A chaincode typically handles business logic agreed to by members of the network, so it similar to a “smart contract”.
By default, endorsement policies are specified in the chaincode definition, which is agreed to by channel members and then committed to a channel (that is, one endorsement policy covers all of the state associated with a chaincode).
I think there is no current official support for that. But it seems possible to get first called chaincode from SignedProposal (More on this here)
Another possible generic solution can be something like temporary token verification, it goes like this:
- chaincode1(cc1) gets called, and it wants to call chaincode2 (cc2)
- cc1 random generates token and appends it to message with its name.
- cc1 invokes cc2
- cc2 takes token and with help of given name invoked cc1 with same token in msg.
- cc1 verifies that token is correct.
- cc2 continues to do its thing.
There is overhead in communication but it is, within my knowledge, only way to know for sure if your code is called from another specific chaincode.
edit: this way is not working
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With