-
Notifications
You must be signed in to change notification settings - Fork 198
/
stake_to_max_cu_list.go
46 lines (36 loc) · 1.04 KB
/
stake_to_max_cu_list.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
package types
import "encoding/json"
// reference: https://github.com/gogo/protobuf/blob/master/custom_types.md
func (cuList StakeToMaxCUList) Equal(other StakeToMaxCUList) bool {
if len(cuList.List) != len(other.List) {
return false
}
for i, item := range cuList.List {
if item != other.List[i] {
return false
}
}
return true
}
func (cuList StakeToMaxCUList) Compare(other StakeToMaxCUList) int {
if len(cuList.List) != len(other.List) {
return len(cuList.List) - len(other.List)
}
for i, item := range cuList.List {
if item != other.List[i] {
return (int(item.StakeThreshold.Amount.Int64()) - int(other.List[i].StakeThreshold.Amount.Int64())) + (int(item.MaxComputeUnits) - int(other.List[i].MaxComputeUnits))
}
}
return 0
}
// func NewPopulatedT(r randyThetest) *T {}
func (cuList StakeToMaxCUList) MarshalJSON() ([]byte, error) {
return json.Marshal(cuList.List)
}
func (cuList *StakeToMaxCUList) UnmarshalJSON(data []byte) error {
err := json.Unmarshal(data, &cuList.List)
if err != nil {
return err
}
return nil
}