prysm-pulse/shared/blockutil/block_utils.go

26 lines
836 B
Go
Raw Normal View History

package blockutil
import (
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
)
// SignedBeaconBlockHeaderFromBlock function to retrieve block header from block.
func SignedBeaconBlockHeaderFromBlock(block *ethpb.SignedBeaconBlock) (*ethpb.SignedBeaconBlockHeader, error) {
bodyRoot, err := stateutil.BlockBodyRoot(block.Block.Body)
if err != nil {
return nil, errors.Wrap(err, "failed to get body root of block")
}
return &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{
Slot: block.Block.Slot,
ProposerIndex: block.Block.ProposerIndex,
ParentRoot: block.Block.ParentRoot,
StateRoot: block.Block.StateRoot,
BodyRoot: bodyRoot[:],
},
Signature: block.Signature,
}, nil
}