mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Add blob getters (#13170)
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
12f7143c4f
commit
f663f605d2
@ -2,6 +2,8 @@ package blocks
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
@ -40,3 +42,23 @@ func NewROBlob(b *ethpb.BlobSidecar) (ROBlob, error) {
|
||||
func (b *ROBlob) BlockRoot() [32]byte {
|
||||
return b.root
|
||||
}
|
||||
|
||||
// Slot returns the slot of the blob sidecar.
|
||||
func (b *ROBlob) Slot() primitives.Slot {
|
||||
return b.SignedBlockHeader.Header.Slot
|
||||
}
|
||||
|
||||
// ParentRoot returns the parent root of the blob sidecar.
|
||||
func (b *ROBlob) ParentRoot() [32]byte {
|
||||
return bytesutil.ToBytes32(b.SignedBlockHeader.Header.ParentRoot)
|
||||
}
|
||||
|
||||
// BodyRoot returns the body root of the blob sidecar.
|
||||
func (b *ROBlob) BodyRoot() [32]byte {
|
||||
return bytesutil.ToBytes32(b.SignedBlockHeader.Header.BodyRoot)
|
||||
}
|
||||
|
||||
// ProposerIndex returns the proposer index of the blob sidecar.
|
||||
func (b *ROBlob) ProposerIndex() primitives.ValidatorIndex {
|
||||
return b.SignedBlockHeader.Header.ProposerIndex
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
||||
)
|
||||
@ -57,3 +58,59 @@ func TestBlockRoot(t *testing.T) {
|
||||
}
|
||||
assert.Equal(t, root, blob.BlockRoot())
|
||||
}
|
||||
|
||||
func TestSlot(t *testing.T) {
|
||||
slot := primitives.Slot(1)
|
||||
blob := &ROBlob{
|
||||
BlobSidecar: ðpb.BlobSidecar{
|
||||
SignedBlockHeader: ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
Slot: slot,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, slot, blob.Slot())
|
||||
}
|
||||
|
||||
func TestParentRoot(t *testing.T) {
|
||||
root := [32]byte{1}
|
||||
blob := &ROBlob{
|
||||
BlobSidecar: ðpb.BlobSidecar{
|
||||
SignedBlockHeader: ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ParentRoot: root[:],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, root, blob.ParentRoot())
|
||||
}
|
||||
|
||||
func TestBodyRoot(t *testing.T) {
|
||||
root := [32]byte{1}
|
||||
blob := &ROBlob{
|
||||
BlobSidecar: ðpb.BlobSidecar{
|
||||
SignedBlockHeader: ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
BodyRoot: root[:],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, root, blob.BodyRoot())
|
||||
}
|
||||
|
||||
func TestProposeIndex(t *testing.T) {
|
||||
index := primitives.ValidatorIndex(1)
|
||||
blob := &ROBlob{
|
||||
BlobSidecar: ðpb.BlobSidecar{
|
||||
SignedBlockHeader: ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
ProposerIndex: index,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, index, blob.ProposerIndex())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user