-
Notifications
You must be signed in to change notification settings - Fork 45
/
keys.go
56 lines (45 loc) · 2.14 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
package types
import (
subspacestypes "github.com/desmos-labs/desmos/v5/x/subspaces/types"
)
// DONTCOVER
const (
ModuleName = "relationships"
RouterKey = ModuleName
StoreKey = ModuleName
ActionCreateRelationship = "create_relationship"
ActionDeleteRelationship = "delete_relationship"
ActionBlockUser = "block_user"
ActionUnblockUser = "unblock_user"
)
var (
RelationshipsStorePrefix = []byte{0x01}
UsersBlocksStorePrefix = []byte{0x02}
)
// SubspaceRelationshipsPrefix returns the prefix used to store all relationships for the given subspace
func SubspaceRelationshipsPrefix(subspaceID uint64) []byte {
return append(RelationshipsStorePrefix, subspacestypes.GetSubspaceIDBytes(subspaceID)...)
}
// UserRelationshipsSubspacePrefix returns the prefix used to store all the relationships created by the user
// with the given address for the subspace having the given id
func UserRelationshipsSubspacePrefix(subspace uint64, user string) []byte {
return append(SubspaceRelationshipsPrefix(subspace), []byte(user)...)
}
// RelationshipsStoreKey returns the store key used to store the relationships containing the given data
func RelationshipsStoreKey(user, counterparty string, subspace uint64) []byte {
return append(UserRelationshipsSubspacePrefix(subspace, user), []byte(counterparty)...)
}
// SubspaceBlocksPrefix returns the store prefix used to store the blocks for the given subspace
func SubspaceBlocksPrefix(subspaceID uint64) []byte {
return append(UsersBlocksStorePrefix, subspacestypes.GetSubspaceIDBytes(subspaceID)...)
}
// BlockerSubspacePrefix returns the store prefix used to store the blocks that the given blocker
// has created inside the specified subspace
func BlockerSubspacePrefix(subspaceID uint64, blocker string) []byte {
return append(SubspaceBlocksPrefix(subspaceID), []byte(blocker)...)
}
// UserBlockStoreKey returns the store key used to save the block made by the given blocker,
// inside the specified subspace and towards the given blocked user
func UserBlockStoreKey(blocker, blockedUser string, subspace uint64) []byte {
return append(BlockerSubspacePrefix(subspace, blocker), []byte(blockedUser)...)
}