implement peer removal without prompt

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-06-27 09:14:28 -04:00 committed by Jakub
parent 08ec326ea4
commit 51d299888d
5 changed files with 28 additions and 1 deletions

View File

@ -24,3 +24,12 @@ func (c *client) getPeers() ([]Peer, error) {
} }
return peers, nil return peers, nil
} }
func (c *client) removePeer(enode string) (bool, error) {
var rval bool
err := c.rpcClient.Call(&rval, "admin_removePeer", enode)
if err != nil {
return false, err
}
return rval, nil
}

View File

@ -44,3 +44,9 @@ func MoveCursor(mod int, vc *ViewController, g *gocui.Gui, v *gocui.View) error
} }
return nil return nil
} }
func (vc *ViewController) HandleDelete(g *gocui.Gui, v *gocui.View) error {
ps := vc.State.(*PeersState)
selectedPeer := ps.selected
rval := ps.Remove(*selectedPeer)
}

View File

@ -52,6 +52,8 @@ func main() {
Binding{gocui.KeyArrowDown, gocui.ModNone, mainView.CursorDown}, Binding{gocui.KeyArrowDown, gocui.ModNone, mainView.CursorDown},
Binding{'k', gocui.ModNone, mainView.CursorUp}, Binding{'k', gocui.ModNone, mainView.CursorUp},
Binding{'j', gocui.ModNone, mainView.CursorDown}, Binding{'j', gocui.ModNone, mainView.CursorDown},
Binding{gocui.KeyDelete, gocui.ModNone, mainView.HandleDelete},
Binding{'d', gocui.ModNone, mainView.HandleDelete},
} }
infoView := &ViewController{ infoView := &ViewController{
Name: "info", Name: "info",
@ -60,7 +62,7 @@ func main() {
Enabled: true, Enabled: true,
Wrap: true, Wrap: true,
// corner positions // corner positions
TopLeft: func(mx, my int) (int, int) { return 0, my/2 + 1 }, TopLeft: func(mx, my int) (int, int) { return 0, (my / 2) + 1 },
BotRight: func(mx, my int) (int, int) { return mx - 1, my - 1 }, BotRight: func(mx, my int) (int, int) { return mx - 1, my - 1 },
} }

View File

@ -64,6 +64,14 @@ func writePeers(g *gocui.Gui, peers []Peer) {
}) })
} }
func (p *PeersState) Remove(peer Peer) error {
success, err := p.c.removePeer(peer.Enode)
if err != nil || success != true {
log.Panicln(err)
}
return nil
}
func writePeerDetails(g *gocui.Gui, peer *Peer) { func writePeerDetails(g *gocui.Gui, peer *Peer) {
g.Update(func(g *gocui.Gui) error { g.Update(func(g *gocui.Gui) error {
v, err := g.View("info") v, err := g.View("info")

View File

@ -42,6 +42,7 @@ func (m *ViewManager) Layout(g *gocui.Gui) error {
x1, y1 := cfg.BotRight(mx, my) x1, y1 := cfg.BotRight(mx, my)
v, err := g.SetView(cfg.Name, x0, y0, x1, y1) v, err := g.SetView(cfg.Name, x0, y0, x1, y1)
// Some settings can be set only once // Some settings can be set only once
if err == gocui.ErrUnknownView { if err == gocui.ErrUnknownView {
cfg.SetKeybindings(g) cfg.SetKeybindings(g)
@ -54,6 +55,7 @@ func (m *ViewManager) Layout(g *gocui.Gui) error {
} else if err != nil { } else if err != nil {
log.Panicln(err) log.Panicln(err)
} }
v.Title = cfg.Title v.Title = cfg.Title
v.Wrap = cfg.Wrap v.Wrap = cfg.Wrap
v.SelFgColor = cfg.SelFgColor v.SelFgColor = cfg.SelFgColor