不同的 hyperledger fabric 链码能否查看世界状态中的所有 key/value 对?
Can different hyperledger fabric chaincodes view all key/value pairs in world state?
我在同一频道上获得了两个当前提交的智能合约定义。两者都是用 Go 编写的,有些基础,只做基本的 CRUD 操作。但是,我注意到 key/value 用一个链代码编写的对,对另一个链代码不可用。
因此,我使用 go-audit
创建了以下记录:
但是,我尝试使用链码 go-asset
对键 ping
执行获取操作,未找到并出现以下错误(由链码返回)
bad request: failed to invoke go-asset: Error: No valid responses from any peers. Errors: **someurl***, status=500, message=the asset ping does not exist.
这是交易内容:
func (c *GoAssetContract) ReadGoAsset(ctx contractapi.TransactionContextInterface, goAssetID string) (*GoAsset, error) {
exists, err := c.GoAssetExists(ctx, hlpAssetID)
if err != nil {
return nil, fmt.Errorf("could not read from world state. %s", err)
} else if !exists {
return nil, fmt.Errorf("the asset %s does not exist", goAssetID)
}
bytes, _ := ctx.GetStub().GetState(goAssetID)
goAsset := new(GoAsset)
err = json.Unmarshal(bytes, goAsset)
if err != nil {
return nil, fmt.Errorf("could not unmarshal world state data to type GoAsset")
}
return GoAsset, nil
}
和 GoAsset 结构
// GoAsset stores a value
type GoAsset struct {
Value string `json:"value"`
}
世界状态不应该对通道上的所有链码 approved/committed 可用吗?
部署到同一个通道的链代码是命名空间的,因此它们的键仍然特定于使用它们的链代码。因此,您看到部署到同一通道的 2 个链代码按设计工作,它们看不到彼此的密钥。
然而,一个链码可以包含多个不同的合约,在这种情况下,合约可以访问彼此的密钥,因为它们仍然在同一个链码部署中。
您可以使用 InvokeChaincode() API 在同一通道上拥有一个链代码 invoke/query 另一个链代码。被调用链码可以 return keys/values 到调用者链码。通过这种方法,可以将所有访问控制逻辑嵌入到被调用的链代码中。
我在同一频道上获得了两个当前提交的智能合约定义。两者都是用 Go 编写的,有些基础,只做基本的 CRUD 操作。但是,我注意到 key/value 用一个链代码编写的对,对另一个链代码不可用。
因此,我使用 go-audit
创建了以下记录:
但是,我尝试使用链码 go-asset
对键 ping
执行获取操作,未找到并出现以下错误(由链码返回)
bad request: failed to invoke go-asset: Error: No valid responses from any peers. Errors: **someurl***, status=500, message=the asset ping does not exist.
这是交易内容:
func (c *GoAssetContract) ReadGoAsset(ctx contractapi.TransactionContextInterface, goAssetID string) (*GoAsset, error) {
exists, err := c.GoAssetExists(ctx, hlpAssetID)
if err != nil {
return nil, fmt.Errorf("could not read from world state. %s", err)
} else if !exists {
return nil, fmt.Errorf("the asset %s does not exist", goAssetID)
}
bytes, _ := ctx.GetStub().GetState(goAssetID)
goAsset := new(GoAsset)
err = json.Unmarshal(bytes, goAsset)
if err != nil {
return nil, fmt.Errorf("could not unmarshal world state data to type GoAsset")
}
return GoAsset, nil
}
和 GoAsset 结构
// GoAsset stores a value
type GoAsset struct {
Value string `json:"value"`
}
世界状态不应该对通道上的所有链码 approved/committed 可用吗?
部署到同一个通道的链代码是命名空间的,因此它们的键仍然特定于使用它们的链代码。因此,您看到部署到同一通道的 2 个链代码按设计工作,它们看不到彼此的密钥。
然而,一个链码可以包含多个不同的合约,在这种情况下,合约可以访问彼此的密钥,因为它们仍然在同一个链码部署中。
您可以使用 InvokeChaincode() API 在同一通道上拥有一个链代码 invoke/query 另一个链代码。被调用链码可以 return keys/values 到调用者链码。通过这种方法,可以将所有访问控制逻辑嵌入到被调用的链代码中。