forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys.go
51 lines (40 loc) · 1.31 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
package types
import (
"fmt"
sdk "github.com/JaTochNietDan/cosmos-sdk/types"
)
const (
// ModuleName defines the module name
ModuleName = "capability"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// MemStoreKey defines the in-memory store key
MemStoreKey = "mem_capability"
)
var (
// KeyIndex defines the key that stores the current globally unique capability
// index.
KeyIndex = []byte("index")
// KeyPrefixIndexCapability defines a key prefix that stores index to capability
// name mappings.
KeyPrefixIndexCapability = []byte("capability_index")
)
// RevCapabilityKey returns a reverse lookup key for a given module and capability
// name.
func RevCapabilityKey(module, name string) []byte {
return []byte(fmt.Sprintf("%s/rev/%s", module, name))
}
// FwdCapabilityKey returns a forward lookup key for a given module and capability
// reference.
func FwdCapabilityKey(module string, cap *Capability) []byte {
return []byte(fmt.Sprintf("%s/fwd/%p", module, cap))
}
// IndexToKey returns bytes to be used as a key for a given capability index.
func IndexToKey(index uint64) []byte {
return sdk.Uint64ToBigEndian(index)
}
// IndexFromKey returns an index from a call to IndexToKey for a given capability
// index.
func IndexFromKey(key []byte) uint64 {
return sdk.BigEndianToUint64(key)
}