mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 23:45:10 +00:00
- update Application section in README
- remove param name in app.go
- add error checks in processor/block.go
- move vars from model to transact logic
- move newAsset to transact
- use ID for well-known initialisms
- move randomelement, randomnint and differentelement to transact
- remove AssertDefined
- blockTxIdsJoinedByComma: use standard library to join elements
- return nil, instead of []byte{}
- remove go routine in listen.go
- move cache to parser
- inline processor in listen.go
- move store to main package
- move util to main package
- fixed failing cache issue
- fixed staticcheck issues
- removed cache function, implemented caching in the structs and methods
Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
/*
|
|
* Copyright 2024 IBM All Rights Reserved.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
package contract
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/hyperledger/fabric-gateway/pkg/client"
|
|
)
|
|
|
|
type AssetTransferBasic struct {
|
|
contract *client.Contract
|
|
}
|
|
|
|
func NewAssetTransferBasic(contract *client.Contract) *AssetTransferBasic {
|
|
return &AssetTransferBasic{contract}
|
|
}
|
|
|
|
func (atb *AssetTransferBasic) CreateAsset(anAsset Asset) error {
|
|
if _, err := atb.contract.Submit(
|
|
"CreateAsset",
|
|
client.WithArguments(
|
|
anAsset.ID,
|
|
anAsset.Color,
|
|
strconv.FormatUint(anAsset.Size, 10),
|
|
anAsset.Owner,
|
|
strconv.FormatUint(anAsset.AppraisedValue, 10),
|
|
)); err != nil {
|
|
return fmt.Errorf("in CreateAsset: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (atb *AssetTransferBasic) TransferAsset(id, newOwner string) (string, error) {
|
|
result, err := atb.contract.Submit(
|
|
"TransferAsset",
|
|
client.WithArguments(
|
|
id,
|
|
newOwner,
|
|
),
|
|
)
|
|
if err != nil {
|
|
return "", fmt.Errorf("in TransferAsset: %w", err)
|
|
}
|
|
|
|
return string(result), nil
|
|
}
|
|
|
|
func (atb *AssetTransferBasic) DeleteAsset(id string) error {
|
|
if _, err := atb.contract.Submit(
|
|
"DeleteAsset",
|
|
client.WithArguments(
|
|
id,
|
|
),
|
|
); err != nil {
|
|
return fmt.Errorf("in DeleteAsset: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (atb *AssetTransferBasic) GetAllAssets() ([]byte, error) {
|
|
result, err := atb.contract.Evaluate("GetAllAssets")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("in GetAllAssets: %w", err)
|
|
}
|
|
return result, nil
|
|
}
|