add displaying of list of peers
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
1e7e996e9f
commit
c6b3fa3b9d
|
@ -16,11 +16,11 @@ func newClient(url string) (*client, error) {
|
|||
return &client{rpcClient}, nil
|
||||
}
|
||||
|
||||
func (c *client) getPeers() (interface{}, error) {
|
||||
var rval interface{}
|
||||
err := c.rpcClient.Call(&rval, "admin_peers")
|
||||
func (c *client) getPeers() ([]Peer, error) {
|
||||
peers := make([]Peer, 0)
|
||||
err := c.rpcClient.Call(&peers, "admin_peers")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rval, nil
|
||||
return peers, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Peer struct {
|
||||
Enode string `json:"enode"`
|
||||
Id string `json:"id"`
|
||||
Name string `json:"na"`
|
||||
Caps []string `json:"caps"`
|
||||
Network NetworkInfo `json:"netrowkr"`
|
||||
Protocols map[string]string `json:"protocols"`
|
||||
}
|
||||
|
||||
func (p Peer) String() string {
|
||||
return fmt.Sprintf("Peer(id=%s)", p.Id)
|
||||
}
|
||||
|
||||
type NetworkInfo struct {
|
||||
LocalAddress string `json:"localAddress"`
|
||||
RemoteAddress string `json:"remoteAddress"`
|
||||
Inbound bool `json:"inbound"`
|
||||
Trusted bool `json:"trusted"`
|
||||
Static bool `json:"static"`
|
||||
}
|
12
main.go
12
main.go
|
@ -2,9 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jroimartin/gocui"
|
||||
"log"
|
||||
"time"
|
||||
//"github.com/kr/pretty"
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
type rcpResp map[string]interface{}
|
||||
|
@ -57,17 +58,16 @@ func fetchPeers(c *client, g *gocui.Gui) {
|
|||
}
|
||||
}
|
||||
|
||||
var idx int
|
||||
|
||||
func writePeers(g *gocui.Gui, peers interface{}) {
|
||||
func writePeers(g *gocui.Gui, peers []Peer) {
|
||||
g.Update(func(g *gocui.Gui) error {
|
||||
v, err := g.View("main")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Clear()
|
||||
idx++
|
||||
fmt.Fprintf(v, "idx: %v\n", idx)
|
||||
for _, peer := range peers {
|
||||
fmt.Fprintf(v, "%v\n", peer)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue