HLF Chaincode的自定义骑士和Unmarshaller。需要升级链码并将字段的数据类型从float64更改为字符串

发布于 2025-02-01 13:39:50 字数 461 浏览 4 评论 0原文

我们如何为HLF Chaincode编写自定义卫生机和Unmarshaller?需要升级链码并将字段的数据类型从float64更改为字符串。

如果我们只是替换了struct(资产)中的数据类型,则createEasset和getAsset在json.unmarshal()失败,因为它无法解散JSON。

例如。

原始资产结构:

type Asset struct{

   Name string `json:"name"`

   Cost float64 `json:"cost"`

}

新资产结构:(链码升级)

type Asset struct{

   Name string `json:"name"`

   Cost string`json:"cost"`

}

How can we write Custom marshaller and unmarshaller for HLF chaincode? Need to upgrade chaincode and change the data type of a field from float64 to string.

If we just replace the data type in struct (Asset), both CreateAsset and GetAsset fail at json.Unmarshal() as it is unable to unmarshal the JSON.

eg.

original Asset struct:

type Asset struct{

   Name string `json:"name"`

   Cost float64 `json:"cost"`

}

new Asset struct: (chaincode upgraded)

type Asset struct{

   Name string `json:"name"`

   Cost string`json:"cost"`

}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文