This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.go
59 lines (43 loc) · 1.2 KB
/
function.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package function
import (
"fmt"
"net/http"
"bytes"
"context"
"google.golang.org/grpc"
beaconservice "github.com/prysmaticlabs/prysm/v3/proto/eth/service"
ethpbv1 "github.com/prysmaticlabs/prysm/v3/proto/eth/v1"
"github.com/GoogleCloudPlatform/functions-framework-go/functions"
)
func init() {
functions.HTTP("DownloadSidecar", downloadSidecar)
}
// helloWorld writes "Hello, World!" to the HTTP response.
func downloadSidecar(w http.ResponseWriter, r *http.Request) {
addr := "localhost:4000"
start := r.URL.Query().Get("slot")
// todo add err handling
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
req := ethpbv1.BlobsRequest{BlockId: []byte(start)}
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure())
if err != nil {
panic(err)
}
client := beaconservice.NewBeaconChainClient(conn)
sidecar, err := client.GetBlobsSidecar(ctx, &req)
if err != nil {
panic(err)
}
blobsBuffer := new(bytes.Buffer)
for _, b := range sidecar.Blobs {
fmt.Printf("%v\n", b)
// Do whatever you want with the blobs here
/*
data := shared.DecodeBlob(blob.Data)
_, _ = blobsBuffer.Write(data)
*/
}
data := blobsBuffer.Bytes()
fmt.Printf("%v\n", data)
}