From 71ae1fe3ea5266546347d5c41e3094cc32208ff1 Mon Sep 17 00:00:00 2001 From: batphonghan Date: Sat, 14 Oct 2023 00:35:24 +0700 Subject: [PATCH 1/3] Septate URL checkpoint --- wizard/config/nav.go | 6 +- .../ConsensusClientCheckpointSyncMainnet.go | 112 ++++++++++++++++++ ...=> ConsensusClientCheckpointSyncPrater.go} | 18 +-- .../ConsensusClientDopelgangerProtection.go | 6 +- wizard/pages/ConsensusClientGraffiti.go | 7 +- wizard/pages/init.go | 3 +- wizard/pages/utils.go | 10 ++ wizard/state/global.go | 4 + 8 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 wizard/pages/ConsensusClientCheckpointSyncMainnet.go rename wizard/pages/{ConsensusClientCheckpointSync.go => ConsensusClientCheckpointSyncPrater.go} (82%) diff --git a/wizard/config/nav.go b/wizard/config/nav.go index 3764b70..28b9607 100644 --- a/wizard/config/nav.go +++ b/wizard/config/nav.go @@ -13,7 +13,8 @@ var PageID = struct { ConsensusClientExternalSelectedTeku string ConsensusClientSelection string ConsensusClientGraffiti string - ConsensusClientCheckpointSync string + ConsensusClientCheckpointSyncMainnet string + ConsensusClientCheckpointSyncPrater string ConsensusClientDopelgangerProtection string FallbackClients string FallbackClientsPrysm string @@ -39,7 +40,8 @@ var PageID = struct { ConsensusClientExternalSelectedLodestar: "consensus_client_external_selected_lodestar", ConsensusClientSelection: "consensus_client_selection", ConsensusClientGraffiti: "consensus_client_graffiti", - ConsensusClientCheckpointSync: "consensus_client_checkpoint_sync", + ConsensusClientCheckpointSyncMainnet: "consensus_client_checkpoint_sync_mainnet", + ConsensusClientCheckpointSyncPrater: "consensus_client_checkpoint_sync_prater", ConsensusClientDopelgangerProtection: "consensus_client_dopelganger_protection", FallbackClients: "fallback_clients", FallbackClientsPrysm: "fallback_clients_prysm", diff --git a/wizard/pages/ConsensusClientCheckpointSyncMainnet.go b/wizard/pages/ConsensusClientCheckpointSyncMainnet.go new file mode 100644 index 0000000..27196c1 --- /dev/null +++ b/wizard/pages/ConsensusClientCheckpointSyncMainnet.go @@ -0,0 +1,112 @@ +package pages + +import ( + "strings" + + "github.com/stader-labs/ethcli-ui/wizard/components" + "github.com/stader-labs/ethcli-ui/wizard/config" + "github.com/stader-labs/ethcli-ui/wizard/state" + "github.com/stader-labs/ethcli-ui/wizard/utils" + + "github.com/gdamore/tcell/v2" + "github.com/rivo/tview" +) + +type ConsensusClientCheckpointSyncMainnet struct { + *PageType + firstElement tview.Primitive +} + +func (p *ConsensusClientCheckpointSyncMainnet) Page() tview.Primitive { + form := components.Form(). + AddInputField("Checkpoint URL", state.ConsensusClient.CheckpointUrlMainnet, 0, nil, trimWrap(func(text string) { + state.ConsensusClient.CheckpointUrlMainnet = text + state.ConsensusClient.CheckpointUrl = text + })). + AddButton("Next", func() { + p.onSumit() + }) + + formHeight := 3 + 2 + + p.firstElement = form + + bodyText := `Good news - Your client is equipped with the Checkpoint +Sync feature, which can significantly reduce the time and +effort required to sync from scratch. With this powerful +functionality, your client can instantly copy the most +recent state from a trusted Consensus client that you +specify. + +If you wish to activate Checkpoint Sync, kindly provide +the provider URL. However, if it's not something you're +interested in, feel free to leave it blank.` + + bodyTextHeight := strings.Count(bodyText, "\n") + 1 + + formWrap := tview.NewFlex(). + SetDirection(tview.FlexColumn). + AddItem(nil, 0, 1, false). + AddItem( + tview.NewFlex(). + SetDirection(tview.FlexRow). + AddItem(nil, 0, 1, false). + AddItem(utils.CenterText(bodyText), bodyTextHeight, 1, false). + AddItem(nil, 1, 1, false). + AddItem(form, formHeight, 1, false). + AddItem(nil, 0, 1, false), + 60, 1, false, + ). + AddItem(nil, 0, 1, false) + formWrapHeight := formHeight + bodyTextHeight + + content := tview.NewFlex(). + SetDirection(tview.FlexRow). + AddItem(nil, 0, 1, false). + AddItem(formWrap, formWrapHeight, 1, false). + AddItem(nil, 0, 1, false) + + body := tview.NewFlex(). + SetDirection(tview.FlexColumn). + AddItem( + components.PageLeftNav( + config.ConsensusClient.Stages, + config.ConsensusClient.Stage.CheckpointSync.Name, + ), + 40, 1, false, + ). + AddItem(content, 0, 1, false) + + return tview.NewFlex(). + SetDirection(tview.FlexRow). + AddItem(components.Header(Version), 3, 1, false). + AddItem(components.Nav(config.TopNav.ConsensusClient), 3, 1, false). + AddItem(body, 0, 1, false). + AddItem(components.Footer(p.App), 5, 1, false) +} + +func (p *ConsensusClientCheckpointSyncMainnet) onSumit() { + log.Infof("onSumit: [%s]", config.PageID.ConsensusClientCheckpointSyncMainnet) + + ChangePage(config.PageID.ConsensusClientDopelgangerProtection) +} + +func (p *ConsensusClientCheckpointSyncMainnet) GoBack() { + ChangePage(config.PageID.ConsensusClientGraffiti) +} + +func (p *ConsensusClientCheckpointSyncMainnet) HandleEvents(event *tcell.EventKey) *tcell.EventKey { + var key = event.Key() + + if key == tcell.KeyEsc { + p.GoBack() + } + + return event +} + +func (p *ConsensusClientCheckpointSyncMainnet) GetFirstElement() tview.Primitive { + fb := p.firstElement + log.Infof("%s GetFirstElement", p.ID) + return fb +} diff --git a/wizard/pages/ConsensusClientCheckpointSync.go b/wizard/pages/ConsensusClientCheckpointSyncPrater.go similarity index 82% rename from wizard/pages/ConsensusClientCheckpointSync.go rename to wizard/pages/ConsensusClientCheckpointSyncPrater.go index b521ed9..304f3d1 100644 --- a/wizard/pages/ConsensusClientCheckpointSync.go +++ b/wizard/pages/ConsensusClientCheckpointSyncPrater.go @@ -12,14 +12,15 @@ import ( "github.com/rivo/tview" ) -type ConsensusClientCheckpointSync struct { +type ConsensusClientCheckpointSyncPrater struct { *PageType firstElement tview.Primitive } -func (p *ConsensusClientCheckpointSync) Page() tview.Primitive { +func (p *ConsensusClientCheckpointSyncPrater) Page() tview.Primitive { form := components.Form(). - AddInputField("Checkpoint URL", state.ConsensusClient.CheckpointUrl, 0, nil, trimWrap(func(text string) { + AddInputField("Checkpoint URL", state.ConsensusClient.CheckpointUrlPrater, 0, nil, trimWrap(func(text string) { + state.ConsensusClient.CheckpointUrlPrater = text state.ConsensusClient.CheckpointUrl = text })). AddButton("Next", func() { @@ -84,16 +85,17 @@ interested in, feel free to leave it blank.` AddItem(components.Footer(p.App), 5, 1, false) } -func (p *ConsensusClientCheckpointSync) onSumit() { - log.Infof("onSumit: [%s]", config.PageID.ConsensusClientCheckpointSync) +func (p *ConsensusClientCheckpointSyncPrater) onSumit() { + log.Infof("onSumit: [%s]", config.PageID.ConsensusClientCheckpointSyncPrater) + ChangePage(config.PageID.ConsensusClientDopelgangerProtection) } -func (p *ConsensusClientCheckpointSync) GoBack() { +func (p *ConsensusClientCheckpointSyncPrater) GoBack() { ChangePage(config.PageID.ConsensusClientGraffiti) } -func (p *ConsensusClientCheckpointSync) HandleEvents(event *tcell.EventKey) *tcell.EventKey { +func (p *ConsensusClientCheckpointSyncPrater) HandleEvents(event *tcell.EventKey) *tcell.EventKey { var key = event.Key() if key == tcell.KeyEsc { @@ -103,7 +105,7 @@ func (p *ConsensusClientCheckpointSync) HandleEvents(event *tcell.EventKey) *tce return event } -func (p *ConsensusClientCheckpointSync) GetFirstElement() tview.Primitive { +func (p *ConsensusClientCheckpointSyncPrater) GetFirstElement() tview.Primitive { fb := p.firstElement log.Infof("%s GetFirstElement", p.ID) return fb diff --git a/wizard/pages/ConsensusClientDopelgangerProtection.go b/wizard/pages/ConsensusClientDopelgangerProtection.go index b310d6f..3d73ca2 100644 --- a/wizard/pages/ConsensusClientDopelgangerProtection.go +++ b/wizard/pages/ConsensusClientDopelgangerProtection.go @@ -71,7 +71,11 @@ func (p *ConsensusClientDopelgangerProtection) selectNextOption() { } func (p *ConsensusClientDopelgangerProtection) GoBack() { - ChangePage(config.PageID.ConsensusClientCheckpointSync) + if state.Network.SelectedOption == "mainnet" { + ChangePage(config.PageID.ConsensusClientCheckpointSyncMainnet) + } else { + ChangePage(config.PageID.ConsensusClientCheckpointSyncPrater) + } } func (p *ConsensusClientDopelgangerProtection) HandleEvents(event *tcell.EventKey) *tcell.EventKey { diff --git a/wizard/pages/ConsensusClientGraffiti.go b/wizard/pages/ConsensusClientGraffiti.go index 7269659..2c070f4 100644 --- a/wizard/pages/ConsensusClientGraffiti.go +++ b/wizard/pages/ConsensusClientGraffiti.go @@ -91,7 +91,12 @@ leave it blank.` func (p *ConsensusClientGraffiti) onSumit() { log.Infof("onSumit: [%s]", config.PageID.ConsensusClientGraffiti) - ChangePage(config.PageID.ConsensusClientCheckpointSync) + + if state.Network.SelectedOption == "mainnet" { + ChangePage(config.PageID.ConsensusClientCheckpointSyncMainnet) + } else { + ChangePage(config.PageID.ConsensusClientCheckpointSyncPrater) + } } func (p *ConsensusClientGraffiti) GoBack() { diff --git a/wizard/pages/init.go b/wizard/pages/init.go index 014ffc8..a994928 100644 --- a/wizard/pages/init.go +++ b/wizard/pages/init.go @@ -29,7 +29,8 @@ func Setup(app *tview.Application) { All[config.PageID.ConsensusClientExternalSelectedLodestar] = &ConsensusClientExternalSelectedLodestar{PageType: &PageType{}} All[config.PageID.ConsensusClientSelection] = &ConsensusClientSelection{PageType: &PageType{}} All[config.PageID.ConsensusClientGraffiti] = &ConsensusClientGraffiti{PageType: &PageType{}} - All[config.PageID.ConsensusClientCheckpointSync] = &ConsensusClientCheckpointSync{PageType: &PageType{}} + All[config.PageID.ConsensusClientCheckpointSyncMainnet] = &ConsensusClientCheckpointSyncMainnet{PageType: &PageType{}} + All[config.PageID.ConsensusClientCheckpointSyncPrater] = &ConsensusClientCheckpointSyncPrater{PageType: &PageType{}} All[config.PageID.ConsensusClientDopelgangerProtection] = &ConsensusClientDopelgangerProtection{PageType: &PageType{}} All[config.PageID.FallbackClients] = &FallbackClients{PageType: &PageType{}} All[config.PageID.FallbackClientsPrysm] = &FallbackClientsPrysm{PageType: &PageType{}} diff --git a/wizard/pages/utils.go b/wizard/pages/utils.go index 78f54de..2535d22 100644 --- a/wizard/pages/utils.go +++ b/wizard/pages/utils.go @@ -107,6 +107,8 @@ type ConsensusClientSettingsType struct { ExternalSelection string `json:"externalSelection"` Graffit string `json:"graffit"` CheckpointUrl string `json:"checkpointUrl"` + CheckpointUrlMainnet string `json:"checkpointUrlMainnet"` + CheckpointUrlPrater string `json:"checkpointUrlPrater"` DoppelgangerProtection string `json:"doppelgangerProtection"` External ConsensusClientExternalType `json:"external"` } @@ -172,7 +174,9 @@ type SettingsType struct { FallbackClients FallbackClientsSettingsType `json:"fallbackClients"` } +// funcs func GetSettings() SettingsType { + settings := SettingsType{ // Confirmed: state.Confirmed, // OpenConfigurationUI: state.OpenConfigurationUI, @@ -190,6 +194,8 @@ func GetSettings() SettingsType { ExternalSelection: state.ConsensusClientExternalSelection.SelectedOption, Graffit: state.ConsensusClient.Graffiti, CheckpointUrl: state.ConsensusClient.CheckpointUrl, + CheckpointUrlMainnet: state.ConsensusClient.CheckpointUrlMainnet, + CheckpointUrlPrater: state.ConsensusClient.CheckpointUrlPrater, DoppelgangerProtection: state.ConsensusClient.DopelgangerProtectionSelectedOption, External: ConsensusClientExternalType{ Lighthouse: ConsensusClientExternalSelectedLighthouseType{ @@ -260,7 +266,11 @@ func SetSettings(settings SettingsType) { state.ConsensusClient.SelectionSelectedOption = settings.ConsensusClient.Selection state.ConsensusClient.Graffiti = settings.ConsensusClient.Graffit + state.ConsensusClient.CheckpointUrl = settings.ConsensusClient.CheckpointUrl + state.ConsensusClient.CheckpointUrlMainnet = settings.ConsensusClient.CheckpointUrlMainnet + state.ConsensusClient.CheckpointUrlPrater = settings.ConsensusClient.CheckpointUrlPrater + state.ConsensusClient.DopelgangerProtectionSelectedOption = settings.ConsensusClient.DoppelgangerProtection state.ConsensusClientExternalSelection.SelectedOption = settings.ConsensusClient.ExternalSelection diff --git a/wizard/state/global.go b/wizard/state/global.go index c86c672..b89e693 100644 --- a/wizard/state/global.go +++ b/wizard/state/global.go @@ -56,12 +56,16 @@ var ( DopelgangerProtectionSelectedOption string Graffiti string CheckpointUrl string + CheckpointUrlMainnet string + CheckpointUrlPrater string }{ SelectionSelectedOption: config.ConsensusClient.Stage.Selection.Option.SystemRecommended, SelectedStage: config.ConsensusClient.Stage.Selection.Name, DopelgangerProtectionSelectedOption: config.ConsensusClient.Stage.DopelgangerProtection.Option.Yes, Graffiti: "", CheckpointUrl: "", + CheckpointUrlMainnet: "", + CheckpointUrlPrater: "", } ConsensusClientExternalSelectedLighthouse = struct { From a80dbbdcc86b33de84352f70612a19f5ce7d691c Mon Sep 17 00:00:00 2001 From: batphonghan Date: Sun, 15 Oct 2023 11:52:09 +0700 Subject: [PATCH 2/3] Update ver --- configuration/go.mod | 2 +- wizard/go.mod | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/configuration/go.mod b/configuration/go.mod index 48f8ee0..f6d40a3 100644 --- a/configuration/go.mod +++ b/configuration/go.mod @@ -6,7 +6,6 @@ require ( github.com/gdamore/tcell/v2 v2.6.0 github.com/rivo/tview v0.0.0-20230325211341-281d14d896d7 go.uber.org/zap v1.24.0 - golang.org/x/term v0.5.0 ) require ( @@ -17,6 +16,7 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect golang.org/x/sys v0.5.0 // indirect + golang.org/x/term v0.5.0 // indirect golang.org/x/text v0.7.0 // indirect ) diff --git a/wizard/go.mod b/wizard/go.mod index 05cb70e..6642c26 100644 --- a/wizard/go.mod +++ b/wizard/go.mod @@ -6,8 +6,8 @@ require ( github.com/gdamore/tcell/v2 v2.6.0 github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 github.com/rivo/tview v0.0.0-20230406072732-e22ce9588bb4 + github.com/rivo/tview v0.0.0-20230406072732-e22ce9588bb4 go.uber.org/zap v1.24.0 - golang.org/x/term v0.7.0 ) require ( @@ -18,6 +18,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/sys v0.7.0 // indirect + golang.org/x/term v0.7.0 // indirect golang.org/x/text v0.9.0 // indirect ) From 948d4da56e5a7931533fb544c686d6b832f2b436 Mon Sep 17 00:00:00 2001 From: batphonghan Date: Sun, 15 Oct 2023 13:50:42 +0700 Subject: [PATCH 3/3] Put ack direct deps --- configuration/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configuration/go.mod b/configuration/go.mod index f6d40a3..48f8ee0 100644 --- a/configuration/go.mod +++ b/configuration/go.mod @@ -6,6 +6,7 @@ require ( github.com/gdamore/tcell/v2 v2.6.0 github.com/rivo/tview v0.0.0-20230325211341-281d14d896d7 go.uber.org/zap v1.24.0 + golang.org/x/term v0.5.0 ) require ( @@ -16,7 +17,6 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect golang.org/x/sys v0.5.0 // indirect - golang.org/x/term v0.5.0 // indirect golang.org/x/text v0.7.0 // indirect )