'i am working on supply chain DApps .here i want to add budget with ownername only not with the whole block
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.
Solution 1:[1]
If requirement is to restrict budget access only for owner, then private data collection can be used. Corresponding APIs are getPrivateData and putPrivateData.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Satheesh Srinivasan |