-
Notifications
You must be signed in to change notification settings - Fork 45
/
types.go
91 lines (79 loc) · 1.83 KB
/
types.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package types
import (
"fmt"
"reflect"
sdkmath "cosmossdk.io/math"
)
const (
SecondarySPNum = 6
// MinChargeSize is the minimum size to charge for a storage object
MinChargeSize = 1024
)
type (
Int = sdkmath.Int
Uint = sdkmath.Uint
)
const (
TagKeyTraits = "traits"
TagValueOmit = "omit"
MaxPaginationLimit = 200 // the default limit is 100 if pagination parameters is not provided
)
func EncodeSequence(u Uint) []byte {
return u.Bytes()
}
func DecodeSequence(bz []byte) Uint {
u := sdkmath.NewUint(0)
return u.SetBytes(bz)
}
func (m *BucketInfo) ToNFTMetadata() *BucketMetaData {
return &BucketMetaData{
BucketName: m.BucketName,
Attributes: getNFTAttributes(*m),
}
}
func (m *ObjectInfo) ToNFTMetadata() *ObjectMetaData {
return &ObjectMetaData{
ObjectName: m.ObjectName,
Attributes: getNFTAttributes(*m),
}
}
func (m *GroupInfo) ToNFTMetadata() *GroupMetaData {
return &GroupMetaData{
GroupName: m.GroupName,
Attributes: getNFTAttributes(*m),
}
}
func getNFTAttributes(m interface{}) []Trait {
attributes := make([]Trait, 0)
v := reflect.ValueOf(m)
typ := v.Type()
for i := 0; i < v.NumField(); i++ {
if typ.Field(i).Tag.Get(TagKeyTraits) == TagValueOmit {
continue
}
attributes = append(attributes,
Trait{
TraitType: typ.Field(i).Name,
Value: fmt.Sprintf("%v", v.Field(i).Interface()),
})
}
return attributes
}
func (di *DeleteInfo) IsEmpty() bool {
isBucketIdsEmpty := false
isObjectIdsEmpty := false
isGroupIdsEmpty := false
if di == nil {
return true
}
if di.BucketIds == nil || len(di.BucketIds.Id) == 0 {
isBucketIdsEmpty = true
}
if di.ObjectIds == nil || len(di.ObjectIds.Id) == 0 {
isObjectIdsEmpty = true
}
if di.GroupIds == nil || len(di.GroupIds.Id) == 0 {
isGroupIdsEmpty = true
}
return isBucketIdsEmpty && isObjectIdsEmpty && isGroupIdsEmpty
}