-
Notifications
You must be signed in to change notification settings - Fork 47
/
keys.go
174 lines (138 loc) · 5.65 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package types
import (
"encoding/binary"
"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"
// TStoreKey defines the transient store key
TStoreKey = "transient_storage"
)
type RawID math.Uint
var (
ParamsKey = []byte{0x01}
VersionedParamsKeyPrefix = []byte{0x02}
BucketInfoPrefix = []byte{0x11}
ObjectInfoPrefix = []byte{0x12}
GroupInfoPrefix = []byte{0x13}
QuotaPrefix = []byte{0x14}
InternalBucketInfoPrefix = []byte{0x15}
ShadowObjectInfoPrefix = []byte{0x16}
LockedObjectCountPrefix = []byte{0x17} // key to track count of created/updating objects, which will involve lock fee
BucketByIDPrefix = []byte{0x21}
ObjectByIDPrefix = []byte{0x22}
GroupByIDPrefix = []byte{0x23}
BucketSequencePrefix = []byte{0x31}
ObjectSequencePrefix = []byte{0x32}
GroupSequencePrefix = []byte{0x33}
DiscontinueObjectCountPrefix = []byte{0x41}
DiscontinueBucketCountPrefix = []byte{0x42}
DiscontinueObjectIdsPrefix = []byte{0x43}
DiscontinueBucketIdsPrefix = []byte{0x44}
DiscontinueObjectStatusPrefix = []byte{0x45}
// CurrentBlockDeleteStalePoliciesKey is the key for DeleteInfo which keep track of deleted resources in the current block,
//stale permission of these resources needs to be deleted.
// it is stored in transient store
CurrentBlockDeleteStalePoliciesKey = []byte{0x51}
DeleteStalePoliciesPrefix = []byte{0x52}
MigrateBucketPrefix = []byte{0x61}
)
// GetBucketKey return the bucket name store key
func GetBucketKey(bucketName string) []byte {
bucketNameHash := sdk.Keccak256([]byte(bucketName))
return append(BucketInfoPrefix, bucketNameHash...)
}
// 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(ObjectInfoPrefix, append(bucketNameHash, objectNameHash...)...)
}
func GetObjectKeyOnlyBucketPrefix(bucketName string) []byte {
return append(ObjectInfoPrefix, sdk.Keccak256([]byte(bucketName))...)
}
// GetShadowObjectKey return the shadow object name store key
func GetShadowObjectKey(bucketName string, objectName string) []byte {
bucketNameHash := sdk.Keccak256([]byte(bucketName))
objectNameHash := sdk.Keccak256([]byte(objectName))
return append(ShadowObjectInfoPrefix, append(bucketNameHash, objectNameHash...)...)
}
// GetGroupKey return the group name store key
func GetGroupKey(owner sdk.AccAddress, groupName string) []byte {
groupNameHash := sdk.Keccak256([]byte(groupName))
return append(GroupInfoPrefix, append(owner.Bytes(), groupNameHash...)...)
}
// GetGroupKeyOnlyOwnerPrefix return the group name store key
func GetGroupKeyOnlyOwnerPrefix(owner sdk.AccAddress) []byte {
return append(GroupInfoPrefix, owner.Bytes()...)
}
// GetBucketByIDKey return the bucketID store key
func GetBucketByIDKey(bucketId math.Uint) []byte {
var seq sequence.Sequence[math.Uint]
return append(BucketByIDPrefix, seq.EncodeSequence(bucketId)...)
}
// GetObjectByIDKey return the objectId store key
func GetObjectByIDKey(objectId math.Uint) []byte {
var seq sequence.Sequence[math.Uint]
return append(ObjectByIDPrefix, seq.EncodeSequence(objectId)...)
}
// GetGroupByIDKey return the groupId store key
func GetGroupByIDKey(groupId math.Uint) []byte {
var seq sequence.Sequence[math.Uint]
return append(GroupByIDPrefix, seq.EncodeSequence(groupId)...)
}
// GetDiscontinueObjectIdsKey return discontinue object store key
func GetDiscontinueObjectIdsKey(timestamp int64) []byte {
bz := make([]byte, 8)
binary.BigEndian.PutUint64(bz, uint64(timestamp))
return append(DiscontinueObjectIdsPrefix, bz...)
}
// GetDiscontinueBucketIdsKey return discontinue bucket store key
func GetDiscontinueBucketIdsKey(timestamp int64) []byte {
bz := make([]byte, 8)
binary.BigEndian.PutUint64(bz, uint64(timestamp))
return append(DiscontinueBucketIdsPrefix, bz...)
}
// GetDiscontinueObjectStatusKey return discontinue object status store key
func GetDiscontinueObjectStatusKey(objectId math.Uint) []byte {
var seq sequence.Sequence[math.Uint]
return append(DiscontinueObjectStatusPrefix, seq.EncodeSequence(objectId)...)
}
// GetParamsKeyWithTimestamp return multi-version params store key
func GetParamsKeyWithTimestamp(timestamp int64) []byte {
bz := make([]byte, 8)
binary.BigEndian.PutUint64(bz, uint64(timestamp))
return append(ParamsKey, bz...)
}
// GetDeleteStalePoliciesKey return delete stale policies store Key
func GetDeleteStalePoliciesKey(height int64) []byte {
bz := make([]byte, 8)
binary.BigEndian.PutUint64(bz, uint64(height))
return append(DeleteStalePoliciesPrefix, bz...)
}
func GetMigrationBucketKey(bucketID math.Uint) []byte {
var seq sequence.Sequence[math.Uint]
return append(MigrateBucketPrefix, seq.EncodeSequence(bucketID)...)
}
// GetQuotaKey return the quota store key
func GetQuotaKey(bucketID math.Uint) []byte {
var seq sequence.Sequence[math.Uint]
return append(QuotaPrefix, seq.EncodeSequence(bucketID)...)
}
func GetInternalBucketInfoKey(bucketID math.Uint) []byte {
var seq sequence.Sequence[math.Uint]
return append(InternalBucketInfoPrefix, seq.EncodeSequence(bucketID)...)
}
func GetLockedObjectCountKey(bucketId math.Uint) []byte {
var seq sequence.Sequence[math.Uint]
return append(LockedObjectCountPrefix, seq.EncodeSequence(bucketId)...)
}