-
Notifications
You must be signed in to change notification settings - Fork 121
/
hermes_commander.go
211 lines (170 loc) · 7 KB
/
hermes_commander.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package hermes
import (
"context"
"encoding/json"
"fmt"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/relayer"
"go.uber.org/zap"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
"github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
)
var _ relayer.RelayerCommander = &commander{}
type commander struct {
log *zap.Logger
extraStartFlags []string
}
func (c commander) Name() string {
return hermes
}
func (c commander) DefaultContainerImage() string {
return defaultContainerImage
}
func (c commander) DefaultContainerVersion() string {
return DefaultContainerVersion
}
func (c commander) DockerUser() string {
return hermesDefaultUidGid
}
func (c commander) ParseGetChannelsOutput(stdout, stderr string) ([]ibc.ChannelOutput, error) {
jsonBz := extractJsonResult([]byte(stdout))
var result ChannelOutputResult
if err := json.Unmarshal(jsonBz, &result); err != nil {
return nil, err
}
var ibcChannelOutput []ibc.ChannelOutput
for _, r := range result.Result {
ibcChannelOutput = append(ibcChannelOutput, ibc.ChannelOutput{
State: r.ChannelEnd.State,
Ordering: r.ChannelEnd.Ordering,
Counterparty: ibc.ChannelCounterparty{
PortID: r.ChannelEnd.Remote.PortID,
ChannelID: r.ChannelEnd.Remote.ChannelID,
},
ConnectionHops: r.ChannelEnd.ConnectionHops,
Version: r.ChannelEnd.Version,
PortID: r.CounterPartyChannelEnd.Remote.PortID,
ChannelID: r.CounterPartyChannelEnd.Remote.ChannelID,
})
}
return ibcChannelOutput, nil
}
func (c commander) ParseGetConnectionsOutput(stdout, stderr string) (ibc.ConnectionOutputs, error) {
jsonBz := extractJsonResult([]byte(stdout))
var queryResult ConnectionQueryResult
if err := json.Unmarshal(jsonBz, &queryResult); err != nil {
return ibc.ConnectionOutputs{}, err
}
var outputs ibc.ConnectionOutputs
for _, r := range queryResult.Result {
var versions []*ibcexported.Version
for _, v := range r.ConnectionEnd.Versions {
versions = append(versions, &ibcexported.Version{
Identifier: v.Identifier,
Features: v.Features,
})
}
outputs = append(outputs, &ibc.ConnectionOutput{
ID: r.ConnectionID,
ClientID: r.ConnectionEnd.ClientID,
Versions: versions,
State: r.ConnectionEnd.State,
Counterparty: &ibcexported.Counterparty{
ClientId: r.ConnectionEnd.Counterparty.ClientID,
ConnectionId: r.ConnectionEnd.Counterparty.ConnectionID,
Prefix: types.MerklePrefix{
KeyPrefix: []byte(r.ConnectionEnd.Counterparty.Prefix),
},
},
})
}
return outputs, nil
}
func (c commander) ParseGetClientsOutput(stdout, stderr string) (ibc.ClientOutputs, error) {
jsonBz := extractJsonResult([]byte(stdout))
var queryResult ClientQueryResult
if err := json.Unmarshal(jsonBz, &queryResult); err != nil {
return ibc.ClientOutputs{}, err
}
var clientOutputs []*ibc.ClientOutput
for _, r := range queryResult.ClientResult {
clientOutputs = append(clientOutputs, &ibc.ClientOutput{
ClientID: r.ClientID,
ClientState: ibc.ClientState{
ChainID: r.ChainID,
},
})
}
return clientOutputs, nil
}
func (c commander) Init(homeDir string) []string {
return nil
}
func (c commander) GetChannels(chainID, homeDir string) []string {
// the --verbose and --show-counterparty options are required to get enough information to correctly populate
// the path.
return []string{hermes, "--json", "query", "channels", "--chain", chainID, "--show-counterparty", "--verbose"}
}
func (c commander) GetConnections(chainID, homeDir string) []string {
return []string{hermes, "--config", fmt.Sprintf("%s/%s", homeDir, hermesConfigPath), "--json", "query", "connections", "--chain", chainID, "--verbose"}
}
func (c commander) GetClients(chainID, homeDir string) []string {
return []string{hermes, "--config", fmt.Sprintf("%s/%s", homeDir, hermesConfigPath), "--json", "query", "clients", "--host-chain", chainID}
}
func (c commander) StartRelayer(homeDir string, pathNames ...string) []string {
cmd := []string{hermes, "--config", fmt.Sprintf("%s/%s", homeDir, hermesConfigPath), "start"}
cmd = append(cmd, c.extraStartFlags...)
return cmd
}
func (c commander) CreateWallet(keyName, address, mnemonic string) ibc.Wallet {
return NewWallet(keyName, address, mnemonic)
}
func (c commander) UpdatePath(pathName, homeDir string, opts ibc.PathUpdateOptions) []string {
// TODO: figure out how to implement this.
panic("implement me")
}
// the following methods do not have a single command that cleanly maps to a single hermes command without
// additional logic wrapping them. They have been implemented one layer up in the hermes relayer.
func (c commander) UpdateClients(pathName, homeDir string) []string {
panic("update clients implemented in hermes relayer not the commander")
}
func (c commander) GeneratePath(srcChainID, dstChainID, pathName, homeDir string) []string {
panic("generate path implemented in hermes relayer not the commander")
}
func (c commander) LinkPath(pathName, homeDir string, channelOpts ibc.CreateChannelOptions, clientOpts ibc.CreateClientOptions) []string {
panic("link path implemented in hermes relayer not the commander")
}
func (c commander) RestoreKey(chainID, keyName, coinType, mnemonic, homeDir string) []string {
panic("restore key implemented in hermes relayer not the commander")
}
func (c commander) AddChainConfiguration(containerFilePath, homeDir string) []string {
panic("add chain configuration implemented in hermes relayer not the commander")
}
func (c commander) AddKey(chainID, keyName, coinType, homeDir string) []string {
panic("add key implemented in hermes relayer not the commander")
}
func (c commander) CreateChannel(pathName string, opts ibc.CreateChannelOptions, homeDir string) []string {
panic("create channel implemented in hermes relayer not the commander")
}
func (c commander) CreateClient(srcChainID, dstChainID, pathName string, opts ibc.CreateClientOptions, homeDir string) []string {
panic("create client implemented in hermes relayer not the commander")
}
func (c commander) CreateClients(pathName string, opts ibc.CreateClientOptions, homeDir string) []string {
panic("create clients implemented in hermes relayer not the commander")
}
func (c commander) CreateConnections(pathName string, homeDir string) []string {
panic("create connections implemented in hermes relayer not the commander")
}
func (c commander) Flush(pathName, channelID, homeDir string) []string {
panic("flush implemented in hermes relayer not the commander")
}
func (c commander) ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string) ([]byte, error) {
panic("config content implemented in hermes relayer not the commander")
}
func (c commander) ParseAddKeyOutput(stdout, stderr string) (ibc.Wallet, error) {
panic("add key implemented in Hermes Relayer")
}
// ParseRestoreKeyOutput extracts the address from the hermes output.
func (c commander) ParseRestoreKeyOutput(stdout, stderr string) string {
panic("implemented in Hermes Relayer")
}