我不能在 Hyperledger Fabric 世界状态中 see/store SHA256 有什么原因吗?

Is there a reason I can't see/store a SHA256 in a Hyperledger Fabric worldstate?

我一直致力于测试 hyperledger fabric 以存储有关所选文件和文件夹的详细信息,包括 sha256 密钥以跟踪对文件所做的更新。我已经安装了测试网络,我能够正确地获取网络 运行 并且已经安装并定义了链码来工作。一切正常,除了当我查询资产时,唯一缺少的字段是 sha256 键。

这有什么原因吗?

账本应该这样初始化:

// InitLedger 将一组基本资产添加到分类帐 func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface) error { 资产 := []资产{ {ID: "asset1", sha256: "3654dda35f2604fe43af8b49fae361b0ab77850fc4b9b2d21f098bed8bfdf376", 尺寸: 56, ModifiedOn: "06.04.2022 09:29"}, {ID:“asset2”,sha256:“fe8979c8c7b6f69b393ff1bbd688d3cafa3fd3e8efc1955682cc685517bd64b7”,大小:9756,修改日期:“28.05.2020 10:26”}, {ID:“asset3”,sha256:“c023e9f6c1fb3d0ba9894123e0c58c46039863dea617e9007569f76014334206”,大小:5992,修改时间:“20.03.2022 08:53”}, {ID: "asset4", sha256: "5f87db405f88f6788710a6f21c4dd74221716b4832a17d3cbd4701741c716a9b", 尺寸: 45336, ModifiedOn: "21.09.2016 11:21"}, {ID: "asset5", sha256: "367c38d5833e63e19a2053c2787b9913ed45e406d947a55fc08b21d03c60a9d7", 尺寸: 108, ModifiedOn: "13.08.2013 10:40"}, {ID:“asset6”,sha256:“d1652041e169ddfe0ee32cd0f8b4ef6f968dbd2dd119a3769dd44081661bf202”,大小:5308,修改时间:“21.02.2019 17:00”}, {ID: "asset7", sha256: "2f9684e36bace94d4791160a31e0595e4cae7a9f17003d460f01c7e1ed1e8b04", 大小: 8704, ModifiedOn: "12.04.2022 17:02"}, {ID:“asset8”,sha256:“702b9d6ddd7d850ca7ae06d9521ef5400ea5d8a2e6ffa75737560ef54b3a1ba1”,大小:13436,修改日期:“27.02.2022 09:22”}, {ID:“asset9”,sha256:“a81f09ae679dbf4c597060d6de14283b69c7c1a0c0fbc6e484c5762d0c19ab26”,大小:159732,修改时间:“27.04.2022 13:35”}, {ID: "asset10", sha256: "6e166d4f7c464cff392f3d4e3e13bd780243a9793d19b95a1eb1df896ab9162a", 尺寸: 322120, ModifiedOn: "25.05.2022 09:41"}, }

这是查询的结果:

peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}' [{"ID":"asset1","ModifiedOn":"06.04.2022 09:29","Size":56},{"ID":"asset10","ModifiedOn":"25.05.2022 09:41","Size":322120},{"ID":"asset2","ModifiedOn":"28.05.2020 10:26","Size":9756},{"ID":" asset3","ModifiedOn":"20.03.2022 08:53","Size":5992},{"ID":"asset4","ModifiedOn":"21.09.2016 11:21","大小":45336},{"ID":"asset5","ModifiedOn":"13.08.2013 10:40","大小":108}, {"ID":"asset6","ModifiedOn":"21.02.2019 17:00","Size":5308},{"ID":"asset7","ModifiedOn":"12.04.2022 17:02","Size":8704},{"ID":"asset8","ModifiedOn":"27.02.2022 09:22","Size":13436},{"ID":"asset9 ","ModifiedOn":"27.04.2022 13:35","大小":159732}]

缺少 sha256。 如有任何帮助,我们将不胜感激。

您正在将资产编组到 JSON 以存储在分类帐中。 Go JSON 编组器仅包含导出的字段。例如:

type Asset struct {
    sha256 string `json:"privateSHA256"`
    SHA256 string `json:"publicSHA256"`
}

func main() {
asset := &Asset{
    sha256: "privateSHA256Value",
    SHA256: "publicSHA256Value",
}

    assetJSON, err := json.MarshalIndent(asset, "", "    ")
    if err != nil {
        panic(err)
    }

    fmt.Printf("Asset: %#v\n", asset)
    fmt.Printf("JSON: %s\n", assetJSON)
}

产生以下输出:

Asset: &main.Asset{sha256:"privateSHA256Value", SHA256:"publicSHA256Value"}
JSON: {
    "publicSHA256": "publicSHA256Value"
}