Chaincode (smart contract) interactions within and across channels in Hyperledger Fabric

China☆狼群 提交于 2020-01-02 05:29:07

问题


Consider the Organization-Peer setup in a Hyperledger Fabric network as shown in the image.

Org 1 has two peers, Org 2 has one peer - all of which exist inside the same channel - X. Org 3 has one peer which exist outside in a different channel.

The peers have distinct chaincodes(c1, c2, c3 & c4) installed in each of them with the functions as explained.

write() - put a key-value pair into the ledger  
update() - update a value for an existing key  
read() - query an existing key-value pair  

Now on to few questions.

  1. Can c3 invoke c2 to update a key's value (as c3 do not have update()function)?
  2. Can c4 invoke c2 to update a key's value (as c4 do not have update()function)?
  3. Can c3.read() query the data created by c1.write() ?
    This link on chaincode tutorial says "State created by a chaincode is scoped exclusively to that chaincode and can’t be accessed directly by another chaincode". Does this apply for peers in the same channel too? As per my understanding blockchain ledger data is accessible to all participating peers.
  4. Can c4.read() query the data created by c1.write() ?
  5. Can c2.update() update the data created by c1.write() ?

回答1:


Peers can only execute chaincode that they have installed and have access to (local). You can have multiple chaincode for a given peer, but you can't have peers executing chaincode of other peers.

From ChaincodeStub.invokeChaincode(chaincodeName, args, channel) documentation at https://fabric-shim.github.io/ChaincodeStub.html#invokeChaincode__anchor:

Locally calls the specified chaincode invoke() using the same transaction context; that is, chaincode calling chaincode doesn't create a new transaction message.

You should be able to install each chaincode for all peers and use the ChaincodeStub.invokeChaincode method along with the ClientIdentity class (https://fabric-shim.github.io/ClientIdentity.html) to handle with access control.



来源:https://stackoverflow.com/questions/51657142/chaincode-smart-contract-interactions-within-and-across-channels-in-hyperledge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!