-
Notifications
You must be signed in to change notification settings - Fork 532
/
plugin-stargate.go
143 lines (128 loc) · 3.95 KB
/
plugin-stargate.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
package chain
import (
"context"
"os"
"path/filepath"
"github.com/pelletier/go-toml"
"github.com/tendermint/starport/starport/chainconfig"
"github.com/tendermint/starport/starport/pkg/chaincmd"
chaincmdrunner "github.com/tendermint/starport/starport/pkg/chaincmd/runner"
"github.com/tendermint/starport/starport/pkg/cosmosver"
"github.com/tendermint/starport/starport/pkg/xurl"
)
type stargatePlugin struct {
app App
}
func newStargatePlugin(app App) *stargatePlugin {
return &stargatePlugin{
app: app,
}
}
func (p *stargatePlugin) Name() string {
return "Stargate"
}
func (p *stargatePlugin) Gentx(ctx context.Context, runner chaincmdrunner.Runner, v Validator) (path string, err error) {
return runner.Gentx(
ctx,
v.Name,
v.StakingAmount,
chaincmd.GentxWithMoniker(v.Moniker),
chaincmd.GentxWithCommissionRate(v.CommissionRate),
chaincmd.GentxWithCommissionMaxRate(v.CommissionMaxRate),
chaincmd.GentxWithCommissionMaxChangeRate(v.CommissionMaxChangeRate),
chaincmd.GentxWithMinSelfDelegation(v.MinSelfDelegation),
chaincmd.GentxWithGasPrices(v.GasPrices),
chaincmd.GentxWithDetails(v.Details),
chaincmd.GentxWithIdentity(v.Identity),
chaincmd.GentxWithWebsite(v.Website),
chaincmd.GentxWithSecurityContact(v.SecurityContact),
)
}
func (p *stargatePlugin) Configure(homePath string, conf chainconfig.Config) error {
if err := p.appTOML(homePath, conf); err != nil {
return err
}
if err := p.clientTOML(homePath); err != nil {
return err
}
return p.configTOML(homePath, conf)
}
func (p *stargatePlugin) appTOML(homePath string, conf chainconfig.Config) error {
// TODO find a better way in order to not delete comments in the toml.yml
path := filepath.Join(homePath, "config/app.toml")
config, err := toml.LoadFile(path)
if err != nil {
return err
}
config.Set("api.enable", true)
config.Set("api.enabled-unsafe-cors", true)
config.Set("rpc.cors_allowed_origins", []string{"*"})
config.Set("api.address", xurl.TCP(conf.Host.API))
config.Set("grpc.address", conf.Host.GRPC)
config.Set("grpc-web.address", conf.Host.GRPCWeb)
file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer file.Close()
_, err = config.WriteTo(file)
return err
}
func (p *stargatePlugin) configTOML(homePath string, conf chainconfig.Config) error {
// TODO find a better way in order to not delete comments in the toml.yml
path := filepath.Join(homePath, "config/config.toml")
config, err := toml.LoadFile(path)
if err != nil {
return err
}
config.Set("rpc.cors_allowed_origins", []string{"*"})
config.Set("consensus.timeout_commit", "1s")
config.Set("consensus.timeout_propose", "1s")
config.Set("rpc.laddr", xurl.TCP(conf.Host.RPC))
config.Set("p2p.laddr", xurl.TCP(conf.Host.P2P))
config.Set("rpc.pprof_laddr", conf.Host.Prof)
file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer file.Close()
_, err = config.WriteTo(file)
return err
}
func (p *stargatePlugin) clientTOML(homePath string) error {
path := filepath.Join(homePath, "config/client.toml")
config, err := toml.LoadFile(path)
if os.IsNotExist(err) {
return nil
}
if err != nil {
return err
}
config.Set("keyring-backend", "test")
config.Set("broadcast-mode", "block")
file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer file.Close()
_, err = config.WriteTo(file)
return err
}
func (p *stargatePlugin) Start(ctx context.Context, runner chaincmdrunner.Runner, conf chainconfig.Config) error {
err := runner.Start(ctx,
"--pruning",
"nothing",
"--grpc.address",
conf.Host.GRPC,
)
return &CannotStartAppError{p.app.Name, err}
}
func (p *stargatePlugin) Home() string {
return stargateHome(p.app)
}
func stargateHome(app App) string {
home, _ := os.UserHomeDir()
return filepath.Join(home, "."+app.Name)
}
func (p *stargatePlugin) Version() cosmosver.Family { return cosmosver.Stargate }
func (p *stargatePlugin) SupportsIBC() bool { return true }