本文介绍了Hyperledger Fabric中通道之间以及通道之间的Chaincode(智能合约)交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如图所示,在Hyperledger Fabric网络中考虑组织对等设置.

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

Org 1有两个对等体,Org 2有一个对等体-所有这些对等体都存在于同一通道中-X.Org 3有一个对等体,它们存在于同一个通道之外.

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.

对等体具有各自不同的链码(c1,c2,c3和c4),并具有所说明的功能.

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

现在有几个问题.

  1. c3是否可以调用c2来更新键的值(因为c3不具有update()功能)?
  2. c4是否可以调用c2来更新键的值(因为c4不具有update()功能)?
  3. c3.read()可以查询c1.write()创建的数据吗?
    链码教程上的此链接说由一个链码创建的状态仅适用于该链码,并且不能被另一个链码直接访问".这是否也适用于同一渠道中的对等方?据我了解,所有参与的同行都可以访问区块链分类帐数据.
  4. c4.read()可以查询c1.write()创建的数据吗?
  5. c2.update()可以更新由c1.write()创建的数据吗?
  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() ?

推荐答案

对等只能执行他们已安装并有权访问(本地)的链码.给定对等方可以有多个链码,但是对等方不能执行其他对等方的链码.

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.

来自ChaincodeStub.invokeChaincode(chaincodeName, args, channel)文档,位于 https://fabric-shim.github.io/ChaincodeStub.html#invokeChaincode__anchor :

您应该能够为所有对等方安装每个链码,并使用ChaincodeStub.invokeChaincode方法和ClientIdentity类( https://fabric-shim.github.io/ClientIdentity.html )以使用访问控制进行处理.

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.

这篇关于Hyperledger Fabric中通道之间以及通道之间的Chaincode(智能合约)交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 20:53