-
Notifications
You must be signed in to change notification settings - Fork 44
/
keys.go
87 lines (68 loc) · 2.41 KB
/
keys.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
package types
import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/bnb-chain/greenfield/types/resource"
)
const (
// ModuleName defines the module name
ModuleName = "permission"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RouterKey defines the module's message routing key
RouterKey = ModuleName
// MemStoreKey defines the in-memory store key
MemStoreKey = "mem_permission"
)
func KeyPrefix(p string) []byte {
return []byte(p)
}
var (
BucketPolicyToAccountPrefix = []byte{0x11}
ObjectPolicyToAccountPrefix = []byte{0x12}
GroupPolicyToAccountPrefix = []byte{0x13}
BucketPolicyToGroupPrefix = []byte{0x21}
ObjectPolicyToGroupPrefix = []byte{0x22}
PolicyByIDPrefix = []byte{0x31}
PolicySequencePrefix = []byte{0x41}
)
func GetPolicyToAccountKey(resourceID math.Uint, resourceType resource.ResourceType, addr sdk.AccAddress) []byte {
switch resourceType {
case resource.RESOURCE_TYPE_BUCKET:
return GetBucketPolicyToAccountKey(resourceID, addr)
case resource.RESOURCE_TYPE_OBJECT:
return GetObjectPolicyToAccountKey(resourceID, addr)
case resource.RESOURCE_TYPE_GROUP:
return GetGroupPolicyToAccountKey(resourceID, addr)
default:
return nil
}
}
func GetBucketPolicyToAccountKey(resourceID math.Uint, addr sdk.AccAddress) []byte {
return append(BucketPolicyToAccountPrefix, append(resourceID.Bytes(), addr.Bytes()...)...)
}
func GetObjectPolicyToAccountKey(resourceID math.Uint, addr sdk.AccAddress) []byte {
return append(ObjectPolicyToAccountPrefix, append(resourceID.Bytes(), addr.Bytes()...)...)
}
func GetGroupPolicyToAccountKey(resourceID math.Uint, addr sdk.AccAddress) []byte {
return append(GroupPolicyToAccountPrefix, append(resourceID.Bytes(), addr.Bytes()...)...)
}
func GetPolicyToGroupKey(resourceID math.Uint, resourceType resource.ResourceType) []byte {
switch resourceType {
case resource.RESOURCE_TYPE_BUCKET:
return GetBucketPolicyToGroupKey(resourceID)
case resource.RESOURCE_TYPE_OBJECT:
return GetObjectPolicyToGroupKey(resourceID)
default:
return nil
}
}
func GetBucketPolicyToGroupKey(resourceID math.Uint) []byte {
return append(BucketPolicyToGroupPrefix, resourceID.Bytes()...)
}
func GetObjectPolicyToGroupKey(resourceID math.Uint) []byte {
return append(ObjectPolicyToGroupPrefix, resourceID.Bytes()...)
}
func GetPolicyByIDKey(policyID math.Uint) []byte {
return append(PolicyByIDPrefix, policyID.Bytes()...)
}