fabric-samples/off_chain_data/application-go/contract/asset.go
Stanislav Jakuschevskij 2c43e03591
Encapsulate block parser in a package
Created parser, contract and utils packages and extracted each piece of
functionality into its own files. Removed "Get" prefix from methods and
changed return values from interfaces to structs.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00

45 lines
903 B
Go

/*
* Copyright 2024 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
package contract
import (
"offChainData/utils"
"github.com/google/uuid"
)
var (
colors = []string{"red", "green", "blue"}
Owners = []string{"alice", "bob", "charlie"}
)
const (
maxInitialValue = 1000
maxInitialSize = 10
)
type Asset struct {
ID string `json:"ID"`
Color string `json:"Color"`
Size uint64 `json:"Size"`
Owner string `json:"Owner"`
AppraisedValue uint64 `json:"AppraisedValue"`
}
func NewAsset() Asset {
id, err := uuid.NewRandom()
if err != nil {
panic(err)
}
return Asset{
ID: id.String(),
Color: utils.RandomElement(colors),
Size: uint64(utils.RandomInt(maxInitialSize) + 1),
Owner: utils.RandomElement(Owners),
AppraisedValue: uint64(utils.RandomInt(maxInitialValue) + 1),
}
}