Skip to content

Commit

Permalink
Merge pull request #249 from multiversx/integrate-latest-version-of-c…
Browse files Browse the repository at this point in the history
…omm-go

Integrate latest version of `mx-chain-communication-go`
  • Loading branch information
ssd04 authored Sep 22, 2023
2 parents 4d6fe11 + 49011b9 commit e18418b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
11 changes: 6 additions & 5 deletions data/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ type Logs struct {

// Event holds all the fields needed for an event structure
type Event struct {
Address string `json:"address"`
Identifier string `json:"identifier"`
Topics [][]byte `json:"topics"`
Data []byte `json:"data"`
Order int `json:"order"`
Address string `json:"address"`
Identifier string `json:"identifier"`
Topics [][]byte `json:"topics"`
Data []byte `json:"data"`
AdditionalData [][]byte `json:"additionalData,omitempty"`
Order int `json:"order"`
}

// PreparedLogsResults is the DTO that holds all the results after processing
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/elastic/go-elasticsearch/v7 v7.12.0
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/multiversx/mx-chain-communication-go v1.0.6
github.com/multiversx/mx-chain-core-go v1.2.15
github.com/multiversx/mx-chain-communication-go v1.0.7
github.com/multiversx/mx-chain-core-go v1.2.16
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-vm-common-go v1.5.2
github.com/prometheus/client_model v0.4.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-communication-go v1.0.6 h1:f2bizRoVuJXBWc32px7pCuzMx4Pgi2tKhUt8BkFV1Fg=
github.com/multiversx/mx-chain-communication-go v1.0.6/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4=
github.com/multiversx/mx-chain-core-go v1.2.15 h1:2qbcGP9yHi9CFeLF9xTDnDPJjvafvTmwEkitfI0wWME=
github.com/multiversx/mx-chain-core-go v1.2.15/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-communication-go v1.0.7 h1:7qeDBcqmGYYhSqFcpwv0qKkR3ahOfIMbRwXYEnOt/do=
github.com/multiversx/mx-chain-communication-go v1.0.7/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4=
github.com/multiversx/mx-chain-core-go v1.2.16 h1:m0hUNmZQjGJxKDLQOHoM9jSaeDfVTbyd+mqiS8+NckE=
github.com/multiversx/mx-chain-core-go v1.2.16/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU=
github.com/multiversx/mx-chain-logger-go v1.0.13 h1:eru/TETo0MkO4ZTnXsQDKf4PBRpAXmqjT02klNT/JnY=
github.com/multiversx/mx-chain-logger-go v1.0.13/go.mod h1:MZJhTAtZTJxT+yK2EHc4ZW3YOHUc1UdjCD0iahRNBZk=
Expand Down
22 changes: 10 additions & 12 deletions process/elasticproc/logsevents/logsAndEventsProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (lep *logsAndEventsProcessor) PrepareLogsForDB(

func (lep *logsAndEventsProcessor) prepareLogsForDB(
logHashHex string,
logHandler coreData.LogHandler,
eventLogs *transaction.Log,
timestamp uint64,
) *data.Logs {
originalTxHash := ""
Expand All @@ -212,31 +212,29 @@ func (lep *logsAndEventsProcessor) prepareLogsForDB(
originalTxHash = scr.OriginalTxHash
}

events := logHandler.GetLogEvents()

encodedAddr := lep.pubKeyConverter.SilentEncode(logHandler.GetAddress(), log)

encodedAddr := lep.pubKeyConverter.SilentEncode(eventLogs.GetAddress(), log)
logsDB := &data.Logs{
ID: logHashHex,
OriginalTxHash: originalTxHash,
Address: encodedAddr,
Timestamp: time.Duration(timestamp),
Events: make([]*data.Event, 0, len(events)),
Events: make([]*data.Event, 0, len(eventLogs.Events)),
}

for idx, event := range events {
for idx, event := range eventLogs.Events {
if check.IfNil(event) {
continue
}

encodedAddress := lep.pubKeyConverter.SilentEncode(event.GetAddress(), log)

logsDB.Events = append(logsDB.Events, &data.Event{
Address: encodedAddress,
Identifier: string(event.GetIdentifier()),
Topics: event.GetTopics(),
Data: event.GetData(),
Order: idx,
Address: encodedAddress,
Identifier: string(event.GetIdentifier()),
Topics: event.GetTopics(),
Data: event.GetData(),
AdditionalData: event.GetAdditionalData(),
Order: idx,
})
}

Expand Down
14 changes: 8 additions & 6 deletions process/elasticproc/logsevents/logsAndEventsProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ func TestLogsAndEventsProcessor_PrepareLogsForDB(t *testing.T) {
Address: []byte("address"),
Events: []*transaction.Event{
{
Address: []byte("addr"),
Identifier: []byte(core.BuiltInFunctionESDTNFTTransfer),
Topics: [][]byte{[]byte("my-token"), big.NewInt(0).SetUint64(1).Bytes(), []byte("receiver")},
Address: []byte("addr"),
Identifier: []byte(core.BuiltInFunctionESDTNFTTransfer),
Topics: [][]byte{[]byte("my-token"), big.NewInt(0).SetUint64(1).Bytes(), []byte("receiver")},
AdditionalData: [][]byte{[]byte("something")},
},
},
},
Expand All @@ -243,9 +244,10 @@ func TestLogsAndEventsProcessor_PrepareLogsForDB(t *testing.T) {
Timestamp: time.Duration(1234),
Events: []*data.Event{
{
Address: "61646472",
Identifier: core.BuiltInFunctionESDTNFTTransfer,
Topics: [][]byte{[]byte("my-token"), big.NewInt(0).SetUint64(1).Bytes(), []byte("receiver")},
Address: "61646472",
Identifier: core.BuiltInFunctionESDTNFTTransfer,
Topics: [][]byte{[]byte("my-token"), big.NewInt(0).SetUint64(1).Bytes(), []byte("receiver")},
AdditionalData: [][]byte{[]byte("something")},
},
},
}, logsDB[0])
Expand Down
6 changes: 5 additions & 1 deletion process/wsindexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ func (i *indexer) initActionsMap() {
}

// ProcessPayload will proces the provided payload based on the topic
func (i *indexer) ProcessPayload(payload []byte, topic string) error {
func (i *indexer) ProcessPayload(payload []byte, topic string, version uint32) error {
if version != 1 {
log.Warn("received a payload with a different version", "version", version)
}

payloadTypeAction, ok := i.actions[topic]
if !ok {
log.Warn("invalid payload type", "topic", topic)
Expand Down

0 comments on commit e18418b

Please sign in to comment.