Skip to content

Commit

Permalink
Add halving banner
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Chain committed Apr 10, 2020
1 parent ba84b32 commit 1ac079b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
)

const (
BLOCK_WIDTH = 22
BLOCK_WIDTH = 22
NEXT_HALVING = 630_000
)

type state struct {
Expand Down Expand Up @@ -231,6 +232,11 @@ func (ui *UI) Layout(g *gocui.Gui) error {
return err
}

// halving
if err := ui.halvingBanner(); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -326,6 +332,28 @@ func (ui *UI) info(g *gocui.Gui, x, y int) error {
return nil
}

func (ui *UI) halvingBanner() error {
blocks := ui.state.blocks
if len(blocks) == 0 {
return nil
}
height := blocks[0].Height
if height >= NEXT_HALVING {
return nil
}

in := NEXT_HALVING - height
msg := fmt.Sprintf("Quantitative Hardening in %d blocks", in)
v, err := ui.gui.SetView("halving", 1, 1, len(msg)+2, 3)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
}
_, err = fmt.Fprintf(v, msg)
return err
}

func (ui *UI) onBlockClick(g *gocui.Gui, v *gocui.View) error {
name := v.Name()
if strings.HasPrefix(name, "mempool-block-") {
Expand Down

0 comments on commit 1ac079b

Please sign in to comment.