-
Notifications
You must be signed in to change notification settings - Fork 44
/
keys.go
81 lines (63 loc) · 2.29 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
package types
import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/bnb-chain/greenfield/internal/sequence"
)
const (
// ModuleName defines the module name
ModuleName = "storage"
// 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_storage"
)
type RawID math.Uint
var (
BucketPrefix = []byte{0x11}
ObjectPrefix = []byte{0x12}
GroupPrefix = []byte{0x13}
BucketByIDPrefix = []byte{0x21}
ObjectByIDPrefix = []byte{0x22}
GroupByIDPrefix = []byte{0x23}
BucketSequencePrefix = []byte{0x31}
ObjectSequencePrefix = []byte{0x32}
GroupSequencePrefix = []byte{0x33}
)
// GetBucketKey return the bucket name store key
func GetBucketKey(bucketName string) []byte {
objectNameHash := sdk.Keccak256([]byte(bucketName))
return append(BucketPrefix, objectNameHash...)
}
// GetObjectKey return the object name store key
func GetObjectKey(bucketName string, objectName string) []byte {
bucketNameHash := sdk.Keccak256([]byte(bucketName))
objectNameHash := sdk.Keccak256([]byte(objectName))
return append(ObjectPrefix, append(bucketNameHash, objectNameHash...)...)
}
func GetObjectKeyOnlyBucketPrefix(bucketName string) []byte {
return append(ObjectPrefix, sdk.Keccak256([]byte(bucketName))...)
}
// GetGroupKey return the group name store key
func GetGroupKey(owner sdk.AccAddress, groupName string) []byte {
groupNameHash := sdk.Keccak256([]byte(groupName))
return append(GroupPrefix, append(owner.Bytes(), groupNameHash...)...)
}
// GetGroupKeyOnlyOwnerPrefix return the group name store key
func GetGroupKeyOnlyOwnerPrefix(owner sdk.AccAddress) []byte {
return append(GroupPrefix, owner.Bytes()...)
}
// GetBucketByIDKey return the bucketID store key
func GetBucketByIDKey(bucketId math.Uint) []byte {
return append(BucketByIDPrefix, sequence.EncodeSequence(bucketId)...)
}
// GetObjectByIDKey return the objectId store key
func GetObjectByIDKey(objectId math.Uint) []byte {
return append(ObjectByIDPrefix, sequence.EncodeSequence(objectId)...)
}
// GetGroupByIDKey return the groupId store key
func GetGroupByIDKey(groupId math.Uint) []byte {
return append(GroupByIDPrefix, sequence.EncodeSequence(groupId)...)
}