-
Notifications
You must be signed in to change notification settings - Fork 580
/
keys.go
55 lines (43 loc) · 1.58 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
package types
import (
"crypto/sha256"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName defines the IBC transfer name
ModuleName = "transfer"
// Version defines the current version the IBC tranfer
// module supports
Version = "ics20-1"
// PortID is the default port id that transfer module binds to
PortID = "transfer"
// StoreKey is the store key string for IBC transfer
StoreKey = ModuleName
// RouterKey is the message route for IBC transfer
RouterKey = ModuleName
// QuerierRoute is the querier route for IBC transfer
QuerierRoute = ModuleName
// DenomPrefix is the prefix used for internal SDK coin representation.
DenomPrefix = "ibc"
)
var (
// PortKey defines the key to store the port ID in store
PortKey = []byte{0x01}
// DenomTraceKey defines the key to store the denomination trace info in store
DenomTraceKey = []byte{0x02}
)
// GetEscrowAddress returns the escrow address for the specified channel.
// The escrow address follows the format as outlined in ADR 028:
// https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-028-public-key-addresses.md
func GetEscrowAddress(portID, channelID string) sdk.AccAddress {
// a slash is used to create domain separation between port and channel identifiers to
// prevent address collisions between escrow addresses created for different channels
contents := fmt.Sprintf("%s/%s", portID, channelID)
// ADR 028 AddressHash construction
preImage := []byte(Version)
preImage = append(preImage, 0)
preImage = append(preImage, contents...)
hash := sha256.Sum256(preImage)
return hash[:20]
}