Skip to content

Commit 13614f4

Browse files
committed
ethstats: fix timestamps and add custom proto support
1 parent 4f9ccdd commit 13614f4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ethstats/ethstats.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"regexp"
2626
"runtime"
2727
"strconv"
28+
"strings"
2829
"time"
2930

3031
"github.com/ethereum/go-ethereum/common"
@@ -115,7 +116,11 @@ func (s *Service) loop() {
115116
// Loop reporting until termination
116117
for {
117118
// Establish a websocket connection to the server and authenticate the node
118-
conn, err := websocket.Dial(fmt.Sprintf("wss://%s/api", s.host), "", "http://localhost/")
119+
url := fmt.Sprintf("%s/api", s.host)
120+
if !strings.Contains(url, "://") {
121+
url = "wss://" + url
122+
}
123+
conn, err := websocket.Dial(url, "", "http://localhost/")
119124
if err != nil {
120125
glog.V(logger.Warn).Infof("Stats server unreachable: %v", err)
121126
time.Sleep(10 * time.Second)
@@ -297,6 +302,7 @@ func (s *Service) reportLatency(in *json.Decoder, out *json.Encoder) error {
297302
type blockStats struct {
298303
Number *big.Int `json:"number"`
299304
Hash common.Hash `json:"hash"`
305+
Timestamp *big.Int `json:"timestamp"`
300306
Miner common.Address `json:"miner"`
301307
GasUsed *big.Int `json:"gasUsed"`
302308
GasLimit *big.Int `json:"gasLimit"`
@@ -362,6 +368,7 @@ func (s *Service) reportBlock(out *json.Encoder, block *types.Block) error {
362368
"block": &blockStats{
363369
Number: head.Number,
364370
Hash: head.Hash(),
371+
Timestamp: head.Time,
365372
Miner: head.Coinbase,
366373
GasUsed: new(big.Int).Set(head.GasUsed),
367374
GasLimit: new(big.Int).Set(head.GasLimit),

0 commit comments

Comments
 (0)