/
immutables.go
49 lines (40 loc) · 1.5 KB
/
immutables.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
// SPDX-License-Identifier: Apache-2.0
package base
import (
"github.com/AssetMantle/schema/go/ids"
baseIDs "github.com/AssetMantle/schema/go/ids/base"
"github.com/AssetMantle/schema/go/lists"
baseLists "github.com/AssetMantle/schema/go/lists/base"
"github.com/AssetMantle/schema/go/properties"
"github.com/AssetMantle/schema/go/qualified"
)
var _ qualified.Immutables = (*Immutables)(nil)
func (immutables *Immutables) ValidateBasic() error {
return immutables.PropertyList.ValidateBasic()
}
// TODO write test case
func (immutables *Immutables) GetImmutablePropertyList() lists.PropertyList {
if immutables.PropertyList.Get() == nil {
return baseLists.NewPropertyList()
}
return immutables.PropertyList
}
func (immutables *Immutables) GetProperty(id ids.PropertyID) properties.AnyProperty {
return immutables.GetImmutablePropertyList().GetProperty(id)
}
func (immutables *Immutables) GenerateHashID() ids.ID {
metaList := make([][]byte, len(immutables.PropertyList.Get()))
for i, immutableProperty := range immutables.PropertyList.Get() {
metaList[i] = immutableProperty.GetDataID().(ids.DataID).GetHashID().Bytes()
}
return baseIDs.GenerateHashID(metaList...)
}
func NewImmutables(propertyList lists.PropertyList) qualified.Immutables {
if propertyList == nil {
return &Immutables{baseLists.NewPropertyList().(*baseLists.PropertyList)}
}
return &Immutables{
PropertyList: propertyList.(*baseLists.PropertyList),
}
}