/
types.go
203 lines (168 loc) · 5.61 KB
/
types.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
package ibc
import (
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/types"
ibcexported "github.com/cosmos/ibc-go/v5/modules/core/03-connection/types"
)
// ChainConfig defines the chain parameters requires to run an ibctest testnet for a chain.
type ChainConfig struct {
// Chain type, e.g. cosmos.
Type string `yaml:"type"`
// Chain name, e.g. cosmoshub.
Name string `yaml:"name"`
// Chain ID, e.g. cosmoshub-4
ChainID string `yaml:"chain-id"`
// Docker images required for running chain nodes.
Images []DockerImage `yaml:"images"`
// Binary to execute for the chain node daemon.
Bin string `yaml:"bin"`
// Bech32 prefix for chain addresses, e.g. cosmos.
Bech32Prefix string `yaml:"bech32-prefix"`
// Denomination of native currency, e.g. uatom.
Denom string `yaml:"denom"`
// Minimum gas prices for sending transactions, in native currency denom.
GasPrices string `yaml:"gas-prices"`
// Adjustment multiplier for gas fees.
GasAdjustment float64 `yaml:"gas-adjustment"`
// Trusting period of the chain.
TrustingPeriod string `yaml:"trusting-period"`
// Do not use docker host mount.
NoHostMount bool `yaml:"no-host-mount"`
// When provided, genesis file contents will be altered before sharing for genesis.
ModifyGenesis func(ChainConfig, []byte) ([]byte, error)
// Override config parameters for files at filepath.
ConfigFileOverrides map[string]any
// Non-nil will override the encoding config, used for cosmos chains only.
EncodingConfig *simappparams.EncodingConfig
}
func (c ChainConfig) Clone() ChainConfig {
x := c
images := make([]DockerImage, len(c.Images))
copy(images, c.Images)
x.Images = images
return x
}
func (c ChainConfig) MergeChainSpecConfig(other ChainConfig) ChainConfig {
// Make several in-place modifications to c,
// which is a value, not a reference,
// and return the updated copy.
if other.Type != "" {
c.Type = other.Type
}
// Skip Name, as that is held in ChainSpec.ChainName.
if other.ChainID != "" {
c.ChainID = other.ChainID
}
if len(other.Images) > 0 {
c.Images = append([]DockerImage(nil), other.Images...)
}
if other.Bin != "" {
c.Bin = other.Bin
}
if other.Bech32Prefix != "" {
c.Bech32Prefix = other.Bech32Prefix
}
if other.Denom != "" {
c.Denom = other.Denom
}
if other.GasPrices != "" {
c.GasPrices = other.GasPrices
}
if other.GasAdjustment > 0 && c.GasAdjustment == 0 {
c.GasAdjustment = other.GasAdjustment
}
if other.TrustingPeriod != "" {
c.TrustingPeriod = other.TrustingPeriod
}
// Skip NoHostMount so that false can be distinguished.
if other.ModifyGenesis != nil {
c.ModifyGenesis = other.ModifyGenesis
}
if other.ConfigFileOverrides != nil {
c.ConfigFileOverrides = other.ConfigFileOverrides
}
if other.EncodingConfig != nil {
c.EncodingConfig = other.EncodingConfig
}
return c
}
// IsFullyConfigured reports whether all required fields have been set on c.
// It is possible for some fields, such as GasAdjustment and NoHostMount,
// to be their respective zero values and for IsFullyConfigured to still report true.
func (c ChainConfig) IsFullyConfigured() bool {
return c.Type != "" &&
c.Name != "" &&
c.ChainID != "" &&
len(c.Images) > 0 &&
c.Bin != "" &&
c.Bech32Prefix != "" &&
c.Denom != "" &&
c.GasPrices != "" &&
c.TrustingPeriod != ""
}
type DockerImage struct {
Repository string `yaml:"repository"`
Version string `yaml:"version"`
UidGid string `yaml:"uid-gid"`
}
// Ref returns the reference to use when e.g. creating a container.
func (i DockerImage) Ref() string {
if i.Version == "" {
return i.Repository + ":latest"
}
return i.Repository + ":" + i.Version
}
type WalletAmount struct {
Address string
Denom string
Amount int64
}
type IBCTimeout struct {
NanoSeconds uint64
Height uint64
}
type ChannelCounterparty struct {
PortID string `json:"port_id"`
ChannelID string `json:"channel_id"`
}
type ChannelOutput struct {
State string `json:"state"`
Ordering string `json:"ordering"`
Counterparty ChannelCounterparty `json:"counterparty"`
ConnectionHops []string `json:"connection_hops"`
Version string `json:"version"`
PortID string `json:"port_id"`
ChannelID string `json:"channel_id"`
}
// ConnectionOutput represents the IBC connection information queried from a chain's state for a particular connection.
type ConnectionOutput struct {
ID string `json:"id,omitempty" yaml:"id"`
ClientID string `json:"client_id,omitempty" yaml:"client_id"`
Versions []*ibcexported.Version `json:"versions,omitempty" yaml:"versions"`
State string `json:"state,omitempty" yaml:"state"`
Counterparty *ibcexported.Counterparty `json:"counterparty" yaml:"counterparty"`
DelayPeriod string `json:"delay_period,omitempty" yaml:"delay_period"`
}
type ConnectionOutputs []*ConnectionOutput
type Wallet struct {
Mnemonic string `json:"mnemonic"`
Address string `json:"address"`
KeyName string
}
func (w *Wallet) GetKeyName() string {
return w.KeyName
}
func (w *Wallet) Bech32Address(bech32Prefix string) string {
return types.MustBech32ifyAddressBytes(bech32Prefix, []byte(w.Address))
}
type RelayerImplementation int64
const (
CosmosRly RelayerImplementation = iota
Hermes
)
// ChannelFilter provides the means for either creating an allowlist or a denylist of channels on the src chain
// which will be used to narrow down the list of channels a user wants to relay on.
type ChannelFilter struct {
Rule string
ChannelList []string
}