我可以在HyperLeDger Fabric Worldstate中看到/存储SHA256吗?

发布于 2025-02-02 00:55:18 字数 2272 浏览 3 评论 0原文

我一直在研究测试HyperLeDger面料,以存储一些文件和文件夹中的详细信息,包括SHA256键跟踪对文件进行的更新。我已经安装了测试网络,可以使网络正确运行,并安装并定义了工作链码。一切正常,除了我查询资产时,唯一缺少的字段是SHA256密钥。

有原因吗?

这就是应该初始化分类帐的方式:

//启动为分类帐添加一组资产集 func(S *SmartContract)启动(CTX Contractapi.transactionContextTeinterface)错误{ 资产:= []资产{ {id:“ asset1”,sha256:“ 3654DDA35F2604FE4FE4FE4FE4FE4FAE361B0AB777850FC4B9B9B21F098BEDBED8BFDFF376”,尺寸:56,Modifyon:56,Modiediedon:“ 06.04.2022 09:29:” {id:“ Asset2”,SHA256:“ FE8979C7B6F69B393FF1BBD688D33CAFA3FD3E8EFC19555682CC685517BD64B7” {id:“ Asset3”,SHA256:“ C023E9F6C1FB3D0BA9894123E0C58C46039863DEA617E9007569F760143334206”,尺寸:5992,Modifiedon:5992 {id:“ Asset4”,SHA256:“ 5F87DB405F88F678878710A6F21C4DD74221716B4832A17D3CBD4701741C71C716A9B” {id:“ Asset5”,SHA256:“ 367C38D5833E63E19A2053C2787B9913ED45E406D947A555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555FC603C60A9D7” {id:“ asset6”,sha256:“ D1652041E169DDFE0EE32CD0F8B4EF6F968DBDDBD2DD19A3769DD444081661BF202” {id:“ Asset7”,SHA256:“ 2F9684E36BACE94D4791160A31E31E0595E4CAE7A9F17003D460F01C7E1C7E1ED1ED1ED1ED1ED1ED1ED1ED1ED1ED4” {id:“ Asset8”,SHA256:“ 702B9D6DDD7D850CA7AE06D9521EF5400EA5D8A2E2E6FFA75757560EF54B3A1BA1BA1” {id:“ Asset9”,SHA256:“ A81F09AE679DBF4C597060D6DE14283B69C7C1A0C1A0C0FBC6E484C5762D0C19AB26” {ID:“ Asset10”,SHA256:“ 6E166D4F7C464CFF392F392F3D4E3E13BD780243A9793D19B95A1EB1EB1DF896AB912A” }

这是查询的结果:

对等链码查询-C myChannel -n基本-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”:“ asset3”,“ modifyon” :“ 20.03.2022 08:53”,“ size”:5992},{“ id”:“ asset4”,“ modifyon”:“ 21.09.2016 11:21”,“ size”:45336},“:45336},{” :“ Asset5”,“ Modifiedon”:“ 13.08.2013 10:40”,“ size”:108},, {“ id”:“ asset6”,“ modifiedon”:“ 21.02.2019 17:00”,“ size”:5308},{“ id”:“ asset7”,“ modifyon”:“ 12.04.2022 17:02” ,“ size”:8704},{“ id”:“ asset8”,“ modifiedon”:“ 27.02.2022 09:22”,“ size”:13436},{“ id”“:” Asset9:“ sist9”,“ modifyon”: “ 27.04.2022 13:35”,“大小”:159732}]

SHA256只是缺少。 对此的任何帮助将不胜感激。

I have been working on testing hyperledger fabric to store details on a selection of files and folders including sha256 keys to track updates made to a file. I have installed the test network, I am able to get the network running correctly and have installed and defined the chaincode to work. Everything is working perfectly, except when I query the assets the only field missing is the sha256 key.

Is there a reason for this?

This is how the ledger should be initialised:

// InitLedger adds a base set of assets to the ledger
func (s *SmartContract) InitLedger(ctx contractapi.TransactionContextInterface) error {
assets := []Asset{
{ID: "asset1", sha256: "3654dda35f2604fe43af8b49fae361b0ab77850fc4b9b2d21f098bed8bfdf376", Size: 56, ModifiedOn: "06.04.2022 09:29"},
{ID: "asset2", sha256: "fe8979c8c7b6f69b393ff1bbd688d3cafa3fd3e8efc1955682cc685517bd64b7", Size: 9756, ModifiedOn: "28.05.2020 10:26"},
{ID: "asset3", sha256: "c023e9f6c1fb3d0ba9894123e0c58c46039863dea617e9007569f76014334206", Size: 5992, ModifiedOn: "20.03.2022 08:53"},
{ID: "asset4", sha256: "5f87db405f88f6788710a6f21c4dd74221716b4832a17d3cbd4701741c716a9b", Size: 45336, ModifiedOn: "21.09.2016 11:21"},
{ID: "asset5", sha256: "367c38d5833e63e19a2053c2787b9913ed45e406d947a55fc08b21d03c60a9d7", Size: 108, ModifiedOn: "13.08.2013 10:40"},
{ID: "asset6", sha256: "d1652041e169ddfe0ee32cd0f8b4ef6f968dbd2dd119a3769dd44081661bf202", Size: 5308, ModifiedOn: "21.02.2019 17:00"},
{ID: "asset7", sha256: "2f9684e36bace94d4791160a31e0595e4cae7a9f17003d460f01c7e1ed1e8b04", Size: 8704, ModifiedOn: "12.04.2022 17:02"},
{ID: "asset8", sha256: "702b9d6ddd7d850ca7ae06d9521ef5400ea5d8a2e6ffa75737560ef54b3a1ba1", Size: 13436, ModifiedOn: "27.02.2022 09:22"},
{ID: "asset9", sha256: "a81f09ae679dbf4c597060d6de14283b69c7c1a0c0fbc6e484c5762d0c19ab26", Size: 159732, ModifiedOn: "27.04.2022 13:35"},
{ID: "asset10", sha256: "6e166d4f7c464cff392f3d4e3e13bd780243a9793d19b95a1eb1df896ab9162a", Size: 322120, ModifiedOn: "25.05.2022 09:41"},
}

This is the result of a query:

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","Size":45336},{"ID":"asset5","ModifiedOn":"13.08.2013 10:40","Size":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","Size":159732}]

The sha256 is just missing.
Any help on this would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原来分手还会想你 2025-02-09 00:55:19

您正在将资产编码到JSON存储在分类帐中。 Go JSON MARSHALLER仅包括导出的字段。例如:

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"
}

You are marshalling the asset to JSON to store in the ledger. The Go JSON marshaller only includes exported fields. For example:

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)
}

Produces the following output:

Asset: &main.Asset{sha256:"privateSHA256Value", SHA256:"publicSHA256Value"}
JSON: {
    "publicSHA256": "publicSHA256Value"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文