mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 03:51:29 +00:00
37 lines
893 B
Go
37 lines
893 B
Go
|
package state_native
|
||
|
|
||
|
import (
|
||
|
"github.com/pkg/errors"
|
||
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||
|
"github.com/prysmaticlabs/prysm/runtime/version"
|
||
|
)
|
||
|
|
||
|
var errAssertionFailed = errors.New("failed to convert interface to proto state")
|
||
|
var errUnsupportedVersion = errors.New("unsupported beacon state version")
|
||
|
|
||
|
func (b *BeaconState) MarshalSSZ() ([]byte, error) {
|
||
|
proto := b.ToProto()
|
||
|
switch b.Version() {
|
||
|
case version.Phase0:
|
||
|
s, ok := proto.(*ethpb.BeaconState)
|
||
|
if !ok {
|
||
|
return nil, errAssertionFailed
|
||
|
}
|
||
|
return s.MarshalSSZ()
|
||
|
case version.Altair:
|
||
|
s, ok := proto.(*ethpb.BeaconStateAltair)
|
||
|
if !ok {
|
||
|
return nil, errAssertionFailed
|
||
|
}
|
||
|
return s.MarshalSSZ()
|
||
|
case version.Bellatrix:
|
||
|
s, ok := proto.(*ethpb.BeaconStateBellatrix)
|
||
|
if !ok {
|
||
|
return nil, errAssertionFailed
|
||
|
}
|
||
|
return s.MarshalSSZ()
|
||
|
default:
|
||
|
return nil, errUnsupportedVersion
|
||
|
}
|
||
|
}
|