-
Notifications
You must be signed in to change notification settings - Fork 0
/
coin.go
34 lines (27 loc) · 1.15 KB
/
coin.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
package types
import (
"fmt"
"strings"
)
// SenderChainIsSource returns false if the denomination originally came
// from the receiving chain and true otherwise.
func SenderChainIsSource(sourcePort, sourceChannel, denom string) bool {
// This is the prefix that would have been prefixed to the denomination
// on sender chain IF and only if the token originally came from the
// receiving chain.
return !ReceiverChainIsSource(sourcePort, sourceChannel, denom)
}
// ReceiverChainIsSource returns true if the denomination originally came
// from the receiving chain and false otherwise.
func ReceiverChainIsSource(sourcePort, sourceChannel, denom string) bool {
// The prefix passed in should contain the SourcePort and SourceChannel.
// If the receiver chain originally sent the token to the sender chain
// the denom will have the sender's SourcePort and SourceChannel as the
// prefix.
voucherPrefix := GetDenomPrefix(sourcePort, sourceChannel)
return strings.HasPrefix(denom, voucherPrefix)
}
// GetDenomPrefix returns the receiving denomination prefix
func GetDenomPrefix(portID, channelID string) string {
return fmt.Sprintf("%s/%s/", portID, channelID)
}