Skip to content

Commit

Permalink
FEAT: Refactor incoming header proc to work with EventResult struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmihaic committed Dec 23, 2024
1 parent 3f4ee06 commit 47d0620
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
13 changes: 9 additions & 4 deletions process/block/sovereign/incomingHeader/depositEventProc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type depositEventProc struct {
topicsChecker TopicsChecker
}

func (dep *depositEventProc) ProcessEvent(event data.EventHandler) (*eventsResult, error) {
func (dep *depositEventProc) ProcessEvent(event data.EventHandler) (*EventResult, error) {
topics := event.GetTopics()
err := dep.topicsChecker.CheckValidity(topics)
if err != nil {
Expand Down Expand Up @@ -55,11 +55,11 @@ func (dep *depositEventProc) ProcessEvent(event data.EventHandler) (*eventsResul
return nil, err
}

return &eventsResult{
scrs: []*scrInfo{{
return &EventResult{
SCR: &scrInfo{
scr: scr,
hash: hash,
}},
},
}, nil
}

Expand Down Expand Up @@ -160,3 +160,8 @@ func (dep *depositEventProc) getTokenDataBytes(tokenNonce []byte, tokenData []by

return dep.marshaller.Marshal(digitalToken)
}

// IsInterfaceNil checks if the underlying pointer is nil
func (dep *depositEventProc) IsInterfaceNil() bool {
return dep == nil
}
18 changes: 11 additions & 7 deletions process/block/sovereign/incomingHeader/executedBridgeOpEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ type executedEventPoc struct {
depositEventProc IncomingEventHandler
}

func (eep *executedEventPoc) ProcessEvent(event data.EventHandler) (*eventsResult, error) {
func (eep *executedEventPoc) ProcessEvent(event data.EventHandler) (*EventResult, error) {
topics := event.GetTopics()
if len(topics) == 0 {
return nil, fmt.Errorf("%w for event id: %s", errInvalidNumTopicsIncomingEvent, eventIDExecutedOutGoingBridgeOp)
}

var scr *scrInfo
var resDeposit *EventResult
var confirmedOp *confirmedBridgeOp
var err error
switch string(topics[0]) {
case topicIDDepositIncomingTransfer:
resDeposit, errDeposit := eep.depositEventProc.ProcessEvent(event)
scr, err = resDeposit.scrs[0], errDeposit
resDeposit, err = eep.depositEventProc.ProcessEvent(event)
case topicIDConfirmedOutGoingOperation:
confirmedOp, err = getConfirmedBridgeOperation(topics)
default:
Expand All @@ -33,9 +32,9 @@ func (eep *executedEventPoc) ProcessEvent(event data.EventHandler) (*eventsResul
return nil, err
}

return &eventsResult{
scrs: []*scrInfo{scr},
confirmedBridgeOps: []*confirmedBridgeOp{confirmedOp},
return &EventResult{
SCR: resDeposit.SCR,
ConfirmedBridgeOp: confirmedOp,
}, nil
}

Expand All @@ -49,3 +48,8 @@ func getConfirmedBridgeOperation(topics [][]byte) (*confirmedBridgeOp, error) {
hash: topics[hashOfOperationIndex],
}, nil
}

// IsInterfaceNil checks if the underlying pointer is nil
func (eep *executedEventPoc) IsInterfaceNil() bool {
return eep == nil
}
7 changes: 7 additions & 0 deletions process/block/sovereign/incomingHeader/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package incomingHeader
import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/sovereign"

sovereignBlock "github.com/multiversx/mx-chain-go/dataRetriever/dataPool/sovereign"
sovBlock "github.com/multiversx/mx-chain-go/process/block/sovereign"
)
Expand Down Expand Up @@ -42,3 +43,9 @@ type RunTypeComponentsHolder interface {
TopicsCheckerHandler() sovBlock.TopicsCheckerHandler
IsInterfaceNil() bool
}

// IncomingEventHandler defines the behaviour of an incoming cross chain event processor handler
type IncomingEventHandler interface {
ProcessEvent(event data.EventHandler) (*EventResult, error)
IsInterfaceNil() bool
}

0 comments on commit 47d0620

Please sign in to comment.