Skip to content

Commit

Permalink
Initial approach
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Nov 30, 2021
1 parent 87f9b91 commit 1253fd5
Show file tree
Hide file tree
Showing 7 changed files with 486 additions and 95 deletions.
62 changes: 62 additions & 0 deletions command/chain_watch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"context"
"fmt"

"github.com/ethereum/go-ethereum/command/flagset"
"github.com/ethereum/go-ethereum/command/server/proto"
)

// ChainWatchCommand is the command to group the peers commands
type ChainWatchCommand struct {
*Meta2
}

// Help implements the cli.Command interface
func (c *ChainWatchCommand) Help() string {
return ``
}

func (c *ChainWatchCommand) Flags() *flagset.Flagset {
flags := c.NewFlagSet("chain watch")

return flags
}

// Synopsis implements the cli.Command interface
func (c *ChainWatchCommand) Synopsis() string {
return ""
}

// Run implements the cli.Command interface
func (c *ChainWatchCommand) Run(args []string) int {
flags := c.Flags()
if err := flags.Parse(args); err != nil {
c.UI.Error(err.Error())
return 1
}

borClt, err := c.BorConn()
if err != nil {
c.UI.Error(err.Error())
return 1
}

sub, err := borClt.ChainWatch(context.Background(), &proto.ChainWatchRequest{})
if err != nil {
panic(err)
}

for {
msg, err := sub.Recv()
if err != nil {
// if err == EOF if finished on the other side
panic(err)
}
fmt.Println("message received")
fmt.Println(msg)
}

return 0
}
5 changes: 5 additions & 0 deletions command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func commands() map[string]cli.CommandFactory {
UI: ui,
}, nil
},
"chain watch": func() (cli.Command, error) {
return &ChainWatchCommand{
Meta2: meta2,
}, nil
},
"chain sethead": func() (cli.Command, error) {
return &ChainSetHeadCommand{
Meta2: meta2,
Expand Down
Loading

0 comments on commit 1253fd5

Please sign in to comment.