Created
September 24, 2024 19:40
-
-
Save peterargue/6b4b58100c559244a9da61fe0e380415 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "log" | |
| "time" | |
| "github.com/onflow/flow/protobuf/go/flow/access" | |
| "github.com/onflow/flow/protobuf/go/flow/entities" | |
| "google.golang.org/grpc" | |
| "google.golang.org/grpc/credentials/insecure" | |
| ) | |
| const ( | |
| accessURL = "access-008.mainnet25.nodes.onflow.org:9000" | |
| ) | |
| func main() { | |
| ctx, cancel := context.WithCancel(context.Background()) | |
| defer cancel() | |
| conn, err := grpc.Dial(accessURL, | |
| grpc.WithTransportCredentials(insecure.NewCredentials()), | |
| grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*20)), | |
| ) | |
| if err != nil { | |
| log.Fatalf("could not connect to access api server: %v", err) | |
| } | |
| client := access.NewAccessAPIClient(conn) | |
| startHeader, err := client.GetLatestBlockHeader(ctx, &access.GetLatestBlockHeaderRequest{}) | |
| if err != nil { | |
| log.Fatalf("could not get latest block header: %v", err) | |
| } | |
| stream, err := client.SubscribeBlockHeadersFromStartHeight(ctx, &access.SubscribeBlockHeadersFromStartHeightRequest{ | |
| StartBlockHeight: startHeader.Block.Height, | |
| BlockStatus: entities.BlockStatus_BLOCK_SEALED, | |
| }) | |
| if err != nil { | |
| log.Fatalf("could not subscribe to block digests: %v", err) | |
| } | |
| for { | |
| header, err := stream.Recv() | |
| if err != nil { | |
| log.Fatalf("error receiving block digest: %v", err) | |
| } | |
| timestamp := header.Header.Timestamp.AsTime() | |
| log.Printf("%d %x %s", header.Header.Height, header.Header.Id, timestamp.Format(time.RFC3339Nano)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment