-
Notifications
You must be signed in to change notification settings - Fork 70
/
config.go
116 lines (93 loc) · 3.82 KB
/
config.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
package interchain
import (
"errors"
"os"
"path/filepath"
"time"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
interchainda "github.com/dymensionxyz/dymint/types/pb/interchain_da"
)
type DAConfig struct {
ClientID string `mapstructure:"client_id" json:"client_id,omitempty"` // IBC client ID between the Hub and DA layer
ChainID string `mapstructure:"chain_id" json:"chain_id,omitempty"` // Chain ID of the DA layer
KeyringBackend string `mapstructure:"keyring_backend" json:"keyring_backend,omitempty"`
KeyringHomeDir string `mapstructure:"keyring_home_dir" json:"keyring_home_dir,omitempty"`
AddressPrefix string `mapstructure:"address_prefix" json:"address_prefix,omitempty"`
AccountName string `mapstructure:"account_name" json:"account_name,omitempty"`
NodeAddress string `mapstructure:"node_address" json:"node_address,omitempty"`
GasLimit uint64 `mapstructure:"gas_limit" json:"gas_limit,omitempty"`
GasPrices string `mapstructure:"gas_prices" json:"gas_prices,omitempty"`
GasAdjustment float64 `mapstructure:"gas_adjustment" json:"gas_adjustment,omitempty"`
GasFees string `mapstructure:"gas_fees" json:"gas_fees,omitempty"`
DAParams interchainda.Params `mapstructure:"da_params" json:"da_params"`
BatchAcceptanceTimeout time.Duration `mapstructure:"batch_acceptance_timeout" json:"batch_acceptance_timeout"`
BatchAcceptanceAttempts uint `mapstructure:"batch_acceptance_attempts" json:"batch_acceptance_attempts"`
RetryMinDelay time.Duration `mapstructure:"retry_min_delay" json:"retry_min_delay,omitempty"`
RetryMaxDelay time.Duration `mapstructure:"retry_min_delay" json:"retry_max_delay,omitempty"`
RetryAttempts uint `mapstructure:"retry_attempts" json:"retry_attempts,omitempty"`
}
func (c *DAConfig) Verify() error {
if c.ClientID == "" {
return errors.New("missing IBC client ID")
}
if c.ChainID == "" {
return errors.New("missing chain ID of the DA layer")
}
if c.KeyringBackend == "" {
return errors.New("missing keyring backend")
}
if c.KeyringHomeDir == "" {
return errors.New("missing keyring home dir")
}
if c.AddressPrefix == "" {
return errors.New("missing address prefix")
}
if c.AccountName == "" {
return errors.New("missing account name")
}
if c.NodeAddress == "" {
return errors.New("missing node address")
}
// GasLimit may be 0
if c.GasPrices == "" && c.GasFees == "" {
return errors.New("either gas prices or gas_prices are required")
}
if c.GasPrices != "" && c.GasFees != "" {
return errors.New("cannot provide both fees and gas prices")
}
// DAParams are set during Init
if c.RetryMinDelay.Nanoseconds() == 0 {
return errors.New("missing retry min delay")
}
if c.RetryMaxDelay.Nanoseconds() == 0 {
return errors.New("missing retry max delay")
}
if c.RetryAttempts == 0 {
return errors.New("missing retry attempts")
}
return nil
}
func DefaultDAConfig() DAConfig {
home, _ := os.UserHomeDir()
keyringHomeDir := filepath.Join(home, ".simapp")
return DAConfig{
ClientID: "dym-interchain",
ChainID: "my-test-chain",
KeyringBackend: keyring.BackendTest,
KeyringHomeDir: keyringHomeDir,
AddressPrefix: sdk.Bech32MainPrefix,
AccountName: "sequencer",
NodeAddress: "http://127.0.0.1:26657",
GasLimit: 0,
GasPrices: "10stake",
GasAdjustment: 1.1,
GasFees: "",
DAParams: interchainda.Params{},
BatchAcceptanceTimeout: 5 * time.Second,
BatchAcceptanceAttempts: 10,
RetryMinDelay: 100 * time.Millisecond,
RetryMaxDelay: 2 * time.Second,
RetryAttempts: 10,
}
}