/
spec.go
60 lines (49 loc) · 1.03 KB
/
spec.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
50
51
52
53
54
55
56
57
58
59
60
package v1
import (
"encoding/hex"
"code.vegaprotocol.io/vega/libs/crypto"
)
func NewID(signers []*Signer, filters []*Filter) string {
buf := []byte{}
for _, filter := range filters {
s := filter.Key.Name + filter.Key.Type.String()
for _, c := range filter.Conditions {
s += c.Operator.String() + c.Value
}
buf = append(buf, []byte(s)...)
}
return hex.EncodeToString(crypto.Hash(buf))
}
func (p PropertyKey) DeepClone() *PropertyKey {
return &PropertyKey{
Name: p.Name,
Type: p.Type,
}
}
func (p Property) DeepClone() *Property {
return &p
}
func (c Condition) DeepClone() *Condition {
return &Condition{
Value: c.Value,
Operator: c.Operator,
}
}
func (s Signer) DeepClone() *Signer {
return &Signer{
Signer: s.Signer,
}
}
func (f Filter) DeepClone() *Filter {
if f.Key != nil {
f.Key = f.Key.DeepClone()
}
if len(f.Conditions) > 0 {
conditions := f.Conditions
f.Conditions = make([]*Condition, len(conditions))
for i, c := range conditions {
f.Conditions[i] = c.DeepClone()
}
}
return &f
}