Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sovereign] Set outgoing miniblock slice with type in header #348

Draft
wants to merge 5 commits into
base: feat/sov-set-epoch-change-validators
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions data/block/sovereignChainHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"math/big"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/headerVersionData"
)
Expand Down Expand Up @@ -42,9 +41,9 @@ func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler {
headerCopy := *sch
headerCopy.Header = &internalHeaderCopy

if !check.IfNil(sch.OutGoingMiniBlockHeader) {
internalOutGoingMbHeader := *sch.OutGoingMiniBlockHeader
headerCopy.OutGoingMiniBlockHeader = &internalOutGoingMbHeader
if len(sch.OutGoingMiniBlockHeader) != 0 {
headerCopy.OutGoingMiniBlockHeader = make([]OutGoingMiniBlockHeader, len(sch.OutGoingMiniBlockHeader))
copy(headerCopy.OutGoingMiniBlockHeader, sch.OutGoingMiniBlockHeader)
}

return &headerCopy
Expand Down Expand Up @@ -549,33 +548,45 @@ func (sch *SovereignChainHeader) CheckFieldsForNil() error {
return nil
}

// GetOutGoingMiniBlockHeaderHandler returns the outgoing mini block header
func (sch *SovereignChainHeader) GetOutGoingMiniBlockHeaderHandler() data.OutGoingMiniBlockHeaderHandler {
// GetOutGoingMiniBlockHeaderHandlers returns the outgoing mini block headers
func (sch *SovereignChainHeader) GetOutGoingMiniBlockHeaderHandlers() []data.OutGoingMiniBlockHeaderHandler {
if sch == nil {
return nil
}

return sch.GetOutGoingMiniBlockHeader()
mbHeaders := sch.GetOutGoingMiniBlockHeader()
mbHeaderHandlers := make([]data.OutGoingMiniBlockHeaderHandler, len(mbHeaders))

for i := range mbHeaders {
mbHeaderHandlers[i] = &mbHeaders[i]
}

return mbHeaderHandlers
}

// SetOutGoingMiniBlockHeaderHandler returns the outgoing mini block header
func (sch *SovereignChainHeader) SetOutGoingMiniBlockHeaderHandler(mbHeader data.OutGoingMiniBlockHeaderHandler) error {
// SetOutGoingMiniBlockHeaderHandlers returns the outgoing mini block headers
func (sch *SovereignChainHeader) SetOutGoingMiniBlockHeaderHandlers(mbHeaders []data.OutGoingMiniBlockHeaderHandler) error {
if sch == nil {
return data.ErrNilPointerReceiver
}

if check.IfNil(mbHeader) {
if len(mbHeaders) == 0 {
sch.OutGoingMiniBlockHeader = nil
return nil
}

sch.OutGoingMiniBlockHeader = &OutGoingMiniBlockHeader{
Hash: mbHeader.GetHash(),
OutGoingOperationsHash: mbHeader.GetOutGoingOperationsHash(),
AggregatedSignatureOutGoingOperations: mbHeader.GetAggregatedSignatureOutGoingOperations(),
LeaderSignatureOutGoingOperations: mbHeader.GetLeaderSignatureOutGoingOperations(),
miniBlockHeaders := make([]OutGoingMiniBlockHeader, len(mbHeaders))
for i, mbHeaderHandler := range mbHeaders {
miniBlockHeaders[i] = OutGoingMiniBlockHeader{
OutGoingMBType: OutGoingMBType(mbHeaderHandler.GetOutGoingMBTypeInt32()),
Hash: mbHeaderHandler.GetHash(),
OutGoingOperationsHash: mbHeaderHandler.GetOutGoingOperationsHash(),
AggregatedSignatureOutGoingOperations: mbHeaderHandler.GetAggregatedSignatureOutGoingOperations(),
LeaderSignatureOutGoingOperations: mbHeaderHandler.GetLeaderSignatureOutGoingOperations(),
}
}

sch.OutGoingMiniBlockHeader = miniBlockHeaders
return nil
}

Expand Down Expand Up @@ -725,6 +736,24 @@ func (omb *OutGoingMiniBlockHeader) SetAggregatedSignatureOutGoingOperations(sig
return nil
}

func (omb *OutGoingMiniBlockHeader) GetOutGoingMBTypeInt32() int32 {
if omb == nil {
return 0
}

return int32(omb.OutGoingMBType)
}

// SetOutGoingMBTypeInt32 sets the mb type
func (omb *OutGoingMiniBlockHeader) SetOutGoingMBTypeInt32(mbType int32) error {
if omb == nil {
return data.ErrNilPointerReceiver
}

omb.OutGoingMBType = OutGoingMBType(mbType)
return nil
}

// IsInterfaceNil checks if the underlying interface is nil
func (omb *OutGoingMiniBlockHeader) IsInterfaceNil() bool {
return omb == nil
Expand Down
Loading
Loading