Skip to content

Commit

Permalink
feat: allow transpose all rounds (#26)
Browse files Browse the repository at this point in the history
* feat: allow transpose all rounds

* chore: added docs

* chore: fixed typo
  • Loading branch information
freak12techno authored Aug 9, 2024
1 parent 4b3f18a commit 6cf21ae
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ A: Verify you have a correct `--consumer-chain-id` specified.

In theory, it should work on any Tendermint-based network with any node that has its RPC accessible.

For cosmos-sdk chains, it should also allow displaying the upgrade info and the validators list.

For non cosmos-sdk chains, it can also display this data given the chain implements the wrapper
that returns the data in cosmos-sdk LCD compatible format (namely, validators list endpoint and upgrade plan one),
`--chain-type cosmos-lcd` is used and the correct LCD path is provided.

## How can I contribute?

Bug reports and feature requests are always welcome! If you want to contribute, feel free to open issues or PRs.
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c Config) Validate() error {
}

if c.ChainType == ChainTypeCosmosLCD && c.LCDHost == "" {
return errors.New("chain-type is 'cosmos-lcd', but lcd-node is not set")
return errors.New("chain-type is 'cosmos-lcd', but lcd-host is not set")
}

return nil
Expand Down
17 changes: 14 additions & 3 deletions pkg/display/all_rounds_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@ type AllRoundsTableData struct {

Validators types.ValidatorsWithInfoAndAllRoundVotes
DisableEmojis bool
Transpose bool
}

func NewAllRoundsTableData(disableEmojis bool) *AllRoundsTableData {
func NewAllRoundsTableData(disableEmojis bool, transpose bool) *AllRoundsTableData {
return &AllRoundsTableData{
Validators: types.ValidatorsWithInfoAndAllRoundVotes{},
DisableEmojis: disableEmojis,
Transpose: transpose,
}
}

func (d *AllRoundsTableData) GetCell(row, column int) *tview.TableCell {
round := column - 1
if d.Transpose {
round = len(d.Validators.RoundsVotes) - column
}

// Table header.
if row == 0 {
text := "validator"
if column != 0 {
text = strconv.Itoa(column - 1)
text = strconv.Itoa(round)
}

return tview.
Expand All @@ -44,7 +51,7 @@ func (d *AllRoundsTableData) GetCell(row, column int) *tview.TableCell {
return cell
}

roundVotes := d.Validators.RoundsVotes[column-1]
roundVotes := d.Validators.RoundsVotes[round]
roundVote := roundVotes[row-1]
text := roundVote.Serialize(d.DisableEmojis)

Expand All @@ -68,3 +75,7 @@ func (d *AllRoundsTableData) GetColumnCount() int {
func (d *AllRoundsTableData) SetValidators(validators types.ValidatorsWithInfoAndAllRoundVotes) {
d.Validators = validators
}

func (d *AllRoundsTableData) SetTranspose(transpose bool) {
d.Transpose = transpose
}
3 changes: 2 additions & 1 deletion pkg/display/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewWrapper(
appVersion string,
) *Wrapper {
lastRoundTableData := NewLastRoundTableData(DefaultColumnsCount, config.DisableEmojis, false)
allRoundsTableData := NewAllRoundsTableData(config.DisableEmojis)
allRoundsTableData := NewAllRoundsTableData(config.DisableEmojis, false)

helpTextBytes, _ := static.TemplatesFs.ReadFile("help.txt")
helpText := strings.ReplaceAll(string(helpTextBytes), "{{ Version }}", appVersion)
Expand Down Expand Up @@ -164,6 +164,7 @@ func (w *Wrapper) Start() {
if event.Rune() == 't' {
w.Transpose = !w.Transpose
w.LastRoundTableData.SetTranspose(w.Transpose)
w.AllRoundsTableData.SetTranspose(w.Transpose)
}

if event.Rune() == 'p' {
Expand Down
2 changes: 1 addition & 1 deletion static/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You can use the following shortcuts:
- display [m[]more or [l[]ess columns in validators table
- display or hide this [h[]elp message
- [p[]ause new updates
- [t[]ranspose the last round validators' view
- [t[]ranspose the last round validators' view/display new rounds first on all rounds view
- [q[]uit the app (or Ctrl+C)

You can also press [Tab[] to switch between modes, which are:
Expand Down

0 comments on commit 6cf21ae

Please sign in to comment.