Skip to content

Commit

Permalink
remove facade old versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 committed Feb 6, 2024
1 parent d11828b commit 6a65ec1
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 58 deletions.
3 changes: 1 addition & 2 deletions api/groups/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (

// EventsFacadeHandler defines the behavior of a facade handler needed for events group
type EventsFacadeHandler interface {
HandlePushEventsV2(events data.ArgsSaveBlockData) error
HandlePushEventsV1(events data.SaveBlockData) error
HandlePushEvents(events data.ArgsSaveBlockData) error
HandleRevertEvents(revertBlock data.RevertBlock)
HandleFinalizedEvents(finalizedBlock data.FinalizedBlock)
GetConnectorUserAndPass() (string, string)
Expand Down
3 changes: 1 addition & 2 deletions api/shared/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ type GroupHandler interface {

// FacadeHandler defines the behavior of a notifier base facade handler
type FacadeHandler interface {
HandlePushEventsV2(events data.ArgsSaveBlockData) error
HandlePushEventsV1(events data.SaveBlockData) error
HandlePushEvents(events data.ArgsSaveBlockData) error
HandleRevertEvents(revertBlock data.RevertBlock)
HandleFinalizedEvents(finalizedBlock data.FinalizedBlock)
GetConnectorUserAndPass() (string, string)
Expand Down
32 changes: 2 additions & 30 deletions facade/notifierFacade.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func checkArgs(args ArgsNotifierFacade) error {
return nil
}

// HandlePushEventsV2 will handle push events received from observer
// HandlePushEvents will handle push events received from observer
// It splits block data and handles log, txs and srcs events separately
func (nf *notifierFacade) HandlePushEventsV2(allEvents data.ArgsSaveBlockData) error {
func (nf *notifierFacade) HandlePushEvents(allEvents data.ArgsSaveBlockData) error {
eventsData, err := nf.eventsInterceptor.ProcessBlockEvents(&allEvents)
if err != nil {
return err
Expand Down Expand Up @@ -107,34 +107,6 @@ func (nf *notifierFacade) HandlePushEventsV2(allEvents data.ArgsSaveBlockData) e
return nil
}

// HandlePushEventsV1 will handle push events received from observer
// It splits block data and handles log, txs and srcs events separately
// TODO: remove this implementation
func (nf *notifierFacade) HandlePushEventsV1(eventsData data.SaveBlockData) error {
pushEvents := data.BlockEvents{
Hash: eventsData.Hash,
Events: eventsData.LogEvents,
}
err := nf.eventsHandler.HandlePushEvents(pushEvents)
if err != nil {
return err
}

txs := data.BlockTxs{
Hash: eventsData.Hash,
Txs: eventsData.Txs,
}
nf.eventsHandler.HandleBlockTxs(txs)

scrs := data.BlockScrs{
Hash: eventsData.Hash,
Scrs: eventsData.Scrs,
}
nf.eventsHandler.HandleBlockScrs(scrs)

return nil
}

// HandleRevertEvents will handle revents events received from observer
func (nf *notifierFacade) HandleRevertEvents(events data.RevertBlock) {
nf.eventsHandler.HandleRevertEvents(events)
Expand Down
4 changes: 2 additions & 2 deletions facade/notifierFacade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestHandlePushEvents(t *testing.T) {
HeaderHash: []byte("blockHash"),
Header: &block.HeaderV2{},
}
err = facade.HandlePushEventsV2(blockData)
err = facade.HandlePushEvents(blockData)
require.Equal(t, expectedErr, err)
})

Expand Down Expand Up @@ -253,7 +253,7 @@ func TestHandlePushEvents(t *testing.T) {
facade, err := facade.NewNotifierFacade(args)
require.Nil(t, err)

facade.HandlePushEventsV2(blockData)
facade.HandlePushEvents(blockData)

assert.True(t, pushWasCalled)
assert.True(t, txsWasCalled)
Expand Down
20 changes: 5 additions & 15 deletions mocks/facadeStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (

// FacadeStub implements FacadeHandler interface
type FacadeStub struct {
HandlePushEventsV2Called func(events data.ArgsSaveBlockData) error
HandlePushEventsV1Called func(eventsData data.SaveBlockData) error
HandlePushEventsCalled func(events data.ArgsSaveBlockData) error
HandleRevertEventsCalled func(events data.RevertBlock)
HandleFinalizedEventsCalled func(events data.FinalizedBlock)
ServeCalled func(w http.ResponseWriter, r *http.Request)
Expand All @@ -18,19 +17,10 @@ type FacadeStub struct {
GetMetricsForPrometheusCalled func() string
}

// HandlePushEventsV2 -
func (fs *FacadeStub) HandlePushEventsV2(events data.ArgsSaveBlockData) error {
if fs.HandlePushEventsV2Called != nil {
return fs.HandlePushEventsV2Called(events)
}

return nil
}

// HandlePushEventsV1 -
func (fs *FacadeStub) HandlePushEventsV1(events data.SaveBlockData) error {
if fs.HandlePushEventsV1Called != nil {
return fs.HandlePushEventsV1Called(events)
// HandlePushEvents -
func (fs *FacadeStub) HandlePushEvents(events data.ArgsSaveBlockData) error {
if fs.HandlePushEventsCalled != nil {
return fs.HandlePushEventsCalled(events)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion process/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type DataProcessor interface {

// EventsFacadeHandler defines the behavior of a facade handler needed for events group
type EventsFacadeHandler interface {
HandlePushEventsV2(events data.ArgsSaveBlockData) error
HandlePushEvents(events data.ArgsSaveBlockData) error
HandleRevertEvents(revertBlock data.RevertBlock)
HandleFinalizedEvents(finalizedBlock data.FinalizedBlock)
IsInterfaceNil() bool
Expand Down
2 changes: 1 addition & 1 deletion process/preprocess/eventsPreProcessorV0.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (d *eventsPreProcessorV0) SaveBlock(marshalledData []byte) error {
Header: header,
}

err = d.facade.HandlePushEventsV2(*saveBlockData)
err = d.facade.HandlePushEvents(*saveBlockData)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions process/preprocess/eventsPreProcessorV0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestPreProcessorV0_SaveBlock(t *testing.T) {

expectedErr := errors.New("exp error")
args.Facade = &mocks.FacadeStub{
HandlePushEventsV2Called: func(events data.ArgsSaveBlockData) error {
HandlePushEventsCalled: func(events data.ArgsSaveBlockData) error {
return expectedErr
},
}
Expand All @@ -65,7 +65,7 @@ func TestPreProcessorV0_SaveBlock(t *testing.T) {

wasCalled := false
args.Facade = &mocks.FacadeStub{
HandlePushEventsV2Called: func(events data.ArgsSaveBlockData) error {
HandlePushEventsCalled: func(events data.ArgsSaveBlockData) error {
wasCalled = true
return nil
},
Expand Down
3 changes: 1 addition & 2 deletions process/preprocess/eventsPreProcessorV1.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func (d *eventsPreProcessorV1) SaveBlock(marshalledData []byte) error {
Header: header,
}

// TODO: refactor to remove facade versioning
err = d.facade.HandlePushEventsV2(*saveBlockData)
err = d.facade.HandlePushEvents(*saveBlockData)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion process/preprocess/eventsPreProcessorV1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestPreProcessorV1_SaveBlock(t *testing.T) {

expectedErr := errors.New("exp error")
args.Facade = &mocks.FacadeStub{
HandlePushEventsV2Called: func(events data.ArgsSaveBlockData) error {
HandlePushEventsCalled: func(events data.ArgsSaveBlockData) error {
return expectedErr
},
}
Expand Down

0 comments on commit 6a65ec1

Please sign in to comment.