-
Notifications
You must be signed in to change notification settings - Fork 109
/
cosmos_message.go
54 lines (43 loc) · 1.58 KB
/
cosmos_message.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
package presenter
import (
"strconv"
"strings"
"github.com/strangelove-ventures/interchaintest/v5/internal/blockdb"
)
// CosmosMessage presents a blockdb.CosmosMessageResult.
type CosmosMessage struct {
Result blockdb.CosmosMessageResult
}
func (msg CosmosMessage) Height() string { return strconv.FormatInt(msg.Result.Height, 10) }
// Index is the message's ordered position within the tx.
func (msg CosmosMessage) Index() string { return strconv.Itoa(msg.Result.Index) }
// Type is a URI for the proto definition, e.g. /ibc.core.client.v1.MsgCreateClient
func (msg CosmosMessage) Type() string { return msg.Result.Type }
func (msg CosmosMessage) ClientChain() string { return msg.Result.ClientChainID.String }
func (msg CosmosMessage) Clients() string {
return msg.srcCounterpartyPair(msg.Result.ClientID.String, msg.Result.CounterpartyClientID.String)
}
func (msg CosmosMessage) Connections() string {
return msg.srcCounterpartyPair(msg.Result.ConnID.String, msg.Result.CounterpartyConnID.String)
}
func (msg CosmosMessage) Channels() string {
join := func(channel, port string) string {
if channel+port == "" {
return ""
}
return channel + ":" + port
}
return msg.srcCounterpartyPair(
join(msg.Result.ChannelID.String, msg.Result.PortID.String),
join(msg.Result.CounterpartyChannelID.String, msg.Result.CounterpartyPortID.String),
)
}
func (msg CosmosMessage) srcCounterpartyPair(source, counterparty string) string {
if source != "" {
source += " (source)"
}
if counterparty != "" {
counterparty += " (counterparty)"
}
return strings.TrimSpace(source + " " + counterparty)
}