mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
302b0f8c80
* use fast ssz anywhere applicable * use fastssz clearly * Merge branch 'master' into use-fastssz * Apply suggestions from code review * imports * Update beacon-chain/p2p/fork.go * Merge branch 'master' into use-fastssz * update go-ssz * update go-ssz * Merge refs/heads/master into use-fastssz * Merge refs/heads/master into use-fastssz
33 lines
865 B
Go
33 lines
865 B
Go
package debug
|
|
|
|
import (
|
|
"context"
|
|
|
|
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// GetBlock in an ssz-encoded format by block root.
|
|
func (ds *Server) GetBlock(
|
|
ctx context.Context,
|
|
req *pbrpc.BlockRequest,
|
|
) (*pbrpc.SSZResponse, error) {
|
|
root := bytesutil.ToBytes32(req.BlockRoot)
|
|
signedBlock, err := ds.BeaconDB.Block(ctx, root)
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not retrieve block by root: %v", err)
|
|
}
|
|
if signedBlock == nil {
|
|
return &pbrpc.SSZResponse{Encoded: make([]byte, 0)}, nil
|
|
}
|
|
encoded, err := signedBlock.MarshalSSZ()
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not marshal block: %v", err)
|
|
}
|
|
return &pbrpc.SSZResponse{
|
|
Encoded: encoded,
|
|
}, nil
|
|
}
|