github.com/prysmaticlabs/prysm@v1.4.4/proto/eth/v1alpha1/wrapper/beacon_block.go (about)

     1  package wrapper
     2  
     3  import (
     4  	types "github.com/prysmaticlabs/eth2-types"
     5  	"github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
     6  	"github.com/prysmaticlabs/prysm/proto/interfaces"
     7  	"github.com/prysmaticlabs/prysm/shared/copyutil"
     8  	"google.golang.org/protobuf/proto"
     9  )
    10  
    11  // Phase0SignedBeaconBlock is a convenience wrapper around a phase 0 beacon block
    12  // object. This wrapper allows us to conform to a common interface so that beacon
    13  // blocks for future forks can also be applied across prysm without issues.
    14  type Phase0SignedBeaconBlock struct {
    15  	b *eth.SignedBeaconBlock
    16  }
    17  
    18  // WrappedPhase0SignedBeaconBlock is constructor which wraps a protobuf phase 0 block
    19  // with the block wrapper.
    20  func WrappedPhase0SignedBeaconBlock(b *eth.SignedBeaconBlock) Phase0SignedBeaconBlock {
    21  	return Phase0SignedBeaconBlock{b: b}
    22  }
    23  
    24  // Signature returns the respective block signature.
    25  func (w Phase0SignedBeaconBlock) Signature() []byte {
    26  	return w.b.Signature
    27  }
    28  
    29  // Block returns the underlying beacon block object.
    30  func (w Phase0SignedBeaconBlock) Block() interfaces.BeaconBlock {
    31  	return WrappedPhase0BeaconBlock(w.b.Block)
    32  }
    33  
    34  // IsNil checks if the underlying beacon block is
    35  // nil.
    36  func (w Phase0SignedBeaconBlock) IsNil() bool {
    37  	return w.b == nil || w.Block().IsNil()
    38  }
    39  
    40  // Copy performs a deep copy of the signed beacon block
    41  // object.
    42  func (w Phase0SignedBeaconBlock) Copy() interfaces.SignedBeaconBlock {
    43  	return WrappedPhase0SignedBeaconBlock(copyutil.CopySignedBeaconBlock(w.b))
    44  }
    45  
    46  // MarshalSSZ marshals the signed beacon block to its relevant ssz
    47  // form.
    48  func (w Phase0SignedBeaconBlock) MarshalSSZ() ([]byte, error) {
    49  	return w.b.MarshalSSZ()
    50  }
    51  
    52  // Proto returns the block in its underlying protobuf
    53  // interface.
    54  func (w Phase0SignedBeaconBlock) Proto() proto.Message {
    55  	return w.b
    56  }
    57  
    58  // PbPhase0Block returns the underlying protobuf object.
    59  func (w Phase0SignedBeaconBlock) PbPhase0Block() (*eth.SignedBeaconBlock, error) {
    60  	return w.b, nil
    61  }
    62  
    63  // Phase0BeaconBlock is the wrapper for the actual block.
    64  type Phase0BeaconBlock struct {
    65  	b *eth.BeaconBlock
    66  }
    67  
    68  // WrappedPhase0BeaconBlock is constructor which wraps a protobuf phase 0 object
    69  // with the block wrapper.
    70  func WrappedPhase0BeaconBlock(b *eth.BeaconBlock) Phase0BeaconBlock {
    71  	return Phase0BeaconBlock{b: b}
    72  }
    73  
    74  // Slot returns the respective slot of the block.
    75  func (w Phase0BeaconBlock) Slot() types.Slot {
    76  	return w.b.Slot
    77  }
    78  
    79  // ProposerIndex returns proposer index of the beacon block.
    80  func (w Phase0BeaconBlock) ProposerIndex() types.ValidatorIndex {
    81  	return w.b.ProposerIndex
    82  }
    83  
    84  // ParentRoot returns the parent root of beacon block.
    85  func (w Phase0BeaconBlock) ParentRoot() []byte {
    86  	return w.b.ParentRoot
    87  }
    88  
    89  // StateRoot returns the state root of the beacon block.
    90  func (w Phase0BeaconBlock) StateRoot() []byte {
    91  	return w.b.StateRoot
    92  }
    93  
    94  // Body returns the underlying block body.
    95  func (w Phase0BeaconBlock) Body() interfaces.BeaconBlockBody {
    96  	return WrappedPhase0BeaconBlockBody(w.b.Body)
    97  }
    98  
    99  // IsNil checks if the beacon block is nil.
   100  func (w Phase0BeaconBlock) IsNil() bool {
   101  	return w.b == nil || w.Body().IsNil()
   102  }
   103  
   104  // HashTreeRoot returns the ssz root of the block.
   105  func (w Phase0BeaconBlock) HashTreeRoot() ([32]byte, error) {
   106  	return w.b.HashTreeRoot()
   107  }
   108  
   109  // MarshalSSZ marshals the block into its respective
   110  // ssz form.
   111  func (w Phase0BeaconBlock) MarshalSSZ() ([]byte, error) {
   112  	return w.b.MarshalSSZ()
   113  }
   114  
   115  // Proto returns the underlying block object in its
   116  // proto form.
   117  func (w Phase0BeaconBlock) Proto() proto.Message {
   118  	return w.b
   119  }
   120  
   121  // Phase0BeaconBlockBody is a wrapper of a beacon block body.
   122  type Phase0BeaconBlockBody struct {
   123  	b *eth.BeaconBlockBody
   124  }
   125  
   126  // WrappedPhase0BeaconBlockBody is constructor which wraps a protobuf phase 0 object
   127  // with the block wrapper.
   128  func WrappedPhase0BeaconBlockBody(b *eth.BeaconBlockBody) Phase0BeaconBlockBody {
   129  	return Phase0BeaconBlockBody{b: b}
   130  }
   131  
   132  // RandaoReveal returns the randao reveal from the block body.
   133  func (w Phase0BeaconBlockBody) RandaoReveal() []byte {
   134  	return w.b.RandaoReveal
   135  }
   136  
   137  // Eth1Data returns the eth1 data in the block.
   138  func (w Phase0BeaconBlockBody) Eth1Data() *eth.Eth1Data {
   139  	return w.b.Eth1Data
   140  }
   141  
   142  // Graffiti returns the graffiti in the block.
   143  func (w Phase0BeaconBlockBody) Graffiti() []byte {
   144  	return w.b.Graffiti
   145  }
   146  
   147  // ProposerSlashings returns the proposer slashings in the block.
   148  func (w Phase0BeaconBlockBody) ProposerSlashings() []*eth.ProposerSlashing {
   149  	return w.b.ProposerSlashings
   150  }
   151  
   152  // AttesterSlashings returns the attester slashings in the block.
   153  func (w Phase0BeaconBlockBody) AttesterSlashings() []*eth.AttesterSlashing {
   154  	return w.b.AttesterSlashings
   155  }
   156  
   157  // Attestations returns the stored attestations in the block.
   158  func (w Phase0BeaconBlockBody) Attestations() []*eth.Attestation {
   159  	return w.b.Attestations
   160  }
   161  
   162  // Deposits returns the stored deposits in the block.
   163  func (w Phase0BeaconBlockBody) Deposits() []*eth.Deposit {
   164  	return w.b.Deposits
   165  }
   166  
   167  // VoluntaryExits returns the voluntary exits in the block.
   168  func (w Phase0BeaconBlockBody) VoluntaryExits() []*eth.SignedVoluntaryExit {
   169  	return w.b.VoluntaryExits
   170  }
   171  
   172  // IsNil checks if the block body is nil.
   173  func (w Phase0BeaconBlockBody) IsNil() bool {
   174  	return w.b == nil
   175  }
   176  
   177  // HashTreeRoot returns the ssz root of the block body.
   178  func (w Phase0BeaconBlockBody) HashTreeRoot() ([32]byte, error) {
   179  	return w.b.HashTreeRoot()
   180  }
   181  
   182  // Proto returns the underlying proto form of the block
   183  // body.
   184  func (w Phase0BeaconBlockBody) Proto() proto.Message {
   185  	return w.b
   186  }