@@ -739,7 +739,7 @@ func initializeApp(state *RunL1NodeState) tea.Cmd {
739
739
url = state .initiadEndpoint
740
740
case string (Mainnet ), string (Testnet ):
741
741
var result map [string ]interface {}
742
- err = utils .MakeGetRequest (strings .ToLower (state .network ), "lcd" , "/cosmos/base/tendermint/v1beta1/node_info" , nil , & result )
742
+ err = utils .MakeGetRequestUsingConfig (strings .ToLower (state .network ), "lcd" , "/cosmos/base/tendermint/v1beta1/node_info" , nil , & result )
743
743
if err != nil {
744
744
panic (err )
745
745
}
@@ -1016,6 +1016,7 @@ func (m *ExistingDataReplaceSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
1016
1016
m .state .replaceExistingData = false
1017
1017
return m , tea .Quit
1018
1018
case ReplaceData :
1019
+ // TODO: comet unsafe-reset-all here too
1019
1020
m .state .replaceExistingData = true
1020
1021
switch m .state .syncMethod {
1021
1022
case string (Snapshot ):
@@ -1074,7 +1075,6 @@ func (m *SnapshotEndpointInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
1074
1075
}
1075
1076
1076
1077
func (m * SnapshotEndpointInput ) View () string {
1077
- // TODO: Correctly render terminal output
1078
1078
view := m .state .weave .Render () + styles .RenderPrompt (m .GetQuestion (), []string {"snapshot url" }, styles .Question )
1079
1079
if m .err != nil {
1080
1080
return view + "\n " + m .TextInput .ViewErr (m .err )
@@ -1086,6 +1086,7 @@ type StateSyncEndpointInput struct {
1086
1086
utils.TextInput
1087
1087
state * RunL1NodeState
1088
1088
question string
1089
+ err error
1089
1090
}
1090
1091
1091
1092
func NewStateSyncEndpointInput (state * RunL1NodeState ) * StateSyncEndpointInput {
@@ -1109,16 +1110,20 @@ func (m *StateSyncEndpointInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
1109
1110
if done {
1110
1111
m .state .stateSyncEndpoint = input .Text
1111
1112
m .state .weave .PushPreviousResponse (styles .RenderPreviousResponse (styles .DotsSeparator , m .GetQuestion (), []string {"state sync RPC" }, input .Text ))
1112
- // TODO: Continue
1113
- return m , tea . Quit
1113
+ newLoader := NewStateSyncSetupLoading ( m . state )
1114
+ return newLoader , newLoader . Init ()
1114
1115
}
1115
1116
m .TextInput = input
1116
1117
return m , cmd
1117
1118
}
1118
1119
1119
1120
func (m * StateSyncEndpointInput ) View () string {
1120
1121
// TODO: Correctly render terminal output
1121
- return m .state .weave .Render () + styles .RenderPrompt (m .GetQuestion (), []string {"state sync RPC" }, styles .Question ) + m .TextInput .View ()
1122
+ view := m .state .weave .Render () + styles .RenderPrompt (m .GetQuestion (), []string {"state sync RPC" }, styles .Question )
1123
+ if m .err != nil {
1124
+ return view + "\n " + m .TextInput .ViewErr (m .err )
1125
+ }
1126
+ return view + m .TextInput .View ()
1122
1127
}
1123
1128
1124
1129
type SnapshotDownloadLoading struct {
@@ -1231,3 +1236,75 @@ func snapshotExtractor() tea.Cmd {
1231
1236
return utils.EndLoading {}
1232
1237
}
1233
1238
}
1239
+
1240
+ type StateSyncSetupLoading struct {
1241
+ utils.Loading
1242
+ state * RunL1NodeState
1243
+ }
1244
+
1245
+ func NewStateSyncSetupLoading (state * RunL1NodeState ) * StateSyncSetupLoading {
1246
+ return & StateSyncSetupLoading {
1247
+ Loading : utils .NewLoading ("Setting up State Sync..." , setupStateSync (state )),
1248
+ state : state ,
1249
+ }
1250
+ }
1251
+
1252
+ func (m * StateSyncSetupLoading ) Init () tea.Cmd {
1253
+ return m .Loading .Init ()
1254
+ }
1255
+
1256
+ func (m * StateSyncSetupLoading ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
1257
+ loader , cmd := m .Loading .Update (msg )
1258
+ m .Loading = loader
1259
+ switch msg := msg .(type ) {
1260
+ case utils.ErrorLoading :
1261
+ m .state .weave .PopPreviousResponse ()
1262
+ m .state .weave .PopPreviousResponse ()
1263
+ model := NewStateSyncEndpointInput (m .state )
1264
+ model .err = msg .Err
1265
+ return model , cmd
1266
+ }
1267
+
1268
+ if m .Loading .Completing {
1269
+ m .state .weave .PushPreviousResponse (styles .RenderPreviousResponse (styles .NoSeparator , fmt .Sprintf ("Snapshot setup successfully." ), []string {}, "" ))
1270
+ return m , tea .Quit
1271
+ }
1272
+ return m , cmd
1273
+ }
1274
+
1275
+ func (m * StateSyncSetupLoading ) View () string {
1276
+ if m .Completing {
1277
+ return m .state .weave .Render ()
1278
+ }
1279
+ return m .state .weave .Render () + m .Loading .View ()
1280
+ }
1281
+
1282
+ func setupStateSync (state * RunL1NodeState ) tea.Cmd {
1283
+ return func () tea.Msg {
1284
+ userHome , err := os .UserHomeDir ()
1285
+ if err != nil {
1286
+ return utils.ErrorLoading {Err : fmt .Errorf ("[error] Failed to get user home: %v" , err )}
1287
+ }
1288
+
1289
+ stateSyncInfo , err := utils .GetStateSyncInfo (state .stateSyncEndpoint )
1290
+ if err != nil {
1291
+ return utils.ErrorLoading {Err : fmt .Errorf ("[error] Failed to get state sync info: %v" , err )}
1292
+ }
1293
+
1294
+ initiaConfigPath := filepath .Join (userHome , utils .InitiaConfigDirectory )
1295
+ if err = utils .UpdateTomlValue (filepath .Join (initiaConfigPath , "config.toml" ), "statesync.enable" , "true" ); err != nil {
1296
+ return utils.ErrorLoading {Err : fmt .Errorf ("[error] Failed to setup state sync enable: %v" , err )}
1297
+ }
1298
+ if err = utils .UpdateTomlValue (filepath .Join (initiaConfigPath , "config.toml" ), "statesync.rpc_servers" , fmt .Sprintf ("%[1]s,%[1]s" , state .stateSyncEndpoint )); err != nil {
1299
+ return utils.ErrorLoading {Err : fmt .Errorf ("[error] Failed to setup state sync rpc_servers: %v" , err )}
1300
+ }
1301
+ if err = utils .UpdateTomlValue (filepath .Join (initiaConfigPath , "config.toml" ), "statesync.trust_height" , fmt .Sprintf ("%d" , stateSyncInfo .TrustHeight )); err != nil {
1302
+ return utils.ErrorLoading {Err : fmt .Errorf ("[error] Failed to setup state sync trust_height: %v" , err )}
1303
+ }
1304
+ if err = utils .UpdateTomlValue (filepath .Join (initiaConfigPath , "config.toml" ), "statesync.trust_hash" , fmt .Sprintf ("%s" , stateSyncInfo .TrustHash )); err != nil {
1305
+ return utils.ErrorLoading {Err : fmt .Errorf ("[error] Failed to setup state sync trust_hash: %v" , err )}
1306
+ }
1307
+
1308
+ return utils.EndLoading {}
1309
+ }
1310
+ }
0 commit comments