Skip to content

Commit

Permalink
change id of event
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Apr 4, 2024
1 parent a8ba485 commit 3e143e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
32 changes: 8 additions & 24 deletions process/elasticproc/logsevents/logsAndEventsProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package logsevents

import (
"encoding/hex"
"encoding/json"
"fmt"
"time"

"github.com/multiversx/mx-chain-core-go/core"
Expand Down Expand Up @@ -46,7 +46,6 @@ func NewLogsAndEventsProcessor(args ArgsLogsAndEventsProcessor) (*logsAndEventsP
pubKeyConverter: args.PubKeyConverter,
eventsProcessors: eventsProcessors,
hasher: args.Hasher,
marshaller: args.Marshalizer,
}, nil
}

Expand Down Expand Up @@ -244,18 +243,13 @@ func (lep *logsAndEventsProcessor) prepareLogsForDB(
logsDB.Events = append(logsDB.Events, logEvent)

executionOrder := lep.getExecutionOrder(logHashHex)
dbEvent, ok := lep.prepareLogEvent(logsDB, logEvent, shardID, executionOrder)
if !ok {
continue
}

dbEvents = append(dbEvents, dbEvent)
dbEvents = append(dbEvents, lep.prepareLogEvent(logsDB, logEvent, shardID, executionOrder))
}

return logsDB, dbEvents
}

func (lep *logsAndEventsProcessor) prepareLogEvent(dbLog *data.Logs, event *data.Event, shardID uint32, execOrder int) (*data.LogEvent, bool) {
func (lep *logsAndEventsProcessor) prepareLogEvent(dbLog *data.Logs, event *data.Event, shardID uint32, execOrder int) *data.LogEvent {
dbEvent := &data.LogEvent{
TxHash: dbLog.ID,
LogAddress: dbLog.Address,
Expand All @@ -266,23 +260,13 @@ func (lep *logsAndEventsProcessor) prepareLogEvent(dbLog *data.Logs, event *data
Topics: hexEncodeSlice(event.Topics),
Order: event.Order,
ShardID: shardID,
TxOrder: execOrder,
OriginalTxHash: dbLog.OriginalTxHash,
Timestamp: dbLog.Timestamp,
ID: fmt.Sprintf("%s-%d-%d", dbLog.ID, shardID, event.Order),
}

dbEventBytes, err := json.Marshal(dbEvent)
if err != nil {
log.Warn("cannot marshal event",
"txHash", dbLog.ID,
"order", event.Order,
"error", err,
)
}

dbEvent.TxOrder = execOrder
dbEvent.OriginalTxHash = dbLog.OriginalTxHash
dbEvent.Timestamp = dbLog.Timestamp
dbEvent.ID = hex.EncodeToString(lep.hasher.Compute(string(dbEventBytes)))

return dbEvent, true
return dbEvent
}

func (lep *logsAndEventsProcessor) getOriginalTxHash(logHashHex string) string {
Expand Down
4 changes: 2 additions & 2 deletions process/elasticproc/logsevents/logsAndEventsProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func TestPrepareLogsAndEvents_LogEvents(t *testing.T) {
_, eventsDB := proc.PrepareLogsForDB(logsAndEvents, 1234, 1)
require.Equal(t, []*data.LogEvent{
{
ID: "a87eefc4b4190a84ac61543c568f11e54629038267807d639c59f8736a1e4e1b",
ID: "747848617368-1-0",
TxHash: "747848617368",
OriginalTxHash: "originalHash",
LogAddress: "61646472657373",
Expand All @@ -352,7 +352,7 @@ func TestPrepareLogsAndEvents_LogEvents(t *testing.T) {
TxOrder: 0,
},
{
ID: "639d9df8a2dd65957f69de3aade47199b3265ffc6f998e11d8beab7e7c14710c",
ID: "747848617368-1-1",
TxHash: "747848617368",
OriginalTxHash: "originalHash",
LogAddress: "61646472657373",
Expand Down

0 comments on commit 3e143e0

Please sign in to comment.