mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Move BeaconBlockNil Checker Function to Consensus-Types/Wrapper Package (#10731)
* beacon block is nil wrapper * gaz Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -32,7 +32,10 @@ var (
|
||||
// ErrUnsupportedBlindedBellatrixBlock is returned when accessing a blinded bellatrix block from unsupported method.
|
||||
ErrUnsupportedBlindedBellatrixBlock = errors.New("unsupported blinded bellatrix block")
|
||||
// ErrNilObjectWrapped is returned in a constructor when the underlying object is nil.
|
||||
ErrNilObjectWrapped = errors.New("attempted to wrap nil object")
|
||||
ErrNilObjectWrapped = errors.New("attempted to wrap nil object")
|
||||
ErrNilSignedBeaconBlock = errors.New("signed beacon block can't be nil")
|
||||
ErrNilBeaconBlock = errors.New("beacon block can't be nil")
|
||||
ErrNilBeaconBlockBody = errors.New("beacon block body can't be nil")
|
||||
)
|
||||
|
||||
// WrappedSignedBeaconBlock will wrap a signed beacon block to conform to the
|
||||
@@ -159,3 +162,19 @@ func UnwrapGenericSignedBeaconBlock(gb *eth.GenericSignedBeaconBlock) (interface
|
||||
return nil, errors.Wrapf(ErrUnsupportedSignedBeaconBlock, "unable to wrap block of type %T", gb)
|
||||
}
|
||||
}
|
||||
|
||||
// BeaconBlockIsNil checks if any composite field of input signed beacon block is nil.
|
||||
// Access to these nil fields will result in run time panic,
|
||||
// it is recommended to run these checks as first line of defense.
|
||||
func BeaconBlockIsNil(b interfaces.SignedBeaconBlock) error {
|
||||
if b == nil || b.IsNil() {
|
||||
return ErrNilSignedBeaconBlock
|
||||
}
|
||||
if b.Block().IsNil() {
|
||||
return ErrNilBeaconBlock
|
||||
}
|
||||
if b.Block().Body().IsNil() {
|
||||
return ErrNilBeaconBlockBody
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user