This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblock.go
51 lines (48 loc) · 1.46 KB
/
block.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
package main
import (
"bytes"
"context"
"fmt"
"strconv"
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/wealdtech/go-bytesutil"
)
func getBlockCommandResult(command string, parameters []string) string {
if len(parameters) != 1 {
log.Error("Expected 1 parameter for validator command")
}
reqSlot, err := strconv.Atoi(parameters[0])
if err != nil {
log.WithError(err).Error(err, "failed to convert")
return ""
}
req := ð.ListBlocksRequest{
QueryFilter: ð.ListBlocksRequest_Slot{
Slot: uint64(reqSlot),
},
}
blocks, err := beaconClient.ListBlocks(context.Background(), req)
if err != nil {
log.WithError(err).Error(err, "failed to get committees")
return fmt.Sprintf("Could not get block %d.", reqSlot)
}
if len(blocks.BlockContainers) < 1 {
return fmt.Sprintf("No block found for slot %d", reqSlot)
}
block := blocks.BlockContainers[0].Block
switch command {
case blockGraffiti.command, blockGraffiti.shorthand:
graffiti := block.Block.Body.Graffiti
emptyGraffiti := bytesutil.ToBytes32([]byte{0})
if bytes.Equal(graffiti, emptyGraffiti[:]) {
return fmt.Sprintf("Graffiti for block %d is empty", reqSlot)
}
fmt.Printf("%s\n", graffiti)
return fmt.Sprintf(blockGraffiti.responseText, reqSlot, graffiti)
case blockProposer.command, blockProposer.shorthand:
return fmt.Sprintf(blockProposer.responseText, reqSlot, block.Block.ProposerIndex)
default:
return ""
}
return ""
}