HLF Chaincode的自定义骑士和Unmarshaller。需要升级链码并将字段的数据类型从float64更改为字符串
我们如何为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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论