hyperledger-fabric - 不同的超级账本结构链码可以查看世界状态中的所有键/值对吗?
问题描述
我目前在同一个频道上提交了两个智能合约定义。两者都是用 Go 编写的,有些基础,只做基本的 CRUD 操作。但是,我注意到用一个链码编写的键/值对对另一个链码不可用。
因此,go-audit
我创建了以下记录:
但是后来,我尝试ping
使用 chaincode对 key 执行 get 操作go-asset
,但没有找到以下错误(由 chaincode 返回)
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"`
}
世界状态不应该对通道上批准/提交的所有链码可用吗?
解决方案
部署到同一通道的链代码是命名空间的,因此它们的键仍然特定于使用它们的链代码。因此,您看到部署到同一通道的 2 个链代码按设计工作,它们无法看到彼此的密钥。
然而,一个链码可以由多个不同的合约组成,在这种情况下,这些合约可以访问彼此的密钥,因为它们仍然在同一个链码部署中。
推荐阅读
- python - python中的for循环-生成包含项目列表的输出
- python - 如何将文件转换为列表,然后将该列表转换为字典并在每次运行时将其加载到程序中
- php - Foreach - 如何仅打印第三个和第四个值
- python - Python - 检查缺失库依赖项的用户友好方式的最佳实践?
- ios - 选择器结果始终为零
- eclipse - 在 Eclipse 4.15 中安装 drools 7.38 插件时出错
- laravel - Laravel - 如何从外部 API 解决特殊日期问题
- maven - Synopsys 检测:请求授权失败 [HTTP 错误]:尝试 GET 时出现问题
- spring-boot - 根据某些条件调用 kafka 消费者
- ruby-on-rails - 安装 rails 时出错:错误:无法构建 gem 原生扩展。Ubuntu 20.04