mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-18 07:55:10 +00:00
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>
45 lines
903 B
Go
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),
|
|
}
|
|
}
|