diff --git a/process/elasticproc/logsevents/delegatorsProcessor.go b/process/elasticproc/logsevents/delegatorsProcessor.go index 26fd3a82..1cf6c6e7 100644 --- a/process/elasticproc/logsevents/delegatorsProcessor.go +++ b/process/elasticproc/logsevents/delegatorsProcessor.go @@ -18,6 +18,9 @@ const ( withdrawFunc = "withdraw" reDelegateRewardsFunc = "reDelegateRewards" claimRewardsFunc = "claimRewards" + + minNumTopicsClaimRewards = 2 + numTopicsClaimRewardsWithContractAddress = 3 ) type delegatorsProc struct { @@ -137,18 +140,23 @@ func (dp *delegatorsProc) getDelegatorFromClaimRewardsEvent(args *argsProcessEve // topics slice contains: // topics[0] -- claimed rewards // topics[1] -- true = if delegator was deleted + // topics[2] -- if is present will contain the contract address - if len(topics) < 2 { + if len(topics) < minNumTopicsClaimRewards { return nil } - shouldDelete := bytesToBool(topics[1]) + shouldDelete := bytesToBool(topics[minNumTopicsClaimRewards-1]) if !shouldDelete { return nil } encodedAddr := dp.pubkeyConverter.SilentEncode(args.event.GetAddress(), log) + encodedContractAddr := dp.pubkeyConverter.SilentEncode(args.logAddress, log) + if len(topics) == numTopicsClaimRewardsWithContractAddress { + encodedContractAddr = dp.pubkeyConverter.SilentEncode(topics[numTopicsClaimRewardsWithContractAddress-1], log) + } return &data.Delegator{ Address: encodedAddr, diff --git a/process/elasticproc/logsevents/delegatorsProcessor_test.go b/process/elasticproc/logsevents/delegatorsProcessor_test.go index e808fb4e..8d8a5471 100644 --- a/process/elasticproc/logsevents/delegatorsProcessor_test.go +++ b/process/elasticproc/logsevents/delegatorsProcessor_test.go @@ -1,6 +1,7 @@ package logsevents import ( + "encoding/hex" "math/big" "strconv" "testing" @@ -100,6 +101,34 @@ func TestDelegatorProcessor_ClaimRewardsWithDelete(t *testing.T) { }, res.delegator) } +func TestDelegatorProcessor_ClaimRewardsContractAddressInTopics(t *testing.T) { + t.Parallel() + + contractAddress := []byte("contract2") + event := &transaction.Event{ + Address: []byte("addr"), + Identifier: []byte(claimRewardsFunc), + Topics: [][]byte{big.NewInt(1000).Bytes(), []byte(strconv.FormatBool(true)), contractAddress}, + } + args := &argsProcessEvent{ + timestamp: 1234, + event: event, + logAddress: []byte("contract1"), + selfShardID: core.MetachainShardId, + } + + balanceConverter, _ := converters.NewBalanceConverter(10) + delegatorsProcessor := newDelegatorsProcessor(&mock.PubkeyConverterMock{}, balanceConverter) + + res := delegatorsProcessor.processEvent(args) + require.True(t, res.processed) + require.Equal(t, &data.Delegator{ + Address: "61646472", + Contract: hex.EncodeToString(contractAddress), + ShouldDelete: true, + }, res.delegator) +} + func TestDelegatorProcessor_ClaimRewardsNoDelete(t *testing.T) { t.Parallel()