Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions wizard/config/nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion wizard/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
)

Expand Down
112 changes: 112 additions & 0 deletions wizard/pages/ConsensusClientCheckpointSyncMainnet.go
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion wizard/pages/ConsensusClientDopelgangerProtection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion wizard/pages/ConsensusClientGraffiti.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion wizard/pages/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}}
Expand Down
10 changes: 10 additions & 0 deletions wizard/pages/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -172,7 +174,9 @@ type SettingsType struct {
FallbackClients FallbackClientsSettingsType `json:"fallbackClients"`
}

// funcs
func GetSettings() SettingsType {

settings := SettingsType{
// Confirmed: state.Confirmed,
// OpenConfigurationUI: state.OpenConfigurationUI,
Expand All @@ -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{
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions wizard/state/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down