From 8bfea2f8b32b51f269aef20f294b6100d84d8930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 1 Jul 2019 16:35:44 -0400 Subject: [PATCH] add a call to admin_nodeInfo before launching gui MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- client.go | 9 +++++++++ json.go | 27 ++++++++++++++++++++++++--- main.go | 8 ++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index fb5b1fd..fc1a681 100644 --- a/client.go +++ b/client.go @@ -16,6 +16,15 @@ func newClient(url string) (*StatusGoClient, error) { return &StatusGoClient{rpcClient}, nil } +func (c *StatusGoClient) nodeInfo() (*NodeInfo, error) { + var info NodeInfo + err := c.rpcClient.Call(&info, "admin_nodeInfo") + if err != nil { + return nil, err + } + return &info, nil +} + func (c *StatusGoClient) getPeers() ([]Peer, error) { var peers []Peer err := c.rpcClient.Call(&peers, "admin_peers") diff --git a/json.go b/json.go index fd3e80a..75e0c01 100644 --- a/json.go +++ b/json.go @@ -2,9 +2,30 @@ package main import "fmt" +type NodeInfo struct { + Enode string `json:"enode"` + Name string `json:"name"` + ID PeerID `json:"id"` + ListenIp string `json:"ip"` + ListenAddr string `json:"listenAddr"` + ListenPorts NodeInfoPorts `json:"ports"` + Protocols map[string]NodeProtocol `json:"protocols"` +} + +type NodeInfoPorts struct { + Discovery int `json:"discovert"` + Listener int `json:"listener"` +} + +type NodeProtocol struct { + MaxMessageSize int `json:"maxMessageSize"` + MinimumPoW float32 `json:"minimumPoW"` + Version string `json:"version"` +} + type Peer struct { Enode string `json:"enode"` - ID PeerId `json:"id"` + ID PeerID `json:"id"` Name string `json:"name"` Caps []string `json:"caps"` Network NetworkInfo `json:"network"` @@ -15,10 +36,10 @@ func (p Peer) String() string { return fmt.Sprintf("Peer(ID=%s)", p.ID) } -type PeerId string +type PeerID string // the ID is too long to display in full in most places -func (id PeerId) String() string { +func (id PeerID) String() string { return fmt.Sprintf("%s...%s", string(id[:6]), string(id[len(id)-6:])) diff --git a/main.go b/main.go index 3a0edc2..16facbf 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,14 @@ func main() { log.Panicln(err) } + // Verify the RPC endpoint is available first + node, err := client.nodeInfo() + if err != nil { + log.Panicln(err) + } + log.Println("Successful connection to:", url) + log.Println("Enode:", node.Enode) + // Create a state wrapper. state := NewState(client) // Subscribe rendering method to state changes.