mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
5aac06f04e
* begin move * use same import path * imports * regen protos * regen * no rename * generate ssz * gaz * fmt * edit build file * imports * modify * remove generated files * remove protos * edit imports in prysm * beacon chain all builds * edit script * add generated pbs * add replace rules * license for ethereumapis protos * change visibility * fmt * update build files to gaz ignore * use proper form * edit imports * wrap block * revert scripts * revert go mod
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package blockutil
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
)
|
|
|
|
// SignedBeaconBlockHeaderFromBlock function to retrieve signed block header from block.
|
|
func SignedBeaconBlockHeaderFromBlock(block *ethpb.SignedBeaconBlock) (*ethpb.SignedBeaconBlockHeader, error) {
|
|
if block.Block == nil || block.Block.Body == nil {
|
|
return nil, errors.New("nil block")
|
|
}
|
|
|
|
bodyRoot, err := block.Block.Body.HashTreeRoot()
|
|
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
|
|
}
|
|
|
|
// BeaconBlockHeaderFromBlock function to retrieve block header from block.
|
|
func BeaconBlockHeaderFromBlock(block *ethpb.BeaconBlock) (*ethpb.BeaconBlockHeader, error) {
|
|
if block.Body == nil {
|
|
return nil, errors.New("nil block body")
|
|
}
|
|
|
|
bodyRoot, err := block.Body.HashTreeRoot()
|
|
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
|
|
}
|