2020-05-20 15:23:22 +00:00
|
|
|
package blockutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
|
|
|
)
|
|
|
|
|
2020-06-23 16:46:48 +00:00
|
|
|
// SignedBeaconBlockHeaderFromBlock function to retrieve signed block header from block.
|
2020-05-20 15:23:22 +00:00
|
|
|
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 ðpb.SignedBeaconBlockHeader{
|
|
|
|
Header: ðpb.BeaconBlockHeader{
|
|
|
|
Slot: block.Block.Slot,
|
|
|
|
ProposerIndex: block.Block.ProposerIndex,
|
|
|
|
ParentRoot: block.Block.ParentRoot,
|
|
|
|
StateRoot: block.Block.StateRoot,
|
|
|
|
BodyRoot: bodyRoot[:],
|
|
|
|
},
|
|
|
|
Signature: block.Signature,
|
|
|
|
}, nil
|
|
|
|
}
|
2020-06-23 16:46:48 +00:00
|
|
|
|
|
|
|
// BeaconBlockHeaderFromBlock function to retrieve block header from block.
|
|
|
|
func BeaconBlockHeaderFromBlock(block *ethpb.BeaconBlock) (*ethpb.BeaconBlockHeader, error) {
|
|
|
|
bodyRoot, err := stateutil.BlockBodyRoot(block.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to get body root of block")
|
|
|
|
}
|
|
|
|
return ðpb.BeaconBlockHeader{
|
|
|
|
Slot: block.Slot,
|
|
|
|
ProposerIndex: block.ProposerIndex,
|
|
|
|
ParentRoot: block.ParentRoot,
|
|
|
|
StateRoot: block.StateRoot,
|
|
|
|
BodyRoot: bodyRoot[:],
|
|
|
|
}, nil
|
|
|
|
}
|