@@ -20,10 +20,13 @@ import (
2020 "os"
2121 "strconv"
2222 "strings"
23+ "time"
2324
2425 . "github.com/streamingfast/cli"
26+ "github.com/streamingfast/cli/sflags"
2527
2628 "github.com/spf13/cobra"
29+ "github.com/spf13/pflag"
2730 "github.com/streamingfast/bstream"
2831 "github.com/streamingfast/bstream/blockstream"
2932 pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1"
@@ -42,6 +45,9 @@ func NewToolsRelayerGroup[B firecore.Block](chain *firecore.Chain[B], logger *za
4245 toolsRelayerStreamRunner (chain , logger ),
4346 "stream <source> [:<stop>]" ,
4447 "Stream blocks from a live relayer source to the console" ,
48+ Flags (func (flags * pflag.FlagSet ) {
49+ flags .Bool ("clock" , false , "For each block, only print the current timestamp, block timestamp, drift" )
50+ }),
4551
4652 RangeArgs (1 , 2 ),
4753 Description (`
@@ -68,6 +74,8 @@ func toolsRelayerStreamRunner[B firecore.Block](chain *firecore.Chain[B], logger
6874 stop := int64 (- 1 )
6975 stopIsRelative := false
7076
77+ onlyClock := sflags .MustGetBool (cmd , "clock" )
78+
7179 if len (args ) == 2 {
7280 input := strings .TrimPrefix (args [1 ], ":" )
7381
@@ -89,8 +97,12 @@ func toolsRelayerStreamRunner[B firecore.Block](chain *firecore.Chain[B], logger
8997 endpoint ,
9098 1 ,
9199 bstream .HandlerFunc (func (blk * pbbstream.Block , obj any ) error {
92- if err := printer .PrintTo (blk , os .Stderr ); err != nil {
93- return fmt .Errorf ("unable to print block: %w" , err )
100+ if onlyClock {
101+ fmt .Printf ("%d -- %s %s latency(ms): %5d\n " , blk .Number , blk .Timestamp .AsTime ().UTC ().Format ("15:04:05" ), time .Now ().UTC ().Format ("15:04:05.000" ), time .Since (blk .Timestamp .AsTime ()).Milliseconds ())
102+ } else {
103+ if err := printer .PrintTo (blk , os .Stderr ); err != nil {
104+ return fmt .Errorf ("unable to print block: %w" , err )
105+ }
94106 }
95107
96108 blockCount ++
0 commit comments