-
Notifications
You must be signed in to change notification settings - Fork 573
/
keys.go
63 lines (49 loc) · 1.87 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
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"
KeyTotalEscrowPrefix = "totalEscrowForDenom"
)
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]
}
// TotalEscrowForDenomKey returns the store key of under which the total amout of
// source chain tokens in escrow is stored.
func TotalEscrowForDenomKey(denom string) []byte {
return []byte(fmt.Sprintf("%s/%s", KeyTotalEscrowPrefix, denom))
}