fabric-samples/off_chain_data/application-go/contract/model.go
Stanislav Jakuschevskij b04bda5b11
Extract block processor and store from listener
Created packages for the flat file store and the processor and moved
functions, variables and constants from listener.go to those packages.
Encapsulated everything not used outside the packages, introduced
model.go files which later might be extracted into a model package and
renamed parser/parsedBlock.go to parser/block.go.

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),
}
}