-
Notifications
You must be signed in to change notification settings - Fork 45
/
keys.go
93 lines (76 loc) · 4.05 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
package types
// DONTCOVER
import "strings"
var (
DTagPrefix = []byte("dtag")
DTagTransferRequestPrefix = []byte("transfer_request")
RelationshipsStorePrefix = []byte("relationships")
UsersBlocksStorePrefix = []byte("users_blocks")
ChainLinksPrefix = []byte("chain_links")
UserApplicationLinkPrefix = []byte("user_application_link")
ApplicationLinkClientIDPrefix = []byte("client_id")
)
// DTagStoreKey turns a DTag into the key used to store the address associated with it into the store
func DTagStoreKey(dTag string) []byte {
return append(DTagPrefix, []byte(strings.ToLower(dTag))...)
}
// IncomingDTagTransferRequestsPrefix returns the prefix used to store all the DTag transfer requests that
// have been made towards the given recipient
func IncomingDTagTransferRequestsPrefix(recipient string) []byte {
return append(DTagTransferRequestPrefix, []byte(recipient)...)
}
// DTagTransferRequestStoreKey returns the store key used to save the DTag transfer request made
// from the sender towards the recipient
func DTagTransferRequestStoreKey(sender, recipient string) []byte {
return append(IncomingDTagTransferRequestsPrefix(recipient), []byte(sender)...)
}
// UserRelationshipsPrefix returns the prefix used to store all relationships created
// by the user with the given address
func UserRelationshipsPrefix(user string) []byte {
return append(RelationshipsStorePrefix, []byte(user)...)
}
// 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(user, subspace string) []byte {
return append(UserRelationshipsPrefix(user), []byte(subspace)...)
}
// RelationshipsStoreKey returns the store key used to store the relationships containing the given data
func RelationshipsStoreKey(user, subspace, recipient string) []byte {
return append(UserRelationshipsSubspacePrefix(user, subspace), []byte(recipient)...)
}
// BlockerPrefix returns the store prefix used to store the blocks created by the given blocker
func BlockerPrefix(blocker string) []byte {
return append(UsersBlocksStorePrefix, []byte(blocker)...)
}
// BlockerSubspacePrefix returns the store prefix used to store the blocks that the given blocker
// has created inside the specified subspace
func BlockerSubspacePrefix(blocker string, subspace string) []byte {
return append(BlockerPrefix(blocker), []byte(subspace)...)
}
// 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 string, subspace string, blockedUser string) []byte {
return append(BlockerSubspacePrefix(blocker, subspace), []byte(blockedUser)...)
}
// UserChainLinksPrefix returns the store prefix used to identify all the chain links for the given user
func UserChainLinksPrefix(user string) []byte {
return append(ChainLinksPrefix, []byte(user)...)
}
// ChainLinksStoreKey returns the store key used to store the chain links containing the given data
func ChainLinksStoreKey(user, chainName, address string) []byte {
return append(UserChainLinksPrefix(user), []byte(chainName+address)...)
}
// UserApplicationLinksPrefix returns the store prefix used to identify all the application links for the given user
func UserApplicationLinksPrefix(user string) []byte {
return append(UserApplicationLinkPrefix, []byte(user)...)
}
// UserApplicationLinkKey returns the key used to store the data about the application link
// of the given user for the specified application and username
func UserApplicationLinkKey(user, application, username string) []byte {
return append(UserApplicationLinksPrefix(user), []byte(strings.ToLower(application)+strings.ToLower(username))...)
}
// ApplicationLinkClientIDKey returns the key used to store the reference to the application link
// associated with the specified client id
func ApplicationLinkClientIDKey(clientID string) []byte {
return append(ApplicationLinkClientIDPrefix, []byte(clientID)...)
}