github.com/prysmaticlabs/prysm@v1.4.4/shared/interfaces/metadata_wrapper.go (about)

     1  package interfaces
     2  
     3  import (
     4  	"github.com/prysmaticlabs/go-bitfield"
     5  	pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
     6  	"google.golang.org/protobuf/proto"
     7  )
     8  
     9  // MetadataV0 is a convenience wrapper around our metadata protobuf object.
    10  type MetadataV0 struct {
    11  	md *pb.MetaDataV0
    12  }
    13  
    14  // WrappedMetadataV0 wrappers around the provided protobuf object.
    15  func WrappedMetadataV0(md *pb.MetaDataV0) MetadataV0 {
    16  	return MetadataV0{md: md}
    17  }
    18  
    19  // SequenceNumber returns the sequence number from the metadata.
    20  func (m MetadataV0) SequenceNumber() uint64 {
    21  	return m.md.SeqNumber
    22  }
    23  
    24  // AttnetsBitfield retruns the bitfield stored in the metadata.
    25  func (m MetadataV0) AttnetsBitfield() bitfield.Bitvector64 {
    26  	return m.md.Attnets
    27  }
    28  
    29  // InnerObject returns the underlying metadata protobuf structure.
    30  func (m MetadataV0) InnerObject() interface{} {
    31  	return m.md
    32  }
    33  
    34  // IsNil checks for the nilness of the underlying object.
    35  func (m MetadataV0) IsNil() bool {
    36  	return m.md == nil
    37  }
    38  
    39  // Copy performs a full copy of the underlying metadata object.
    40  func (m MetadataV0) Copy() Metadata {
    41  	return WrappedMetadataV0(proto.Clone(m.md).(*pb.MetaDataV0))
    42  }
    43  
    44  // MetadataObjV0 returns the inner metadata object in its type
    45  // specified form. If it doesn't exist then we return nothing.
    46  func (m MetadataV0) MetadataObjV0() *pb.MetaDataV0 {
    47  	return m.md
    48  }
    49  
    50  // MetadataObjV1 returns the inner metatdata object in its type
    51  // specified form. If it doesn't exist then we return nothing.
    52  func (m MetadataV0) MetadataObjV1() *pb.MetaDataV1 {
    53  	return nil
    54  }
    55  
    56  // MetadataV1 is a convenience wrapper around our metadata v2 protobuf object.
    57  type MetadataV1 struct {
    58  	md *pb.MetaDataV1
    59  }
    60  
    61  // WrappedMetadataV1 wrappers around the provided protobuf object.
    62  func WrappedMetadataV1(md *pb.MetaDataV1) MetadataV1 {
    63  	return MetadataV1{md: md}
    64  }
    65  
    66  // SequenceNumber returns the sequence number from the metadata.
    67  func (m MetadataV1) SequenceNumber() uint64 {
    68  	return m.md.SeqNumber
    69  }
    70  
    71  // AttnetsBitfield retruns the bitfield stored in the metadata.
    72  func (m MetadataV1) AttnetsBitfield() bitfield.Bitvector64 {
    73  	return m.md.Attnets
    74  }
    75  
    76  // InnerObject returns the underlying metadata protobuf structure.
    77  func (m MetadataV1) InnerObject() interface{} {
    78  	return m.md
    79  }
    80  
    81  // IsNil checks for the nilness of the underlying object.
    82  func (m MetadataV1) IsNil() bool {
    83  	return m.md == nil
    84  }
    85  
    86  // Copy performs a full copy of the underlying metadata object.
    87  func (m MetadataV1) Copy() Metadata {
    88  	return WrappedMetadataV1(proto.Clone(m.md).(*pb.MetaDataV1))
    89  }
    90  
    91  // MetadataObjV0 returns the inner metadata object in its type
    92  // specified form. If it doesn't exist then we return nothing.
    93  func (m MetadataV1) MetadataObjV0() *pb.MetaDataV0 {
    94  	return nil
    95  }
    96  
    97  // MetadataObjV1 returns the inner metatdata object in its type
    98  // specified form. If it doesn't exist then we return nothing.
    99  func (m MetadataV1) MetadataObjV1() *pb.MetaDataV1 {
   100  	return m.md
   101  }