diff --git a/pkg/app.go b/pkg/app.go index 0a91d61..91b7272 100644 --- a/pkg/app.go +++ b/pkg/app.go @@ -161,13 +161,13 @@ func (a *App) RefreshChainInfo() { chainInfo, err := a.Aggregator.GetChainInfo() if err != nil { a.Logger.Error().Err(err).Msg("Error getting chain validators") - a.State.SetChainInfoError(err) + a.State.SetStatusError(err) a.DisplayWrapper.SetState(a.State) return } - a.State.SetChainInfo(&chainInfo.Result) - a.State.SetChainInfoError(err) + a.State.SetNodeStatus(&chainInfo.Result) + a.State.SetStatusError(err) a.DisplayWrapper.SetState(a.State) } diff --git a/pkg/display/all_rounds_table.go b/pkg/display/all_rounds_table.go index a7f13aa..3d578cc 100644 --- a/pkg/display/all_rounds_table.go +++ b/pkg/display/all_rounds_table.go @@ -13,9 +13,10 @@ import ( type AllRoundsTableData struct { tview.TableContentReadOnly - Validators types.ValidatorsWithInfoAndAllRoundVotes - DisableEmojis bool - Transpose bool + Validators types.ValidatorsWithInfoAndAllRoundVotes + CurrentValidatorAddress string + DisableEmojis bool + Transpose bool cells [][]*tview.TableCell mutex sync.Mutex @@ -63,12 +64,20 @@ func (d *AllRoundsTableData) GetColumnCount() int { return len(d.cells[0]) } -func (d *AllRoundsTableData) SetValidators(validators types.ValidatorsWithInfoAndAllRoundVotes) { +func (d *AllRoundsTableData) SetValidators( + validators types.ValidatorsWithInfoAndAllRoundVotes, + statusResult *types.TendermintStatusResult, +) { if d.Validators.Equals(validators) { return } d.Validators = validators + + if statusResult != nil { + d.CurrentValidatorAddress = statusResult.ValidatorInfo.Address + } + d.redrawCells() } @@ -124,6 +133,10 @@ func (d *AllRoundsTableData) redrawCells() { cell.SetBackgroundColor(tcell.ColorForestGreen) } + if roundVote.Address == d.CurrentValidatorAddress { + cell.SetBackgroundColor(tcell.ColorMediumTurquoise) + } + d.cells[row][column] = cell } } diff --git a/pkg/display/last_round_table.go b/pkg/display/last_round_table.go index c652140..e26a438 100644 --- a/pkg/display/last_round_table.go +++ b/pkg/display/last_round_table.go @@ -12,11 +12,12 @@ import ( type LastRoundTableData struct { tview.TableContentReadOnly - Validators types.ValidatorsWithInfo - ConsensusError error - ColumnsCount int - DisableEmojis bool - Transpose bool + Validators types.ValidatorsWithInfo + CurrentValidatorAddress string + ConsensusError error + ColumnsCount int + DisableEmojis bool + Transpose bool cells [][]*tview.TableCell mutex sync.Mutex @@ -76,9 +77,18 @@ func (d *LastRoundTableData) GetColumnCount() int { return len(d.cells[0]) } -func (d *LastRoundTableData) SetValidators(validators types.ValidatorsWithInfo, consensusError error) { +func (d *LastRoundTableData) SetValidators( + validators types.ValidatorsWithInfo, + consensusError error, + statusResult *types.TendermintStatusResult, +) { d.Validators = validators d.ConsensusError = consensusError + + if statusResult != nil { + d.CurrentValidatorAddress = statusResult.ValidatorInfo.Address + } + d.redrawData() } @@ -125,6 +135,10 @@ func (d *LastRoundTableData) redrawData() { cell.SetBackgroundColor(tcell.ColorForestGreen) } + if index < len(d.Validators) && d.Validators[index].Validator.Address == d.CurrentValidatorAddress { + cell.SetBackgroundColor(tcell.ColorMediumTurquoise) + } + d.cells[row][column] = cell } } diff --git a/pkg/display/wrapper.go b/pkg/display/wrapper.go index 3ddc415..c0138e5 100644 --- a/pkg/display/wrapper.go +++ b/pkg/display/wrapper.go @@ -222,8 +222,15 @@ func (w *Wrapper) ToggleHelp() { } func (w *Wrapper) SetState(state *types.State) { - w.LastRoundTableData.SetValidators(state.GetValidatorsWithInfo(), state.ConsensusStateError) - w.AllRoundsTableData.SetValidators(state.GetValidatorsWithInfoAndAllRoundVotes()) + w.LastRoundTableData.SetValidators( + state.GetValidatorsWithInfo(), + state.ConsensusStateError, + state.NodeStatus, + ) + w.AllRoundsTableData.SetValidators( + state.GetValidatorsWithInfoAndAllRoundVotes(), + state.NodeStatus, + ) w.ConsensusInfoTextView.Clear() w.ChainInfoTextView.Clear() diff --git a/pkg/types/state.go b/pkg/types/state.go index 9705023..7d89561 100644 --- a/pkg/types/state.go +++ b/pkg/types/state.go @@ -14,7 +14,7 @@ type State struct { Validators *ValidatorsWithRoundVote ValidatorsWithAllRoundsVotes *ValidatorsWithAllRoundsVotes ChainValidators *ChainValidators - ChainInfo *TendermintStatusResult + NodeStatus *TendermintStatusResult StartTime time.Time Upgrade *Upgrade BlockTime time.Duration @@ -23,7 +23,7 @@ type State struct { ValidatorsError error ChainValidatorsError error UpgradePlanError error - ChainInfoError error + StatusError error } func NewState() *State { @@ -70,8 +70,8 @@ func (s *State) SetChainValidators(validators *ChainValidators) { s.ChainValidators = validators } -func (s *State) SetChainInfo(info *TendermintStatusResult) { - s.ChainInfo = info +func (s *State) SetNodeStatus(status *TendermintStatusResult) { + s.NodeStatus = status } func (s *State) SetUpgrade(upgrade *Upgrade) { @@ -94,8 +94,8 @@ func (s *State) SetUpgradePlanError(err error) { s.UpgradePlanError = err } -func (s *State) SetChainInfoError(err error) { - s.ChainInfoError = err +func (s *State) SetStatusError(err error) { + s.StatusError = err } func (s *State) SerializeConsensus(timezone *time.Location) string { @@ -169,11 +169,11 @@ func (s *State) SerializeConsensus(timezone *time.Location) string { func (s *State) SerializeChainInfo(timezone *time.Location) string { var sb strings.Builder - if s.ChainInfoError != nil { - sb.WriteString(fmt.Sprintf(" chain info fetch error: %s\n", s.ChainInfoError.Error())) - } else if s.ChainInfo != nil { - sb.WriteString(fmt.Sprintf(" chain name: %s\n", s.ChainInfo.NodeInfo.Network)) - sb.WriteString(fmt.Sprintf(" tendermint version: v%s\n", s.ChainInfo.NodeInfo.Version)) + if s.StatusError != nil { + sb.WriteString(fmt.Sprintf(" chain info fetch error: %s\n", s.StatusError.Error())) + } else if s.NodeStatus != nil { + sb.WriteString(fmt.Sprintf(" chain name: %s\n", s.NodeStatus.NodeInfo.Network)) + sb.WriteString(fmt.Sprintf(" tendermint version: v%s\n", s.NodeStatus.NodeInfo.Version)) if s.BlockTime != 0 { sb.WriteString(fmt.Sprintf(" avg block time: %s\n", utils.SerializeDuration(s.BlockTime))) diff --git a/pkg/types/status.go b/pkg/types/status.go index cb26bd1..3e455b8 100644 --- a/pkg/types/status.go +++ b/pkg/types/status.go @@ -5,10 +5,15 @@ type TendermintStatusResponse struct { } type TendermintStatusResult struct { - NodeInfo TendermintNodeInfo `json:"node_info"` + NodeInfo TendermintNodeInfo `json:"node_info"` + ValidatorInfo TendermintValidatorInfo `json:"validator_info"` } type TendermintNodeInfo struct { Version string `json:"version"` Network string `json:"network"` } + +type TendermintValidatorInfo struct { + Address string `json:"address"` +}