我正在研究供应链Dapps。在这里,我只想将预算添加到所有块中,而不是整个块

发布于 2025-01-26 03:03:49 字数 1063 浏览 3 评论 0原文

    type Product struct {
    ID        string `json:"id"`
    Name      string `json:"name"`
    Area      string `json:"area"`
    OwnerName string `json:"ownerName"`
    Value     int    `json:"cost"`
    Budget    int    `json:"budget"`
}
func (pc *ProductTransferSmartContract) AddProduct(ctx contractapi.TransactionContextInterface, id string, name string, area string, ownerName string, cost int, budget int) error {

    productJSON, err := ctx.GetStub().GetState(id)
    if err != nil {
        return fmt.Errorf("Failed to read the data from world state", err)
    }

    if productJSON != nil {
        return fmt.Errorf("the product %s already exists", id)
    }

    prop := Product{
        ID:        id,
        Name:      name,
        Area:      area,
        OwnerName: ownerName,
        Value:     cost,
    }

    productBytes, err := json.Marshal(prop)
    if err != nil {
        return err
    }

    return ctx.GetStub().PutState(id, productBytes)
}

在这里,我只想以所有者名称附加预算,以便如果所有者更改了,我也可以更改预算。在这里,我在Golang写了链码。

    type Product struct {
    ID        string `json:"id"`
    Name      string `json:"name"`
    Area      string `json:"area"`
    OwnerName string `json:"ownerName"`
    Value     int    `json:"cost"`
    Budget    int    `json:"budget"`
}
func (pc *ProductTransferSmartContract) AddProduct(ctx contractapi.TransactionContextInterface, id string, name string, area string, ownerName string, cost int, budget int) error {

    productJSON, err := ctx.GetStub().GetState(id)
    if err != nil {
        return fmt.Errorf("Failed to read the data from world state", err)
    }

    if productJSON != nil {
        return fmt.Errorf("the product %s already exists", id)
    }

    prop := Product{
        ID:        id,
        Name:      name,
        Area:      area,
        OwnerName: ownerName,
        Value:     cost,
    }

    productBytes, err := json.Marshal(prop)
    if err != nil {
        return err
    }

    return ctx.GetStub().PutState(id, productBytes)
}

here i want to attach budget only with owner name so that if owner got changed i can change the budget too. Here i have written chaincode in golang.

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

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

发布评论

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

评论(1

你爱我像她 2025-02-02 03:03:49

如果需要仅限制所有者的预算访问,则可以使用私人数据收集。相应的API为GetPrivatedAta和PutprivatedAta。

If requirement is to restrict budget access only for owner, then private data collection can be used. Corresponding APIs are getPrivateData and putPrivateData.

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