-
Notifications
You must be signed in to change notification settings - Fork 381
/
keys.go
62 lines (48 loc) · 1.68 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
package types
import (
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName is the name of the contract module
ModuleName = "wasm"
// StoreKey is the string store representation
StoreKey = ModuleName
// TStoreKey is the string transient store representation
TStoreKey = "transient_" + ModuleName
// QuerierRoute is the querier route for the staking module
QuerierRoute = ModuleName
// RouterKey is the msg router key for the staking module
RouterKey = ModuleName
)
const ( // event attributes
AttributeKeyContract = "contract_address"
AttributeKeyCodeID = "code_id"
AttributeKeySigner = "signer"
)
// nolint
var (
CodeKeyPrefix = []byte{0x01}
ContractKeyPrefix = []byte{0x02}
ContractStorePrefix = []byte{0x03}
SequenceKeyPrefix = []byte{0x04}
ContractHistoryStorePrefix = []byte{0x05}
KeyLastCodeID = append(SequenceKeyPrefix, []byte("lastCodeId")...)
KeyLastInstanceID = append(SequenceKeyPrefix, []byte("lastContractId")...)
)
// GetCodeKey constructs the key for retreiving the ID for the WASM code
func GetCodeKey(codeID uint64) []byte {
contractIDBz := sdk.Uint64ToBigEndian(codeID)
return append(CodeKeyPrefix, contractIDBz...)
}
func decodeCodeKey(src []byte) uint64 {
return binary.BigEndian.Uint64(src[len(CodeKeyPrefix):])
}
// GetContractAddressKey returns the key for the WASM contract instance
func GetContractAddressKey(addr sdk.AccAddress) []byte {
return append(ContractKeyPrefix, addr...)
}
// GetContractStorePrefixKey returns the store prefix for the WASM contract instance
func GetContractStorePrefixKey(addr sdk.AccAddress) []byte {
return append(ContractStorePrefix, addr...)
}